Re: How to get the Component inside advice?
> I hope to have a simple authentication > framework, possibly as a Tapestry extension, at some point in the next > couple of months. Great news Howard, I will look forward to that!! - Original Message - From: "Howard Lewis Ship" To: "Tapestry users" Sent: Wednesday, 31 March, 2010 22:59:19 GMT +02:00 Athens, Beirut, Bucharest, Istanbul Subject: Re: How to get the Component inside advice? Chances are your instanceof is failing because you put the SecurePage interface into the pages or components package; move it up a level, to a non-controlled package, so that the services layer and the component layer can agree. Anything inside the pages or components packages (or mixins or base) will be loaded by a different class loader, and this causes these apparently anomalous ClassCastExceptions. But Thiago is right, Tapestry has a proper place for this kind of thing, if you check my blog, you'll see an article where I head down the same path as you (I've recently done this kind of thing for a couple of different clients). I hope to have a simple authentication framework, possibly as a Tapestry extension, at some point in the next couple of months. On Wed, Mar 31, 2010 at 12:31 PM, satb wrote: > >> Advice is for services, not pages and components. > > Thanks for the response. > > Yes. That is true. I want to do one other thing on the methods of the > service if the request is originating from a "SecurePage" -- which is to > check the credentials. Isn't advice the right thing for it? Thats what the > above advice is trying to do except the "instaceof" check is always > returning false. > > I guess what is causing some concern to me is -- why would "component > instanceof SecurePage" return false? > -- > View this message in context: > http://old.nabble.com/How-to-get-the-Component-inside-advice--tp28100055p28100745.html > Sent from the Tapestry - User mailing list archive at Nabble.com. > > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > -- Howard M. Lewis Ship Creator of Apache Tapestry The source for Tapestry training, mentoring and support. Contact me to learn how I can get you up and productive in Tapestry fast! (971) 678-5210 http://howardlewisship.com - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: How to get the Component inside advice?
Chances are your instanceof is failing because you put the SecurePage interface into the pages or components package; move it up a level, to a non-controlled package, so that the services layer and the component layer can agree. Anything inside the pages or components packages (or mixins or base) will be loaded by a different class loader, and this causes these apparently anomalous ClassCastExceptions. But Thiago is right, Tapestry has a proper place for this kind of thing, if you check my blog, you'll see an article where I head down the same path as you (I've recently done this kind of thing for a couple of different clients). I hope to have a simple authentication framework, possibly as a Tapestry extension, at some point in the next couple of months. On Wed, Mar 31, 2010 at 12:31 PM, satb wrote: > >> Advice is for services, not pages and components. > > Thanks for the response. > > Yes. That is true. I want to do one other thing on the methods of the > service if the request is originating from a "SecurePage" -- which is to > check the credentials. Isn't advice the right thing for it? Thats what the > above advice is trying to do except the "instaceof" check is always > returning false. > > I guess what is causing some concern to me is -- why would "component > instanceof SecurePage" return false? > -- > View this message in context: > http://old.nabble.com/How-to-get-the-Component-inside-advice--tp28100055p28100745.html > Sent from the Tapestry - User mailing list archive at Nabble.com. > > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > -- Howard M. Lewis Ship Creator of Apache Tapestry The source for Tapestry training, mentoring and support. Contact me to learn how I can get you up and productive in Tapestry fast! (971) 678-5210 http://howardlewisship.com - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: How to get the Component inside advice?
On Wed, 31 Mar 2010 16:31:17 -0300, satb wrote: Advice is for services, not pages and components. Thanks for the response. Yes. That is true. I want to do one other thing on the methods of the service if the request is originating from a "SecurePage" -- which is to check the credentials. Isn't advice the right thing for it? Again, advice is for services, not pages and components. If you want to advise pages and components, you'll need to implement a ComponentClassTransformWorker. To check the origin of a request, you'll need to use the Referrer HTTP header or put something in the URL. Thats what the above advice is trying to do except the "instaceof" check is always returning false. Please post your code or we cannot help you. -- Thiago H. de Paula Figueiredo Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor Owner, software architect and developer, Ars Machina Tecnologia da Informação Ltda. http://www.arsmachina.com.br - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: How to get the Component inside advice?
> Advice is for services, not pages and components. Thanks for the response. Yes. That is true. I want to do one other thing on the methods of the service if the request is originating from a "SecurePage" -- which is to check the credentials. Isn't advice the right thing for it? Thats what the above advice is trying to do except the "instaceof" check is always returning false. I guess what is causing some concern to me is -- why would "component instanceof SecurePage" return false? -- View this message in context: http://old.nabble.com/How-to-get-the-Component-inside-advice--tp28100055p28100745.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: How to get the Component inside advice?
On Wed, 31 Mar 2010 15:37:36 -0300, satb wrote: I am trying to get the component inside an advice and if the page invoked isextends "SecurePage", then I have to check the security credentials on that request. A way better way of doing it is to implement a ComponentEventRequestFilter and contribute it to the service ComponentEventRequestHandler. Take a look at the graph in the end of http://tapestry.formos.com/nightly/tapestry5/guide/request.html to have a better look at how Tapestry processes requests. A typical cross-cutting concern which is best served by an advice. Advice is for services, not pages and components. By the way, looking at your advice, there's the ComponentEventLinkEncoder service that provides methods like PageRenderRequestParameters decodePageRenderRequest(Request request) to deal with extracting the page name from a request. -- Thiago H. de Paula Figueiredo Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor Owner, software architect and developer, Ars Machina Tecnologia da Informação Ltda. http://www.arsmachina.com.br - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
How to get the Component inside advice?
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: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org