私は AOP に少し慣れていないので、直面している問題について混乱しています。@AuthorizeUser
プレゼンテーション層のメソッドに作用する注釈があります。ユーザーがそのメソッドを実行する権限があるかどうかを確認する必要があります。のコードは次のAuthorizeUserAspect
とおり
です。
@Aspect
public class AuthorizeUserAspect {
@AuthoWired
private UserService service;
@Before(value = "@annotation(com.company.annotation.AuthorizeUser)")
public void isAuthorized(JoinPoint jp) {
// Check if the user has permission or not
// executing some Service Layer services and
// Persistence Layer, corresponding to that
service.checkUser();
// Is there a way I can make this method Conditional. something like:
if ( /* User has permission */ ) {
// do nothing, so the method will be executed after this
}
else {
// 1) Prevent the Method to be executed [and/or]
// 2) Pass some Parameters to the method for checking [and/or]
// 3) Execute another method on that class [e.g showAccessDenied()]
}
}
}
この質問Spring MVC + Before Advice check securityに少し似ています。ただし、文字列を返すことを提案しました(つまり、「Not OK」)。私のアプリケーションには 2 種類の UI (Struts と Jersey) があるため、2 種類の戻り値の型 (String
とResponse
それぞれ) があります。ですから、それが最善の方法ではないかもしれないと思います。
この場合の回避策を教えていただければ幸いです。
これは良いアプローチですか?