我正在尝试自定义PreAuthenticatedAuthenticationProvider
类来扩展逻辑:
@Component("superAuthenticaionProvider")
public class SuperAuthenticaionProvider extends PreAuthenticatedAuthenticationProvider{
// this is inherited from PreAuthenticatedAuthenticationProvider
/*private AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken> preAuthenticatedUserDetailsService;*/
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
.......
}
}
继承自PreAuthenticatedAuthenticationProvider
,需要preAuthenticatedUserDetailsService
注入类,我在xml中进行注入:
的AuthenticationManager
<sec:authentication-manager alias="authenticationManager">
<sec:authentication-provider ref='preAuthenticatedAuthenticationProvider'/>
</sec:authentication-manager>
自定义身份验证提供程序
<bean id="preAuthenticatedAuthenticationProvider"
class="org.myapps.save.the.world.SuperAuthenticaionProvider">
<property name="preAuthenticatedUserDetailsService"
ref="preAuthenticatedUserDetailsService"/>
</bean>
注入preAuthenticatedUserDetailsService bean
<bean id="preAuthenticatedUserDetailsService"
class="org.springframework.security.web.authentication.preauth.
PreAuthenticatedGrantedAuthoritiesUserDetailsService"/>
但Spring框架给了我例外:
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: An AuthenticationUserDetailsService must be set
和
Caused by: java.lang.IllegalArgumentException: An AuthenticationUserDetailsService must be set
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider.afterPropertiesSet(PreAuthenticatedAuthenticationProvider.java:44)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
... 26 more
例外是必须设置AuthenticationUserDetailsService
意味着preAuthenticatedUserDetailsService
未能注入课堂,但显然它在security-context.xml
。
即使我在AuthenticationUserDetailsService
班级中@Autowired
为AuthenticationProvider
@Autowired
private AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken>
preAuthenticatedUserDetailsService;
它仍然给我同样的错误 那我在这里想念的是什么?
由于
答案 0 :(得分:0)
我认为您需要在使用PreAuthenticatedAuthenticationProvider之前设置AuthenticationUserDetailsService。您能提供更多自定义身份验证提供程序的代码吗?正如医生所说:
此身份验证提供程序不会执行任何检查 身份验证*请求,因为它们应该已经存在 预认证。但是,* AuthenticationUserDetailsService 实现可能仍会抛出UsernameNotFoundException,for 示例