java - Spring Authentication object is null -
i'm trying access authentication object in order user's name, authentication object null.
authentication authentication = securitycontextholder.getcontext().getauthentication(); if (authentication == null) { log.warn("authentication null during current user name!"); return anonymous_user; } return authentication.getname();
however can call (from same method):
httpservletrequest req = (httpservletrequest)inrequest; string user = req.getremoteuser();
and discover user set correctly.
edit: found stated problem may due not having gone through security filter chain.
so added in filter chain, no success.
here web.xml:
<filter> <filter-name>springsecurityfilterchainproxy</filter-name> <filter-class>org.springframework.web.filter.delegatingfilterproxy</filter-class> </filter> <filter-mapping> <filter-name>springsecurityfilterchainproxy</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>cors</filter-name> <filter-class>com.us.tsp.rest.corsfilter</filter-class> </filter> <filter-mapping> <filter-name>cors</filter-name> <url-pattern>/jaxrs/*</url-pattern> </filter-mapping>
here spring config xml:
<bean id="securitycontextpersistencefilter" class="org.springframework.security.web.context.securitycontextpersistencefilter"/> <bean id="springsecurityfilterchainproxy" class="org.springframework.security.web.filterchainproxy"> <sec:filter-chain-map > <sec:filter-chain pattern="/**" filters=" securitycontextpersistencefilter" /> </sec:filter-chain-map> </bean>
end edit
here security.xml:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:sec="http://www.springframework.org/schema/security" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd"> <sec:http use-expressions="true"> <sec:intercept-url pattern="/**" access="isauthenticated()" /> <sec:http-basic /> </sec:http> <sec:ldap-server url="xxxxxxxxxxxxxxxx" manager-dn="xxxxxxxxxxxx" manager-password="xxxxxxxxx" /> <sec:authentication-manager alias="authenticationmanager"> <sec:ldap-authentication-provider user-search-base="xxxxx" user-search-filter="xxxxxx" group-search-filter="member={0}" group-search-base="xxxxxxxxx" role-prefix="role_" /> </sec:authentication-manager> </beans>
Comments
Post a Comment