| 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.apache.commons.logging.Log; |
| 27 |
|
import org.apache.commons.logging.LogFactory; |
| 28 |
|
|
| 29 |
|
import org.springframework.beans.factory.InitializingBean; |
| 30 |
|
|
| 31 |
|
import org.springframework.util.Assert; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
4 |
public class MethodInvocationPrivilegeEvaluator implements InitializingBean { |
| 45 |
|
|
| 46 |
|
|
| 47 |
3 |
protected static final Log logger = LogFactory.getLog(MethodInvocationPrivilegeEvaluator.class); |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
private AbstractSecurityInterceptor securityInterceptor; |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
public void afterPropertiesSet() throws Exception { |
| 56 |
4 |
Assert.notNull(securityInterceptor, "SecurityInterceptor required"); |
| 57 |
4 |
} |
| 58 |
|
|
| 59 |
|
public boolean isAllowed(MethodInvocation mi, Authentication authentication) { |
| 60 |
4 |
Assert.notNull(mi, "MethodInvocation required"); |
| 61 |
4 |
Assert.notNull(mi.getMethod(), "MethodInvocation must provide a non-null getMethod()"); |
| 62 |
|
|
| 63 |
4 |
ConfigAttributeDefinition attrs = securityInterceptor.obtainObjectDefinitionSource().getAttributes(mi); |
| 64 |
|
|
| 65 |
4 |
if (attrs == null) { |
| 66 |
0 |
if (securityInterceptor.isRejectPublicInvocations()) { |
| 67 |
0 |
return false; |
| 68 |
|
} |
| 69 |
|
|
| 70 |
0 |
return true; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
4 |
if ((authentication == null) || (authentication.getAuthorities() == null) |
| 74 |
|
|| (authentication.getAuthorities().length == 0)) { |
| 75 |
0 |
return false; |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
try { |
| 79 |
4 |
securityInterceptor.getAccessDecisionManager().decide(authentication, mi, attrs); |
| 80 |
2 |
} catch (AccessDeniedException unauthorized) { |
| 81 |
2 |
if (logger.isDebugEnabled()) { |
| 82 |
0 |
logger.debug(mi.toString() + " denied for " + authentication.toString(), unauthorized); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
2 |
return false; |
| 86 |
2 |
} |
| 87 |
|
|
| 88 |
2 |
return true; |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
public void setSecurityInterceptor(AbstractSecurityInterceptor securityInterceptor) { |
| 92 |
4 |
Assert.notNull(securityInterceptor, "AbstractSecurityInterceptor cannot be null"); |
| 93 |
4 |
Assert.isTrue(MethodInvocation.class.equals(securityInterceptor.getSecureObjectClass()), |
| 94 |
|
"AbstractSecurityInterceptor does not support MethodInvocations"); |
| 95 |
4 |
Assert.notNull(securityInterceptor.getAccessDecisionManager(), |
| 96 |
|
"AbstractSecurityInterceptor must provide a non-null AccessDecisionManager"); |
| 97 |
4 |
this.securityInterceptor = securityInterceptor; |
| 98 |
4 |
} |
| 99 |
|
} |