【发布时间】:2016-10-24 22:46:49
【问题描述】:
我希望有人可以帮助我将 @PreAuthorize 注释与托管 bean 集成。在过去的几个小时里,我一直试图让它工作,但显然我缺少一些东西。我在网络上的研究表明 global-method-security 元素可以与 spring 或 aspectj 一起使用。因为我不想将我的托管 bean 声明为 spring bean,所以我选择使用 aspectj。出于某种原因,尽管 PreAuthorize 注释被完全忽略。我没有收到任何错误,一切都编译并运行良好,但托管 bean 没有安全检查。显然aspectj需要某种编织???也许我正在接近这种错误的方式,并且有一种更简单的方法......不确定。将 Tomcat 7 与 JSF 2.2 和 Spring Security 4 一起使用。我在类上有注释,但这可能是我的问题。我假设把它放在类上会使用它的默认构造方法。
有人可以建议吗? (以下配置)
安全性.xml
<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>
Maven 构建
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
托管 Bean
@ManagedBean
@ViewScoped
@PreAuthorize("hasAnyRole('Admin')")
public class ProductManagement
【问题讨论】:
标签: jsf spring-security authorization