Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to implement AuthenticationEntryPoint and AuthenticationProvider together in spring security
    primarykey
    data
    text
    <p>Hi Spring Security experts.</p> <p><strong>My Requirements.</strong></p> <p>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. </p> <p>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.</p> <p>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).</p> <p>When I put all together in spring-security.xml (mentioned below), I get following exception.</p> <p><strong>Exception :</strong></p> <p>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)</p> <p>Sample Spring-security.xml</p> <pre><code>&lt;security:http auto-config="true" authentication-manager-ref="hybridAuthenticationProvider"&gt; &lt;security:intercept-url pattern="/auth/login" access="ROLE_USER" /&gt; &lt;/security:http&gt; &lt;security:http realm="Protected API" use-expressions="true" auto-config="false" create-session="stateless" entry-point-ref="CustomAuthenticationEntryPoint"&gt; &lt;security:custom-filter ref="authenticationTokenProcessingFilter" position="FORM_LOGIN_FILTER" /&gt; &lt;security:intercept-url pattern="/welcome" access="isAuthenticated()" /&gt; &lt;/security:http&gt; &lt;bean id="CustomAuthenticationEntryPoint" class="com.ckatudia.tutorial.authentrypoint.CustomAuthenticationEntryPoint" /&gt; &lt;bean id="authenticationTokenProcessingFilter" class="com.ckatudia.tutorial.authentrypoint.AuthenticationTokenProcessingFilter" /&gt; &lt;bean id="TokenUtils" class="com.ckatudia.tutorial.authentrypoint.TokenUtils" /&gt; &lt;bean id="authenticationManager" class="com.ckatudia.tutorial.auth.TokenAuthenticationProvider" /&gt; &lt;bean id="hybridAuthenticationProvider" class="com.ckatudia.tutorial.auth.HybridAuthenticationProvider"&gt; &lt;/bean&gt; &lt;security:authentication-manager&gt; &lt;security:authentication-provider ref="hybridAuthenticationProvider"/&gt; &lt;/security:authentication-manager&gt; </code></pre> <p>I removed authentication-manager-ref="hybridAuthenticationProvider" then I was getting following exception while deployment.</p> <p><strong>Exception :</strong></p> <p>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</p> <p>Please help me here. Is there any other approach to achieve the above requirement. Thanks a lot in advance. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload