org.nuiton.web.tapestry5.services
Class ServiceAuthenticationImpl<U,A extends Annotation>

java.lang.Object
  extended by org.nuiton.web.tapestry5.services.ServiceAuthenticationImpl<U,A>
Type Parameters:
U - user type
A - annotation type used to identify which page need authentication
All Implemented Interfaces:
ServiceAuthentication<U>

public class ServiceAuthenticationImpl<U,A extends Annotation>
extends Object
implements ServiceAuthentication<U>

This class is an abstract implementation of ServiceAuthentication. This service use ApplicationStateManager to manage connected user. You can inherit this class to provide a momre specific authentication managmentan depends on user type and annotation used to identify pages that need authentication. This behavior is done in isAllowed(Class) that detect the annotation on the page (ex : RequiresAuthentication annotation) and call the method checkAuthorizations(Object, Annotation) that is implemented by default to do nothing (return true).

AppModule contribution : Exemple with MyUser type for user and RequiresAnnotation for annotation :
  public ServiceAuthentication buildServiceAuthentication(ApplicationStateManager stateManager) {
      return new ServiceAuthenticationImpl(stateManager);
  }
 
No need to contribute to ApplicationStateManager to provide instantiation of user. Even this service used the default constructor to instanciate a new user.

Created: 3 mai 2010

Version:
$Id: ServiceAuthenticationImpl.java 49 2011-01-26 16:08:25Z tchemit $
Author:
fdesbois

Field Summary
protected  Class<A> annotationClass
          Annotation type to detect pages that need authentication (ex : RequiresAuthentication).
protected  Class<U> userClass
          User type
 
Constructor Summary
ServiceAuthenticationImpl(org.apache.tapestry5.services.ApplicationStateManager stateManager, Class<U> userClass, Class<A> annotationClass)
          Constructor to call in subclasses.
 
Method Summary
protected  boolean checkAuthorizations(U user, A annotation)
          Check the connected user authorizations.
 U getNewUserInstance()
          Default instanciation of the user.
 U getUserConnected()
          Get the current user connected.
 boolean isAllowed(Class<?> page)
          Detect the annotation in the given page.
 boolean isUserConnected()
          Detect if user is connected.
 void setUserConnected(U user)
          Set the connected user to user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

userClass

protected Class<U> userClass
User type


annotationClass

protected Class<A extends Annotation> annotationClass
Annotation type to detect pages that need authentication (ex : RequiresAuthentication).

Constructor Detail

ServiceAuthenticationImpl

public ServiceAuthenticationImpl(org.apache.tapestry5.services.ApplicationStateManager stateManager,
                                 Class<U> userClass,
                                 Class<A> annotationClass)
Constructor to call in subclasses.

Parameters:
stateManager - from Tapestry
userClass - to identify which type of user is managed
annotationClass - to identify which type of annotation is managed for authentication treatment.
Method Detail

isUserConnected

public boolean isUserConnected()
Description copied from interface: ServiceAuthentication
Detect if user is connected.

Specified by:
isUserConnected in interface ServiceAuthentication<U>
Returns:
true if the user is connected, false otherwise.

getUserConnected

public U getUserConnected()
Description copied from interface: ServiceAuthentication
Get the current user connected.

Specified by:
getUserConnected in interface ServiceAuthentication<U>
Returns:
the user connected

setUserConnected

public void setUserConnected(U user)
Description copied from interface: ServiceAuthentication
Set the connected user to user.

Specified by:
setUserConnected in interface ServiceAuthentication<U>
Parameters:
user - that will be connected

isAllowed

public boolean isAllowed(Class<?> page)
Detect the annotation in the given page. If annotation is detected, the user authorizations need to be check using checkAuthorizations(Object, Annotation) method.

Specified by:
isAllowed in interface ServiceAuthentication<U>
Parameters:
page - to check
Returns:
true if connected user can display the page, false otherwise

checkAuthorizations

protected boolean checkAuthorizations(U user,
                                      A annotation)
Check the connected user authorizations. Called in isAllowed(Class) method after detect the annotation on the current page. Override this method to provide more specific authentication managment.

Parameters:
user - current user connected.
annotation - from page to check authorizations.
Returns:
true if the user is granted, false otherwise

getNewUserInstance

public U getNewUserInstance()
Default instanciation of the user. The user class need a default constructor.

Specified by:
getNewUserInstance in interface ServiceAuthentication<U>
Returns:
a new user instance.


Copyright © 2010-2011 CodeLutin. All Rights Reserved.