Spring multiple authentication providers

Viewed 45

Am trying to use 2 different authentication providers. Below is the spring xml

<http use-expressions="true" pattern="/portal/**" authentication-manager-ref = "authenticationManagerPortal"> 
    <intercept-url pattern="/portal/portal.jsp" access="isAuthenticated()" /> 
    <intercept-url pattern="/portal/portal" access="isAuthenticated()" /> 
    <intercept-url pattern="/portal/portal.jsp" access="isAuthenticated()" /> 
    <intercept-url pattern="/portal/portal" access="isAuthenticated()" />
    <intercept-url pattern="/portal/portal_login.jsp" access="permitAll" />
    <intercept-url pattern="/**" access="permitAll" />
    <form-login login-page='/portal/portal_login.jsp'
        authentication-failure-url="/portal/portal_login.jsp?error=true"
        authentication-failure-handler-ref="customAuthenticationFailureHandlerPortal"
        authentication-success-handler-ref="customAuthenticationSuccessPortal"/>
    <logout logout-success-url="/portal/portal_login.jsp"
        invalidate-session="false" 
        logout-url="/j_spring_security_logout" />
    <session-management
        invalid-session-url="/portal/portal_login.jsp" session-authentication-error-url="/portal/portal_login.jsp">
    </session-management>
</http>

<http use-expressions="true" pattern="/siviri/**" authentication-manager-ref = "authenticationManagerInternal"> 
    <intercept-url pattern="/siviri/crm.jsp" access="isAuthenticated()" /> 
    <intercept-url pattern="/siviri/crm" access="isAuthenticated()" />
    <intercept-url pattern="/siviri/crm_login" access="permitAll" />
    <intercept-url pattern="/siviri/logoff" access="permitAll" />
    <intercept-url pattern="/siviri/crm_login.jsp" access="permitAll" />
    <intercept-url pattern="/**" access="permitAll" />
    <form-login login-page="/siviri/crm_login.jsp"
        authentication-failure-url="/siviri/crm_login.jsp?error=true"
        authentication-failure-handler-ref="customAuthenticationFailureHandler"
        authentication-success-handler-ref="customAuthenticationSuccess"/>
    <logout logout-success-url="/siviri/crm_login.jsp"
        invalidate-session="false" 
        logout-url="/j_spring_security_logout" />
    <csrf disabled="true" />
</http>

<b:bean id="accessAllowed" class="authentication.providers.NA_AccessAllowedB"/>
<b:bean id="springApplicationContext" class="inspireObjectsCoreClasses.NA_ApplicationContext"/>

<b:bean id="customAuthenticationSuccess" class="authentication.providers.NA_AuthenticationSuccess">
    <b:property name="redirectPage" value="/crm.jsp"></b:property>
</b:bean>
<b:bean id="customAuthenticationFailureHandler" class="authentication.providers.NA_AuthenticationFailure">
</b:bean>
<b:bean id="customAuthenticationProvider" class="authentication.providers.NA_AuthenticationProvider">
</b:bean>

<b:bean id="customAuthenticationSuccessPortal" class="authentication.providers.NA_AuthenticationSuccessPortal">
    <b:property name="redirectPage" value="/crm.jsp"></b:property>
</b:bean>
<b:bean id="customAuthenticationFailureHandlerPortal" class="authentication.providers.NA_AuthenticationFailurePortal">
</b:bean>
<b:bean id="customAuthenticationProviderPortal" class="authentication.providers.NA_AuthenticationProviderPortal">
</b:bean>


<global-method-security
    secured-annotations="enabled" pre-post-annotations="enabled">
</global-method-security>
<authentication-manager id = "authenticationManagerInternal" erase-credentials="false">
   <authentication-provider
       ref="customAuthenticationProvider">
   </authentication-provider>
</authentication-manager>

<authentication-manager id = "authenticationManagerPortal" erase-credentials="false">
   <authentication-provider
       ref="customAuthenticationProviderPortal">
   </authentication-provider>
</authentication-manager>

<context:annotation-config></context:annotation-config>
<context:component-scan base-package="authentication.providers">
</context:component-scan>

And the web.xml

<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>
        classpath:securityGlobalConfigs/access-control.xml
   </param-value>
</context-param>
<filter>
   <filter-name>springSecurityFilterChain</filter-name>
   <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
   <filter-name>springSecurityFilterChain</filter-name>
   <url-pattern>/**</url-pattern>
</filter-mapping>

When I load either of the login pages, spring gives me an error that it cannot find the "login" page before the customer authenticator is called. With the same web.xml and the below xml config all work fine

<http use-expressions="true">
   <intercept-url pattern="/crm.jsp" access="isAuthenticated()" /> 
   <intercept-url pattern="/crm" access="isAuthenticated()" /> 
   <intercept-url pattern="/crm_login" access="permitAll" />
   <intercept-url pattern="/logoff" access="permitAll" />
   <intercept-url pattern="/crm_login.jsp" access="permitAll" />
   <intercept-url pattern="/email.jsp" access="permitAll" />
   <intercept-url pattern="/**" access="permitAll" />
  <form-login login-page="/crm_login.jsp"
        authentication-failure-url="/crm_login.jsp?error=true"
        authentication-failure-handler-ref="customAuthenticationFailureHandler"
        authentication-success-handler-ref="customAuthenticationSuccess"/>
     <logout logout-success-url="/crm_login.jsp"
        invalidate-session="false" 
        logout-url="/j_spring_security_logout"
        delete-cookies="JSESSIONID,UUID,database,database_definition" />
    <csrf disabled="true" />
    <session-management
        invalid-session-url="/crm_login.jsp" session-authentication-error-url="/crm_login.jsp">
    </session-management>
</http>
    <b:bean id="accessAllowed" class="authentication.providers.NA_AccessAllowedB"/>
    <b:bean id="springApplicationContext" class="inspireObjectsCoreClasses.NA_ApplicationContext"/>
    <b:bean id="customAuthenticationSuccess" name="customAuthenticationSuccess" 
         class="authentication.providers.NA_AuthenticationSuccess">
    <b:property name="redirectPage" value="/crm.jsp"></b:property>
   </b:bean>
<b:bean id="customAuthenticationFailureHandler" name="customAuthenticationFailureHandler"
    class="authentication.providers.NA_AuthenticationFailure">
</b:bean>
<b:bean id="customAuthenticationProvider" class="authentication.providers.NA_AuthenticationProvider">
</b:bean>
<global-method-security
    secured-annotations="enabled" pre-post-annotations="enabled">
</global-method-security>
<authentication-manager alias="authenticationManager" erase-credentials="false">
   <authentication-provider
       ref="customAuthenticationProvider">
   </authentication-provider>
</authentication-manager>
<context:component-scan base-package="authentication.providers">
</context:component-scan>

What am I doing wrong?

0 Answers
Related