I am trying to get the component inside an advice and if the page invoked is
extends "SecurePage", then I have to check the security credentials on that
request. A typical cross-cutting concern which is best served by an advice.
But its not working. Anything I am doing wrong here? Could this below
problem be a classloader problem?
@Match("SecureInterface")
public static void adviceSecureRequest(MethodAdviceReceiver receiver, final
Request request,
final ComponentClassResolver
componentClassResolver,
final RequestPageCache
cache, final AuthService authService){
MethodAdvice advice = new MethodAdvice(){
public void advise(Invocation invocation){
//SOME PLUMBING CODE TO GET TO THE COMPONENT.
//DON'T KNOW IF THERE IS AN EASIER WAY.
String path = request.getPath();
int actionEvent = path.lastIndexOf('.');
if (actionEvent != -1)
path = path.substring(0, actionEvent);
int nextslashx = path.length();
String pageName;
while (true) {
pageName = path.substring(1, nextslashx);
if (!pageName.endsWith("/") &&
componentClassResolver.isPageName(pageName))
break;
nextslashx = path.lastIndexOf('/', nextslashx - 1);
if (nextslashx <= 1)
break;
}
if (componentClassResolver.isPageName(pageName)){
Page page = cache.get(pageName);
//NOW WE HAVE A HANDLE ON THE COMPONENT
Component component = page.getRootComponent();
//THE BELOW IF CONDITION ALWAYS FAILS.
//AS AN EXAMPLE, THIS "component" could be a
"PayPage" page which extends "SecurePage".
//SO component HERE SHOULD ACTUALLY BE "PayPage" AND
THEREFORE A "SecurePage". BUT, THE CONDITION ISN'T SATISFIED
//I DOUBLE CHECKED THE HASHCODE of "PayPage" in
BeginRender of PayPage and that of "component" over here AND BOTH ARE
IDENTICAL.
//SO I AM CONFUSED WHY THE BELOW CONDITION WOULD FAIL.
//IS THIS A CLASSLOADER PROBLEM???? IF THE HASHCODE IS
THE SAME
//THEN THEY ARE THE SAME OBJECTS, SO WHY IS THE BELOW
CONDITION FAILING?
if (component instanceof SecurePage)
authService.checkSecurity(invocation.getParameter(0)); // I NEED TO CALL
THIS TO CHECK THE CREDENTIALS IF THE PAGE IS A "SecurePage"
}
invocation.proceed();
} // end advice method of inner class
}; // end inner class
receiver.adviseAllMethods(advice);
}
--
View this message in context:
http://old.nabble.com/How-to-get-the-Component-inside-advice--tp28100055p28100055.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]