Hi Spring Security experts.
My Requirements.
I have two set of UIs. One set is Login and Logout which needs to be protected by spring security using basic Authentication (using username password credential). I used HybridAuthenticationProvider implementing AuthenticationProvider and achieved it.
The second and rest of UIs need to be supported by passing token in HTTP Header. I used CustomAuthenticationEntryPoint implementing AuthenticationEntryPoint + GenericFilterBean and could achieve it.
Now I want to make single spring-security.xml to achieve above both functionality. Ultimately I have combine set of UI pages where Login/Logout pages I want to protect by credential (AuthenticationProvider) and rest of UIs I want to protect with token (AuthenticationEntryPoint).
When I put all together in spring-security.xml (mentioned below), I get following exception.
Exception :
exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
Sample Spring-security.xml
<security:http auto-config="true" authentication-manager-ref="hybridAuthenticationProvider">
<security:intercept-url pattern="/auth/login" access="ROLE_USER" />
</security:http>
<security:http realm="Protected API" use-expressions="true"
auto-config="false" create-session="stateless" entry-point-ref="CustomAuthenticationEntryPoint">
<security:custom-filter ref="authenticationTokenProcessingFilter"
position="FORM_LOGIN_FILTER" />
<security:intercept-url pattern="/welcome"
access="isAuthenticated()" />
</security:http>
<bean id="CustomAuthenticationEntryPoint"
class="com.ckatudia.tutorial.authentrypoint.CustomAuthenticationEntryPoint" />
<bean id="authenticationTokenProcessingFilter"
class="com.ckatudia.tutorial.authentrypoint.AuthenticationTokenProcessingFilter" />
<bean id="TokenUtils"
class="com.ckatudia.tutorial.authentrypoint.TokenUtils" />
<bean id="authenticationManager"
class="com.ckatudia.tutorial.auth.TokenAuthenticationProvider" />
<bean id="hybridAuthenticationProvider"
class="com.ckatudia.tutorial.auth.HybridAuthenticationProvider">
</bean>
<security:authentication-manager>
<security:authentication-provider ref="hybridAuthenticationProvider"/>
</security:authentication-manager>
I removed authentication-manager-ref="hybridAuthenticationProvider" then I was getting following exception while deployment.
Exception :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChainProxy': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: A universal match pattern ('/**') is defined before other patterns in the filter chain, causing them to be ignored. Please check the ordering in your namespace or FilterChainProxy bean configuration
Please help me here. Is there any other approach to achieve the above requirement. Thanks a lot in advance.