JPA实体上的@Secured Spring Security Annotation无法正常工作

时间:2013-06-19 08:48:54

标签: spring jpa spring-security spring-annotations

我有一个JPA Entity类,我试图通过向该方法添加安全注释来保护remove方法。我的应用程序上下文xml中没有定义我的JPA实体,因此我在context.xml中使用了以下内容来尝试启用Aspect J.

<sec:global-method-security secured-annotations="enabled" mode="aspectj"  />

我使用maven插件进行静态编译时编织,在我的日志中我看不出任何问题

Generating code...

[INFO] 
[INFO] --- aspectj-maven-plugin:1.2:compile (default) @ SubmissionTool ---
[WARNING] advice defined in org.springframework.scheduling.aspectj.AbstractAsyncExecutionAspect has not been applied [Xlint:adviceDidNotMatch]
[WARNING] advice defined in org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl has not been applied [Xlint:adviceDidNotMatch]
[WARNING] advice defined in org.springframework.mock.staticmock.AbstractMethodMockingControl has not been applied [Xlint:adviceDidNotMatch]
[INFO] 

我已经定义了注释的JPA实体是一个抽象类,它有使用remove方法的子类。我的JPA类

上存在以下注释
@Entity
@Configurable

,删除方法就像

@Transactional
    @Secured(value = {"ROLE_ADMINS"})
    public void remove() {
        if (this.entityManager == null) this.entityManager = entityManager();
        if (this.entityManager.contains(this)) {
            this.entityManager.remove(this);
        } else {
            Submission attached = Submission.findSubmission(this.id);
            this.entityManager.remove(attached);
        }
    }

角色ROLE_ADMINS应该只允许具有该角色的用户删除实体,但是所有用户都能够删除该实体。有什么想法吗?

以下是我的pom寻找编织插件的方式

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.2</version> 
                <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>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <sources>
                        <source>
                          <basedir>src/main/java/</basedir>
                          <includes>
                            <include>**/entity/*.java</include>                         
                          </includes>                        
                        </source>
                      </sources>
                    <outxml>true</outxml>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-aspects</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>

0 个答案:

没有答案