1
0
mirror of synced 2026-08-05 01:36:56 +00:00

Initial AspectJ support.

This commit is contained in:
Ben Alex
2004-10-18 06:41:20 +00:00
parent 992cf44b36
commit 7b0145fba7
8 changed files with 321 additions and 20 deletions
@@ -0,0 +1,31 @@
/* Copyright 2004 Acegi Technology Pty Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.acegisecurity.intercept.method.aspectj;
/**
* Called by the {@link AspectJSecurityInterceptor} when it wishes for the
* AspectJ processing to continue. Typically implemented in the
* <code>around()</code> advice as a simple <code>return proceed();</code>
* statement.
*
* @author Ben Alex
* @version $Id$
*/
public interface AspectJCallback {
//~ Methods ================================================================
public Object proceedWithObject();
}
@@ -0,0 +1,109 @@
/* Copyright 2004 Acegi Technology Pty Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.acegisecurity.intercept.method.aspectj;
import net.sf.acegisecurity.intercept.AbstractSecurityInterceptor;
import net.sf.acegisecurity.intercept.InterceptorStatusToken;
import net.sf.acegisecurity.intercept.ObjectDefinitionSource;
import net.sf.acegisecurity.intercept.method.MethodDefinitionSource;
import org.aspectj.lang.JoinPoint;
/**
* Provides security interception of AspectJ method invocations.
*
* <p>
* The <code>ObjectDefinitionSource</code> required by this security
* interceptor is of type {@link MethodDefinitionSource}. This is shared with
* the AOP Alliance based security interceptor
* (<code>MethodSecurityInterceptor</code>), since both work with Java
* <code>Method</code>s.
* </p>
*
* <p>
* The secure object type is <code>org.aspectj.lang.JointPoint</code>, which is
* passed from the relevant <code>around()</code> advice. The
* <code>around()</code> advice also passes an anonymous implementation of
* {@link AspectJCallback} which contains the call for AspectJ to continue
* processing: <code>return proceed();</code>.
* </p>
*
* <P>
* Refer to {@link AbstractSecurityInterceptor} for details on the workflow.
* </p>
*
* @author Ben Alex
* @version $Id$
*/
public class AspectJSecurityInterceptor extends AbstractSecurityInterceptor {
//~ Instance fields ========================================================
private MethodDefinitionSource objectDefinitionSource;
//~ Methods ================================================================
public void setObjectDefinitionSource(MethodDefinitionSource newSource) {
this.objectDefinitionSource = newSource;
}
public MethodDefinitionSource getObjectDefinitionSource() {
return this.objectDefinitionSource;
}
public void afterPropertiesSet() {
super.afterPropertiesSet();
if (!this.getAccessDecisionManager().supports(JoinPoint.class)) {
throw new IllegalArgumentException(
"AccessDecisionManager does not support JointPoint");
}
if (!this.getRunAsManager().supports(JoinPoint.class)) {
throw new IllegalArgumentException(
"RunAsManager does not support JointPoint");
}
}
/**
* This method should be used to enforce security on a
* <code>JoinPoint</code>.
*
* @param jp The AspectJ joint point being invoked which requires a
* security decision
* @param advisorProceed the advice-defined anonymous class that implements
* <code>AspectJCallback</code> containing a simple <code>return
* proceed();</code> statement
*
* @return The returned value from the method invocation
*/
public Object invoke(JoinPoint jp, AspectJCallback advisorProceed) {
Object result;
InterceptorStatusToken token = super.beforeInvocation(jp);
try {
result = advisorProceed.proceedWithObject();
} finally {
super.afterInvocation(token);
}
return result;
}
public ObjectDefinitionSource obtainObjectDefinitionSource() {
return this.objectDefinitionSource;
}
}
@@ -0,0 +1,8 @@
<html>
<body>
Enforces security for AspectJ <code>JointPoint</code>s, delegating secure
object callbacks to the calling aspect.
<p>Refer to the reference guide for information on usage.
</body>
</html>