Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] newbie AspectJ questions

I'm new to AspectJ, and direct use of aspects in general. I've been using them indirectly with the Spring Framework and the Acegi security system that complements spring. But now I need to implement my own aspect to provide security on my domain objects.

Based on the Acegi documentation, I've got the following aspect:

package edu.ucsc.whisper.security.aspectj;

import org.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor;
import org.acegisecurity.intercept.method.aspectj.AspectJCallback;

import org.springframework.beans.factory.InitializingBean;

import edu.ucsc.whisper.core.AclSecurable;

public aspect DomainObjectInstanceSecurityAspect
    implements InitializingBean
{
    private AspectJSecurityInterceptor securityInterceptor;
    
    pointcut domainObjectInstanceExecution(): target( AclSecurable )
        && execution( public * *(..) ) && !within( DomainObjectInstanceSecurityAspect );
    
    Object around(): domainObjectInstanceExecution()
    {
        if( this.securityInterceptor != null )
        {
            AspectJCallback callback = new AspectJCallback()
                {
                    public Object proceedWithObject()
                    {
                        return( proceed() );
                    }
                };
            
            return( this.securityInterceptor.invoke( thisJoinPoint, callback ) );
        }
        else
        {
            return( proceed() );
        }
    }
    
    public AspectJSecurityInterceptor getSecurityInterceptor()
    {
        return( securityInterceptor );
    }
    
    public void setSecurityInterceptor( AspectJSecurityInterceptor newInterceptor )
    {
        securityInterceptor = newInterceptor;
    }
    
    public void afterPropertiesSet()
        throws Exception
    {
        if( securityInterceptor == null )
        {
            throw( new IllegalArgumentException( "SecurityInterceptor required." ) );
        }
    }
}


As you can see, I only want this aspect applied to objects that implement the AclSecurable interface. However, when I look at the output classes (I'm using maven to build), I've got one or more ...$AjcClosure#.class files for each class in the project, and my JUnit test cases. I'm not sure why they would be needed for classes that aren't even indirectly related to the AclSecurable class/interface hierarchy. And I really don't see why the JUnit test cases (which are defined in a separate source tree and compiled to a separate class tree) should be getting this treatment.

But worse (in my mind) is that when I build, I'm getting the following output for every method in my project: 

{package}/{class}.java:55 [warning] can not implement lazyTjp on this joinpoint method-execution(void {package}.{class}.{method}( {parameters} )) because around advice is used [Xlint:canNotImplementLazyTjp]
public void setEditUserAccountInfoValidator( EditUserAccountInfoValidator newValidator )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        see also: /Users/mark/Documents/school/whisper/ftr116_mslater/src/aspectj/edu/ucsc/whisper/security/aspectj/DomainObjectInstanceSecurityAspect.java:18::0

I've done some searching and I can't even figure out what it means that it can't implement lazyTjp, so I don't know if this can be safely ignored, or if it means I've got a bug someplace.

I'm also getting a few messages that look like this:

edu/ucsc/whisper/security/aspectj/DomainObjectInstanceSecurityAspect.java:18 [warning] serialVersionUID of type edu.ucsc.whisper.core.DefaultAuthority needs to be set because of added non-private method hashCode_aroundBody10 [Xlint:needsSerialVersionUIDField]

And once again, I'm not sure what this is talking about... is it suggesting that I need to add new fields to objects that (in this case) I don't even want the aspect applied to?

I'm finding this more confusing than I'd expected it to be. Any help?

Thanks,
Mark


Back to the top