1 | 20 | |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.shiro.aspectj; |
20 | |
|
21 | |
import org.aspectj.lang.JoinPoint; |
22 | |
import org.aspectj.lang.annotation.Aspect; |
23 | |
import org.aspectj.lang.annotation.Before; |
24 | |
import org.aspectj.lang.annotation.Pointcut; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
@Aspect() |
31 | 2 | public class ShiroAnnotationAuthorizingAspect { |
32 | |
|
33 | |
private static final String pointCupExpression = |
34 | |
"execution(@org.apache.shiro.authz.annotation.RequiresAuthentication * *(..)) || " + |
35 | |
"execution(@org.apache.shiro.authz.annotation.RequiresGuest * *(..)) || " + |
36 | |
"execution(@org.apache.shiro.authz.annotation.RequiresPermissions * *(..)) || " + |
37 | |
"execution(@org.apache.shiro.authz.annotation.RequiresRoles * *(..)) || " + |
38 | |
"execution(@org.apache.shiro.authz.annotation.RequiresUser * *(..))"; |
39 | |
|
40 | |
@Pointcut(pointCupExpression) |
41 | 0 | public void anyShiroAnnotatedMethod(){} |
42 | |
|
43 | |
@Pointcut(pointCupExpression) |
44 | |
void anyShiroAnnotatedMethodCall(JoinPoint thisJoinPoint) { |
45 | 0 | } |
46 | |
|
47 | 1 | private AspectjAnnotationsAuthorizingMethodInterceptor interceptor = |
48 | 1 | new AspectjAnnotationsAuthorizingMethodInterceptor(); |
49 | |
|
50 | |
@Before("anyShiroAnnotatedMethodCall(thisJoinPoint)") |
51 | |
public void executeAnnotatedMethod(JoinPoint thisJoinPoint) throws Throwable { |
52 | 18 | interceptor.performBeforeInterception(thisJoinPoint); |
53 | 10 | } |
54 | |
} |