JPA Entity クラスがあり、そのメソッドに保護された注釈を追加して remove メソッドを保護しようとしています。JPA エンティティがアプリケーション コンテキスト xml で定義されていないため、context.xml で次を使用して、アスペクト 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>