jsf 2 - spring security 3 isAuthenticated() not working -
sorry english. why not working method isauthenticated()
in spring security? use in jsf:
#{loginmb.authentication.authenticated} <sec:authorize access="hasrole('role_admin')"> test </sec:authorize>
it not working. time return true
, if authenticated or not.
if showing roles:
#{loginmb.authentication.authorities}
it show right, when authenticated role [role_admin]
, when not authenticated role [role_anonymous]
.
when problem?
==== updated ====
if create metod isauthenticated()
in loginbean
check anonymousauthenticationtoken
said aleksandr:
public boolean isauthenticated(){ authentication authentication = securitycontextholder.getcontext().getauthentication(); return authentication != null && !(authentication instanceof anonymousauthenticationtoken) && authentication.isauthenticated(); }
it working. thank aleksandr. authorize tag not working. if add in jsf page:
<sec:authorize access="hasrole('role_anonymous')"> role_anonymous </sec:authorize> <sec:authorize access="hasrole('role_admin')"> role_admin </sec:authorize>
it print role_anonymous , role_admin. why?
==== updated 2 ====
applicationcontext-security.xml:
<?xml version="1.0" encoding="utf-8"?> <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="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-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> <beans:import resource="applicationcontext.xml"/> <global-method-security jsr250-annotations="enabled" /> <http auto-config="true" use-expressions="true"> <form-login login-page="/pages/login.html" authentication-failure-url="/fail.html"/> <intercept-url pattern="/**" access="permitall" /> </http> <authentication-manager alias="authenticationmanager"> <authentication-provider user-service-ref="userdao"> <password-encoder hash="plaintext" /> </authentication-provider> </authentication-manager> </beans:beans>
problem solved.
if create metod isauthenticated() in loginbean check anonymousauthenticationtoken said aleksandr:
public boolean isauthenticated(){ authentication authentication = securitycontextholder.getcontext().getauthentication(); return authentication != null && !(authentication instanceof anonymousauthenticationtoken) && authentication.isauthenticated(); }
it working. thank aleksandr.
for work authorize tag in jsf page read here. , had it problem.
Comments
Post a Comment