Spring Security CAS и HttpBasic, CasAuthentcationProvider не запускаются после предоставления билета

У меня есть мультимодульное приложение maven, где основной модуль зависит от других. Этот основной модуль защищен Spring Security CAS, а подмодулям требуется базовая аутентификация. Это пример конфигурации безопасности субмодуля:

<security:http name="boobkingapiHttp" create-session="stateless" pattern="/hub/book/**" 
    authentication-manager-ref="apiAuthenticationManager">
    <security:intercept-url pattern="/hub/book" access="ROLE_ORDER_MANAGER" />
     <security:http-basic />
</security:http>

И конфигурация безопасности для основного модуля:

<security:http entry-point-ref="casEntryPoint" pattern="/**" realm="ecab" use-expressions="false">
    <security:intercept-url pattern="/flow/googlestatistics/**" access="ROLE_ADMIN" />
    <security:intercept-url pattern="/**" access="ROLE_ADMIN" />
    <security:custom-filter position="CAS_FILTER" ref="casFilter" />
    <security:logout logout-success-url="/logout.xhtml"/>
    <security:custom-filter ref="requestSingleLogoutFilter" before="LOGOUT_FILTER"/>
    <security:custom-filter ref="singleLogoutFilter" before="CAS_FILTER"/>
</security:http>

<beans:bean id="casFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter">
    <beans:property name="authenticationManager" ref="authenticationManager" />
</beans:bean>

<beans:bean id="casEntryPoint" class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">
    <beans:property name="loginUrl" value="http://localhost:8082/sso/login" />
    <beans:property name="serviceProperties" ref="serviceProperties" />
</beans:bean>

<security:authentication-manager alias="authenticationManager">
    <security:authentication-provider ref="casAuthenticationProvider" />
</security:authentication-manager>

<beans:bean id="casAuthenticationProvider" 
class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
    <beans:property name="authenticationUserDetailsService">
        <beans:bean class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
            <beans:constructor-arg ref="hwsAuthenticationUserDetailsService" />
        </beans:bean>
    </beans:property>
    <beans:property name="serviceProperties" ref="serviceProperties" />
    <beans:property name="ticketValidator">
        <beans:bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
            <beans:constructor-arg index="0" value="http://localhost:8082/sso" />
        </beans:bean>
    </beans:property>
    <beans:property name="key" value="an_id_for_this_auth_provider_only" />
</beans:bean>

<beans:bean id="serviceProperties" 
  class="org.springframework.security.cas.ServiceProperties">
    <beans:property name="service" value="http://localhost:8080/cas-client/login/cas" />
    <beans:property name="sendRenew" value="false" />
</beans:bean>

Проблема в том, что когда сервер CAS предоставляет билет и перенаправляет на URL службы: http://localhost:8080/cas-client/login/cas?ticket=ST-19-1clKw2tZ5MVp0OznfAun casAuthenticationProvider не вызывается. Тот, который вызван, является субмодулем authenticationProvider и результат 401 Unauthorized ошибка. Почему CAS SecurityFilterChain не вызывается? Я думал, что это было обработано Spring Security CAS, но, похоже, нет. Я использую Spring Security 5.1.2. ВЫПУСК. Большое спасибо за вашу помощь.

1 ответ

Решение

Я нашел причину, почему CasAuthenticationProvider не был вызван. Это только из-за этого:

<security:authentication-manager alias="authenticationManager">
   <security:authentication-provider ref="casAuthenticationProvider" />
</security:authentication-manager>

Я изменился alias в id,

Другие вопросы по тегам