SpringSecurity4JSF托管bean预授权注释
我希望有人能帮助我将@PreAuthorize注释与托管bean集成在一起。在过去的几个小时里,我一直在努力让它发挥作用,但显然我缺少了一些东西。我在web上的研究表明,全局方法安全元素可以与spring或aspectj一起使用。因为我不想将我的托管bean声明为Springbean,所以我选择使用aspectj。由于某种原因,尽管预授权注释被完全忽略。我没有收到任何错误,所有的编译和运行都很好,但是没有对托管bean进行安全检查。显然aspectj需要某种编织???也许我走错了路,还有一条更容易的路……不确定。将Tomcat7与JSF2.2和SpringSecurity4结合使用。我在类上有注释,但这可能是我的问题。我假设将它放在类上将使用其默认构造函数方法 有人能给点建议吗?(配置如下) security.xmlSpringSecurity4JSF托管bean预授权注释,jsf,spring-security,authorization,Jsf,Spring Security,Authorization,我希望有人能帮助我将@PreAuthorize注释与托管bean集成在一起。在过去的几个小时里,我一直在努力让它发挥作用,但显然我缺少了一些东西。我在web上的研究表明,全局方法安全元素可以与spring或aspectj一起使用。因为我不想将我的托管bean声明为Springbean,所以我选择使用aspectj。由于某种原因,尽管预授权注释被完全忽略。我没有收到任何错误,所有的编译和运行都很好,但是没有对托管bean进行安全检查。显然aspectj需要某种编织???也许我走错了路,还有一条更容
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<http use-expressions="true">
<headers>
<frame-options policy="SAMEORIGIN" />
</headers>
<intercept-url pattern="/admin/**" access="hasRole('Admin')" />
<intercept-url pattern="/cms/**" access="hasAnyRole('Admin','CMS_Admin')" />
<form-login login-page='/login' default-target-url="/" />
<logout invalidate-session="true" logout-success-url="/" />
<csrf disabled="true"/>
</http>
<b:bean name="bcryptEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/>
<b:bean name="iberisUserDetailsService" class="com.bizznetworxonline.iberis.core.web.controllers.admin.security.IberisUserDetailsService"/>
<authentication-manager>
<authentication-provider user-service-ref='iberisUserDetailsService'>
<password-encoder ref="bcryptEncoder"/>
</authentication-provider>
</authentication-manager>
<global-method-security mode="aspectj" pre-post-annotations="enabled" proxy-target-class="true">
</global-method-security>
</b:beans>
当您指示JSF创建bean而不是Spring时,
@PreAuthorize
在这里没有什么意义。即使在使用Spring创建bean时,它的使用也是针对方法的(即使您可以注释一个类以处理其所有方法):
这里Spring检查当前登录的用户是否具有用户角色,以便他能够创建联系人
在您的问题中,似乎要限制对整个视图的访问,那么为什么不按照security.xml声明中的方式进行呢
<intercept-url pattern="/products/product_management.xhtml" access="hasRole('USER')" />
通过这种方式,Spring security在其Web筛选器中检查权限,这甚至更好
另见:
@ManagedBean
@ViewScoped
@PreAuthorize("hasAnyRole('Admin')")
public class ProductManagement
@PreAuthorize("hasRole('ROLE_USER')")
public void create(Contact contact);
<intercept-url pattern="/products/product_management.xhtml" access="hasRole('USER')" />