Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过注释进行的Spring授权不适用于自定义身份验证_Spring_Spring Security_Jsr250 - Fatal编程技术网

通过注释进行的Spring授权不适用于自定义身份验证

通过注释进行的Spring授权不适用于自定义身份验证,spring,spring-security,jsr250,Spring,Spring Security,Jsr250,我已经覆盖了BasicAuthenticationFilter,并将其替换为我们的a筛选器,以从db获取自定义身份验证对象并通过 SecurityContextHolder.getContext().setAuthentication(auth); 以下是安全配置的重要部分: <http use-expressions="true" entry-point-ref="authEntryPoint"> <custom-filter position="BASIC_AUT

我已经覆盖了BasicAuthenticationFilter,并将其替换为我们的a筛选器,以从db获取自定义身份验证对象并通过

SecurityContextHolder.getContext().setAuthentication(auth);
以下是安全配置的重要部分:

<http use-expressions="true" entry-point-ref="authEntryPoint">
    <custom-filter position="BASIC_AUTH_FILTER" ref="basicProcessingFilter" />
    <intercept-url pattern="/**" access="hasRole('user')"/>
</http>
<beans:bean id="authEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
    <beans:property name="loginFormUrl" value="/login"/>
</beans:bean>
<global-method-security jsr250-annotations="enabled"/>

我还提供了我自己的AuthenticationProvider,它只是一个no op,因为身份验证过程已经在自定义筛选器中完成:

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    logger.info("user:" + authentication.getPrincipal() + " pw:" + authentication.getCredentials());
    authentication.setAuthenticated(false);        
    return authentication;
}

@Override
public boolean supports(Class<? extends Object> authentication) {
    return MyAuthentication.class.isAssignableFrom(authentication);
}
@覆盖
公共身份验证(身份验证)引发AuthenticationException{
logger.info(“用户:”+authentication.getPrincipal()+“pw:”+authentication.getCredentials());
authentication.setAuthenticated(false);
返回认证;
}
@凌驾
公共布尔支持(类移动

<global-method-security jsr250-annotations="enabled"/>

从spring安全上下文到我“扫描”类的上下文(即我的应用程序上下文)都有帮助