|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.intercept.method; |
|
17 |
| |
|
18 |
| import org.acegisecurity.AccessDeniedException; |
|
19 |
| import org.acegisecurity.Authentication; |
|
20 |
| import org.acegisecurity.ConfigAttributeDefinition; |
|
21 |
| |
|
22 |
| import org.acegisecurity.intercept.AbstractSecurityInterceptor; |
|
23 |
| |
|
24 |
| import org.aopalliance.intercept.MethodInvocation; |
|
25 |
| |
|
26 |
| import org.springframework.beans.factory.InitializingBean; |
|
27 |
| |
|
28 |
| import org.springframework.util.Assert; |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| public class MethodInvocationPrivilegeEvaluator implements InitializingBean { |
|
49 |
| |
|
50 |
| |
|
51 |
| private AbstractSecurityInterceptor securityInterceptor; |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
2
| public boolean isAllowed(MethodInvocation mi, Authentication authentication) {
|
|
56 |
2
| Assert.notNull(authentication, "Authentication required");
|
|
57 |
2
| Assert.notNull(authentication.getAuthorities(),
|
|
58 |
| "Authentication must provided non-null GrantedAuthority[]s"); |
|
59 |
2
| Assert.notNull(mi, "MethodInvocation required");
|
|
60 |
2
| Assert.notNull(mi.getMethod(),
|
|
61 |
| "MethodInvocation must provide a non-null getMethod()"); |
|
62 |
| |
|
63 |
2
| ConfigAttributeDefinition attrs = securityInterceptor.obtainObjectDefinitionSource()
|
|
64 |
| .getAttributes(mi); |
|
65 |
| |
|
66 |
2
| if (attrs == null) {
|
|
67 |
0
| if (securityInterceptor.isRejectPublicInvocations()) {
|
|
68 |
0
| return false;
|
|
69 |
| } |
|
70 |
| |
|
71 |
0
| return true;
|
|
72 |
| } |
|
73 |
| |
|
74 |
2
| if (authentication == null) {
|
|
75 |
0
| return false;
|
|
76 |
| } |
|
77 |
| |
|
78 |
2
| try {
|
|
79 |
2
| securityInterceptor.getAccessDecisionManager().decide(authentication,
|
|
80 |
| mi, attrs); |
|
81 |
| } catch (AccessDeniedException unauthorized) { |
|
82 |
1
| unauthorized.printStackTrace();
|
|
83 |
| |
|
84 |
1
| return false;
|
|
85 |
| } |
|
86 |
| |
|
87 |
1
| return true;
|
|
88 |
| } |
|
89 |
| |
|
90 |
2
| public void setSecurityInterceptor(
|
|
91 |
| AbstractSecurityInterceptor securityInterceptor) { |
|
92 |
2
| Assert.notNull(securityInterceptor,
|
|
93 |
| "AbstractSecurityInterceptor cannot be null"); |
|
94 |
2
| Assert.isTrue(MethodInvocation.class.equals(
|
|
95 |
| securityInterceptor.getSecureObjectClass()), |
|
96 |
| "AbstractSecurityInterceptor does not support MethodInvocations"); |
|
97 |
2
| Assert.notNull(securityInterceptor.getAccessDecisionManager(),
|
|
98 |
| "AbstractSecurityInterceptor must provide a non-null AccessDecisionManager"); |
|
99 |
2
| this.securityInterceptor = securityInterceptor;
|
|
100 |
| } |
|
101 |
| |
|
102 |
2
| public void afterPropertiesSet() throws Exception {
|
|
103 |
2
| Assert.notNull(securityInterceptor, "SecurityInterceptor required");
|
|
104 |
| } |
|
105 |
| } |