Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for 
change notification.

The "Tapestry5HowToCreateADispatcher2" page has been changed by 
BasileChandesris.
http://wiki.apache.org/tapestry/Tapestry5HowToCreateADispatcher2?action=diff&rev1=4&rev2=5

--------------------------------------------------

  In the article [[Tapestry5HowToCreateADispatcher]] we covered the basics of 
creating a Dispatcher and getting it into the pipeline. This quick article is a 
supplement to that one, continuing the example of implementing an access 
control mechanism. Specifically, we will cover how to access request-specific 
state objects (ASOs) from a singleton service (our access controller). If you 
haven't already read that article, you should do so before proceeding.
  
- Before reading this be sure to first read about how Tapestry manages 
application state:
+ Before reading this be sure to first read about how Tapestry5 manages 
application state:
  
- http://tapestry.apache.org/tapestry5/tapestry-core/guide/appstate.html
+ http://tapestry.apache.org/tapestry5/guide/appstate.html
  
  This is a fairly quick and painless read and should get you up to speed on 
what application state is, when and why you need it, how to use it, and the 
basics of how it works. The following javadocs are also worth pointing out:
  
- 
[[http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/annotations/ApplicationState.html|ApplicationState]],
 
[[http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/services/ApplicationStateManager.html|ApplicationStateManager]]
+ 
[[http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/annotations/ApplicationState.html|ApplicationState]],
 
[[http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/services/ApplicationStateManager.html|ApplicationStateManager]]
  
  == A Glance at the Problem ==
  The access controller we've implemented is a singleton service. It doesn't 
make sense to implement it per-request as the only per-request state it needs 
are the access permissions of the requesting user. However we can't just 
annotate a service field with @!ApplicationState as we normally would in a page 
or component. This annotation ties a field to a request, but singleton services 
have no such association to any request. They are instantiated once and 
accessible by all concurrent requests, at the same time. 
@@ -28, +28 @@

  
  == A Solution in Code ==
  
- Here is how we could implement the solution. Assume that we have a class 
named !UserPermissions for storing the permissions, and that it contains a 
method named canAccess. This method returns a boolean showing if the user can 
access the resource (page) represented by the 
[[http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/services/Request.html|Request]]
 object.
+ Here is how we could implement the solution. Assume that we have a class 
named !UserPermissions for storing the permissions, and that it contains a 
method named canAccess. This method returns a boolean showing if the user can 
access the resource (page) represented by the 
[[http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/services/Request.html|Request]]
 object.
  
  {{{
  import java.io.IOException;
  
- import org.apache.tapestry.services.ApplicationStateManager;
+ import org.apache.tapestry5.services.ApplicationStateManager;
- import org.apache.tapestry.services.Request;
+ import org.apache.tapestry5.services.Request;
- import org.apache.tapestry.services.Response;
+ import org.apache.tapestry5.services.Response;
  
  public class AccessController implements Dispatcher {
        
@@ -93, +93 @@

  
  == Conclusion ==
  
- It has been noted on the mailing list that access control can be implemented 
using this same technique, but as a 
[[http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry/services/RequestFilter.html|RequestFilter]]
 instead. I haven't tried this but the same concepts regarding ASOs apply.
+ It has been noted on the mailing list that access control can be implemented 
using this same technique, but as a 
[[http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/services/RequestFilter.html|RequestFilter]]
 instead. I haven't tried this but the same concepts regarding ASOs apply.
  
  Any suggestions, corrections, or other furtherings on this document are most 
welcome. If you'd like to chat with me about this, you can find me in #tapestry 
on irc.freenode.net (chrislewis).
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to