Ich habe ein sehr seltsames Problem. Ich versuche, Spring Security (4.1.0) für die Benutzerauthentifizierung auf einem WildFly-Server zu verwenden. Ich versuchte WildFly 9 und 10. Meine Authentifizierungsdaten werden nach der Anmeldung gespeichert und Spring kann es verwenden, wenn es getAuthentication()
von SecurityContext
aufruft, aber wenn ich SecurityContextHolder.getContext().getAuthentication()
aufrufen, gibt es null
zurück. Ich habe bereits erkannt, dass ich eine andere SecurityContextImpl
(andere Objekt ID) bekomme. Ich habe bereits versucht, die drei verschiedenen Modi SecurityContextHolder
zu verwenden, aber es machte keinen Unterschied.SecurityContext.getAuthentication() ist null
Mein security.xml:
<?xml version="1.0" encoding="UTF-8"?>
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<b:bean id="passwordEncoder"
class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" />
<b:bean id="accessDecisionManager"
class="org.springframework.security.access.vote.AffirmativeBased">
<b:property name="allowIfAllAbstainDecisions" value="false" />
<b:constructor-arg>
<b:list>
<b:bean class="tool.security.RightVoter" />
</b:list>
</b:constructor-arg>
</b:bean>
<authentication-manager alias="authenticationManager">
<authentication-provider ref="loginAuthenticationProvider" />
</authentication-manager>
<b:bean id="authenticationProcessingFilter"
class="tool.security.AuthenticationProcessingFilter">
<b:constructor-arg value="/processLogin" /> <!-- defaultFilterProcessesUrl -->
<b:property name="authenticationManager" ref="authenticationManager" />
<!-- <b:property name="filterProcessesUrl" value="/processLogin" /> -->
<b:property name="authenticationSuccessHandler">
<b:bean
class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
<b:property name="alwaysUseDefaultTargetUrl" value="true" />
<b:property name="defaultTargetUrl" value="/initLogin" />
</b:bean>
</b:property>
<b:property name="authenticationFailureHandler">
<b:bean class="tool.security.LoginFailureHandler">
<b:property name="redirectUrl" value="/login" />
</b:bean>
</b:property>
</b:bean>
<b:bean id="loginExistsFilter" class="tool.security.LoginExistsFilter">
<b:property name="loginUrl" value="/login" />
</b:bean>
<b:bean id="authenticationEntryPoint"
class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
<b:constructor-arg value="/login" /> <!-- loginFormUrl -->
</b:bean>
<b:bean id="loginAuthenticationProvider"
class="tool.security.LoginAuthenticationProvider">
<b:property name="loginService" ref="loginService" />
</b:bean>
<b:bean id="loginService" class="tool.security.LoginServiceImpl">
<b:property name="userDao" ref="userDao" />
<b:property name="userTF" ref="userTF" />
<b:property name="passwordEncoder" ref="passwordEncoder" />
</b:bean>
<b:bean id="userDao" class="tool.user.impl.MongoUserDao"></b:bean>
<b:bean id="userTF" class="tool.user.UserTFImpl"></b:bean>
<http security="none" pattern="/css/**" />
<http security="none" pattern="/js/**" />
<http security="none" pattern="/login" />
<http security="none" pattern="/loginRedirect" />
<http security="none" pattern="/invalidbrowser" />
<http entry-point-ref="authenticationEntryPoint"
access-decision-manager-ref="accessDecisionManager">
<session-management invalid-session-url="/login?timeout=1"
session-fixation-protection="newSession">
<concurrency-control max-sessions="1"
error-if-maximum-exceeded="true" />
</session-management>
<custom-filter ref="authenticationProcessingFilter"
position="FORM_LOGIN_FILTER" />
<custom-filter ref="loginExistsFilter" before="FILTER_SECURITY_INTERCEPTOR" />
<csrf disabled="true" />
</http>
<global-method-security
access-decision-manager-ref="accessDecisionManager"
secured-annotations="enabled" />