Tôi muốn triển khai bảo mật khai báo với Spring/AOP và chú thích. Như bạn thấy trong ví dụ mã tiếp theo, tôi có các chú thích bị giới hạn với paramter "allowedRoles" để xác định ai được phép thực hiện một phương thức được đề xuất.Spring AOP: cách nhận các chú thích của phương pháp được đề xuất
@Restricted(allowedRoles="jira-administrators")
public void setPassword(...) throws UserMgmtException {
// set password code
...
}
Bây giờ, vấn đề là trong Lời khuyên của tôi, tôi không có quyền truy cập vào các chú thích định nghĩa:
public Object checkPermission(ProceedingJoinPoint pjp) throws Throwable {
Signature signature = pjp.getSignature();
System.out.println("Allowed:" + rolesAllowedForJoinPoint(pjp));
...
}
private Restricted rolesAllowedForJoinPoint(ProceedingJoinPoint thisJoinPoint)
{
MethodSignature methodSignature = (MethodSignature) thisJoinPoint.getSignature();
Method targetMethod = methodSignature.getMethod();
return targetMethod.getAnnotation(Restricted.class);
}
Các phương pháp trên luôn luôn trả về null (không có chú thích tìm thấy ở tất cả). Có một giải pháp đơn giản cho việc này không?
Tôi đã đọc điều gì đó về việc sử dụng tác nhân AspectJ nhưng tôi không muốn sử dụng tác nhân này.
Cảm ơn rất nhiều, đó là lý do. – hugri