2013-10-07 6 views
2

영어로 죄송합니다. 왜 스프링 보안에서 작동하는 방법이 isAuthenticated()입니까? JSF에서 사용 :스프링 보안 3 isAuthenticated() 작동하지 않음

#{loginMB.authentication.authenticated} 

<sec:authorize access="hasRole('ROLE_ADMIN')"> 
    test 
</sec:authorize> 

작동하지 않습니다. 모든 시간은 true을 반환하며, 인증을 받았는지 여부는 알 수 없습니다.

는 역할을 보여주는 경우

#{loginMB.authentication.authorities} 

그것은 바로 표시되고, 역할을 인증 할 때 역할을 인증되지 않은 경우, [ROLE_ADMIN]입니다 [ROLE_ANONYMOUS]이다.

언제 문제가 있습니까? 알렉산드르 말했듯이 확인 AnonymousAuthenticationToken에 대한 LoginBean에 metod isAuthenticated()을 만들

경우

==== 업데이트 ==== :

public boolean isAuthenticated(){ 

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 
    return authentication != null && !(authentication instanceof AnonymousAuthenticationToken) && authentication.isAuthenticated(); 

} 

그것은 노력하고 있습니다. 고마워요 알렉산드르. 그러나 권한 부여 태그가 작동하지 않습니다. JSF 페이지에 추가 할 경우 :

<sec:authorize access="hasRole('ROLE_ANONYMOUS')"> 
    ROLE_ANONYMOUS 
</sec:authorize> 
<sec:authorize access="hasRole('ROLE_ADMIN')"> 
    ROLE_ADMIN 
</sec:authorize> 

이 페이지는 ROLE_ANONYMOUS 및 ROLE_ADMIN을 인쇄합니다. 왜? 해결

<?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> 
+0

잘 작동합니다. 이 방법을 사용하려면'AnonymousAuthenticationToken'을 확인하기 만하면됩니다. –

+0

Check AnonymousAuthenticationToken을 위해 LoginBean에서 metod isAuthenticated()를 만들었습니다. 그러나 스프링 보안 인증 태그는 작동하지 않습니다. – z3r9

+0

무슨 뜻인가요? –

답변

3

문제점 :

==== 2 ====에게

애플리케이션 컨텍스트-security.xml 업데이트. 그것은이 작동

public boolean isAuthenticated(){ 

     Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 
     return authentication != null && !(authentication instanceof AnonymousAuthenticationToken) && authentication.isAuthenticated(); 

    } 

:

  1. 알렉산드르 말했듯이 확인으로 AnonymousAuthenticationToken에 대한 LoginBean에서 metod IsAuthenticated는()를 작성하는 경우. 고마워요 알렉산드르.

  2. JSF 페이지의 authorize 태그를 사용하여 here을 읽으십시오. 그리고 나는 it 문제가있었습니다.

관련 문제