15
Aug 2014
by
小川 岳史
なぜ MethodSecurityExpressionRoot クラスが public じゃないないのか。そして下記チケットが wontfix になっているのか。
https://jira.spring.io/browse/SEC-1691
前のプロジェクトで @EnableGlobalMethodSecurity で独自の関数を作成したいと思った時、 MethodSecurityExpressionRoot クラスがパッケージスコープでそれを諦めたけど、よく見たらチケットにこのようにコメントされていた。
You can also add your own expressions using static method invocations or by using the @beanName syntax to invoke other beans in the app context.
なるほど、@(アットマーク)で beanName を指定できるのか。つまり DI できるのね。
それなら wontfix でもいいか。
たとえば、こんな感じでExpression用のサービスクラスを定義して、
@Service
@Transactional
public class PermissionService {
public boolean hasSomePermission(Order order) {
...skip
}
}
こんな感じで呼び出せる。
@Service
@Transactional
public class SomeService {
@PostAuthorize("@permissionService.hasSomePermission(returnObject)")
public Something doSomething(Long id) {
...skip
return something;
}
}
いいっすね。