Jsf 2 spring security 3已验证()不工作
对不起我的英语。为什么Spring security中的工作方法Jsf 2 spring security 3已验证()不工作,jsf-2,spring-security,Jsf 2,Spring Security,对不起我的英语。为什么Spring security中的工作方法没有经过身份验证()?我在JSF中使用: #{loginMB.authentication.authenticated} <sec:authorize access="hasRole('ROLE_ADMIN')"> test </sec:authorize> 它显示正确,当身份验证时角色是[role\u ADMIN],当未经身份验证时角色是[role\u ANONYMOUS] 什么时候出问题了 =
没有经过身份验证()?我在JSF中使用:
#{loginMB.authentication.authenticated}
<sec:authorize access="hasRole('ROLE_ADMIN')">
test
</sec:authorize>
它显示正确,当身份验证时角色是[role\u ADMIN]
,当未经身份验证时角色是[role\u ANONYMOUS]
什么时候出问题了
==更新====
如果create metodisAuthenticated()
在LoginBean
中检查匿名身份验证令牌
,如Aleksandr所述:
public boolean isAuthenticated(){
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
return authentication != null && !(authentication instanceof AnonymousAuthenticationToken) && authentication.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>
匿名角色
角色管理
它打印角色\匿名和角色\管理员。为什么?
===更新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>
问题已解决
如果create metod在LoginBean中为check AnonymousAuthenticationToken进行身份验证(),如Aleksandr所述:
public boolean isAuthenticated(){
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
return authentication != null && !(authentication instanceof AnonymousAuthenticationToken) && authentication.isAuthenticated();
}
public boolean isAuthenticated(){
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
return authentication != null && !(authentication instanceof AnonymousAuthenticationToken) && authentication.isAuthenticated();
}
它正在工作。谢谢你,亚历山大
For将工作授权标记在JSF页面中读取。我遇到了问题
它工作得很好。如果要使用此方法,只需检查AnonymousAuthenticationToken
。我在LoginBean中为检查AnonymousAuthenticationToken创建了metod isAuthenticated(),这是可行的。但是spring security Authorization标记不起作用。我在“更新”一节的主要帖子中添加了我的意思。access
属性使用表达式。如果你是说hasRole('ROLE\u ADMIN')
它不起作用。我编辑了主要帖子。