Spring Security:如何在自定义UserDetailsS​​ervice中访问SessionRegistry?

时间:2015-12-10 22:48:52

标签: spring security session registry userdetailsservice

我收到以下错误消息

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [org.springframework.security.core.session.SessionRegistry]
found for dependency: expected at least 1 bean which qualifies as autowire 
candidate for this dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}

给出以下Spring Security 4设置:

Spring安全配置:

...
<x509 subject-principal-regex="CN=(.*?)," user-service-ref="userDetailsService" />
...
<custom-filter ref="concurrencyFilter" after="CONCURRENT_SESSION_FILTER" />
<session-management>
    <concurrency-control max-sessions="1"
                         error-if-maximum-exceeded="true"
                         session-registry-ref="sessionRegistry" />
</session-management>

<beans:bean id="concurrencyFilter"
            class="org.springframework.security.web.session.ConcurrentSessionFilter">
            <beans:property name="sessionRegistry" ref="sessionRegistry"/>
            <beans:property name="expiredUrl" value="/logout" />
</beans:bean>

<beans:bean id="sessionRegistry"
            class="org.springframework.security.core.session.SessionRegistryImpl" />

<authentication-manager alias="authenticationManager">
    <authentication-provider user-service-ref="userDetailsService" />
</authentication-manager>
...

自定义UserDetailsS​​ervice:

...
@Service("userDetailsService")
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private SessionRegistryImpl sessionRegistry;
    ...
}

知道为什么SessionRegistryImpl无法注入我的自定义UserDetailsService?我尝试了各种排列,例如session-registry-alias代替session-registry-ref@Resource(name="sessionRegistry")代替@Autowired等,但没有一个适合我。我被困住了,任何帮助都将不胜感激!

0 个答案:

没有答案