如何在spring security中同时实现AuthenticationEntryPoint和AuthenticationProvider

如何在spring security中同时实现AuthenticationEntryPoint和AuthenticationProvider,spring,authentication,spring-security,Spring,Authentication,Spring Security,嗨,春季安全专家 我的要求。 我有两套UI。一组是登录和注销,需要使用基本身份验证(使用用户名密码凭据)由spring security进行保护。我使用HybridAuthenticationProvider实现AuthenticationProvider并实现了它 需要通过在HTTP头中传递令牌来支持第二个和其他UI。我使用CustomAuthenticationEntryPoint实现AuthenticationEntryPoint+GenericFilterBean,并且可以实现它 现在我

嗨,春季安全专家

我的要求。

我有两套UI。一组是登录和注销,需要使用基本身份验证(使用用户名密码凭据)由spring security进行保护。我使用HybridAuthenticationProvider实现AuthenticationProvider并实现了它

需要通过在HTTP头中传递令牌来支持第二个和其他UI。我使用CustomAuthenticationEntryPoint实现AuthenticationEntryPoint+GenericFilterBean,并且可以实现它

现在我想制作一个spring-security.xml来实现以上两个功能。最终,我合并了一组UI页面,其中我希望通过凭证(AuthenticationProvider)保护登录/注销页面,并使用令牌(AuthenticationEntryPoint)保护其余UI

当我将所有内容放在spring-security.xml(如下所述)中时,我得到了以下异常

例外情况:

异常为org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter”的bean时出错:设置bean属性“authenticationManager”时无法解析对bean“org.springframework.security.authentication.ProviderManager”的引用;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.authentication.ProviderManager#0”的bean时出错:无法解析匹配的构造函数(提示:为简单参数指定索引/类型/名称参数以避免类型歧义) 位于org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)

示例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>

我删除了AuthenticationManager ref=“hybridAuthenticationProvider”,然后在部署时出现以下异常

例外情况:

org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.filterChainProxy”的bean时出错:调用init方法失败;嵌套的异常是java.lang.IllegalArgumentException:在筛选器链中的其他模式之前定义了一个通用匹配模式(“/**”),导致忽略它们。请检查命名空间或FilterChainProxy bean配置中的顺序

请帮帮我。是否有其他方法来达到上述要求。
先谢谢你

出现此异常是因为http元素的de“pattern”属性默认为“/**”。由于您有两个没有特定模式的“http”元素,因此采用默认值,并且它们各自覆盖相同的UI集

尝试在这两个面板上添加不同的图案:

<http pattern="/foo/**" ... >
  ...
</http>

<http pattern="/bar/**" ... >
  ...
</http>

...
...

出现此异常是因为http元素的de“pattern”属性默认为“/**”。由于您有两个没有特定模式的“http”元素,因此采用默认值,并且它们各自覆盖相同的UI集

尝试在这两个面板上添加不同的图案:

<http pattern="/foo/**" ... >
  ...
</http>

<http pattern="/bar/**" ... >
  ...
</http>

...
...