Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Is this possible with Aspect/J?

Hi Cees,

You can write a pointcut which captures first argument, and pass this
argument into your around advice.
E.g. pointcut authorisableMethod(String key) :  execution(* *.*(String,
..)) && args(key)

"key" matches the first parameter passed to your method, since the
parameter list is specified as 'String, ...' - The first parameter is a
String and the other paramaters can be any Type and have any number of
other parameters. (in this case * *.* matches all methods)

Your around advice will use this "key" value to do the authorising.  A
call to proceed() without any arguments will cause the original method
to continue executing *with all of its original parameters*.

E.g. 
Object around(String key) : authorisableMethod(key) {
	Logger log = ????????;
	Account account = AuthenticationHelper.getInstance
().getAccountByKey (key);
	if (account == null) {
		log.logFailedLogin();
		return new AttributeArrayResult("invalid key");
	} else {
		Object thingy = proceed();
		return thingy;
	}
}	

Hopefully this should work,

Fintan


-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Cees De Groot
Sent: 07 July 2006 10:34
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Is this possible with Aspect/J?


Hi,

I have a SOAP interface where one method, login(), generates a cookie
which all other methods have to send as the first parameter. So all the
other methods look like:

       public AttributeArrayResult getExtendedTransactionStatus(String
key, long transactionId) {
               Account account = AuthenticationHelper.getInstance
().getAccountByKey (key);
               if (account == null) {
                       logFailedLogin();
                       return new AttributeArrayResult("invalid key");
               }

              // ... do actual work
       }

Clearly, the authentication check is an aspect that screams to be
refactored away. However, the various methods have different signatures
with different numbers of arguments, and I haven't been able to find how
to write around advice that handles this. Is this possible at all?

(in Smalltalk, I'd just do

self authenticatedWith: key do: [
    // ... do actual work
]

but using the whole anonymous inner class mess in Java just to pass a
bit of code actually makes it less readable)
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


* ** *** ** * ** *** ** * ** *** ** * 
This email and any files transmitted with it are confidential and 
intended solely for the use of the individual or entity to whom they 
are addressed. 
Any views or opinions presented are solely those of the author, and do not necessarily  represent those of ESB. 
If you have received this email in error please notify the sender. 
 
Although ESB scans e-mail and attachments for viruses, it does not guarantee 
that either are virus-free and accepts no liability for any damage sustained 
as a result of viruses. 
 
* ** *** ** * ** *** ** * ** *** ** *



Back to the top