pt.digitalis.dif.controller
Class AbstractDIFDispatcher

java.lang.Object
  extended by pt.digitalis.dif.controller.AbstractDIFDispatcher
All Implemented Interfaces:
IDIFDispatcher

public abstract class AbstractDIFDispatcher
extends Object
implements IDIFDispatcher

This class is the heart of the framework. Its responsibilities include receive and validate the incoming DIFRequest, the request processing (if the request is valid) and the routing of the stage-generated DIFResponse. AbstractDIFDispatcher implements the TEMPLATE METHOD design pattern (see GoF's "Design Patterns: Elements of Reusable Object-Oriented Software"). As such, the executeTaskSteps() method is declared final. This method defines the dispatching-cycle steps, and these steps must be always run in the same order to all the requests. There is a set of protected methods that correspond to the aforementioned dispatching-cycle steps. These methods can be overridden in derived classes if one wants to modify the behavior associated with a given step. ChALs should call a particular controller so this class (the superclass) is declared abstract to inhibit instantiation.

Author:
Rodrigo Goçalves rgoncalves@digitalis.pt, Pedro Viegas pviegas@digitalis.pt
Created on:
2007/03/16

Field Summary
protected  ControllerException authenticationException
          If an authentication error has occurred
protected  IDIFContext difContext
          The execution context.
static String INVALID_STAGE_ERROR_MESSAGE
          The messae for invalid stage requests
protected  IAuthenticationManager theAuthenticationManager
          The Authentication Manager
protected  IAuthorizationManager theAuthorizationManager
          The authorization manager.
protected  pt.digitalis.utils.config.IConfigurations theConfigurations
          The configuration manager.
protected  IIdentityManager theIdentityManager
          The identity manager.
protected  ISessionManager theSessionManager
          The session manager.
protected  IStage theStage
          The stage to be executed.
 
Constructor Summary
AbstractDIFDispatcher(IIdentityManager theIdentityManager, IAuthenticationManager theAuthenticationManager, IAuthorizationManager theAuthorizationManager, ISessionManager theSessionManager, pt.digitalis.utils.config.IConfigurations theConfigurationManager)
          Default constructor.
 
Method Summary
protected  void authenticate()
          Authenticates a user on the framework.
protected  void authorize()
          Check the user permissions to run a given stage.
protected  boolean checkLicense()
          This method checks if the license is valid.
protected  void conclude()
          Concludes the execution cycle.
protected  DIFResponse createResponse(IStageInstance stageInstance)
          Generates the response that will be sent back to AbstractChAL from the request's execution context.
 DIFResponse dispatch(IDIFRequest difRequest)
          This method serves as an interface between the AbstractDIFDispatcher and the calling AbstractChAL.
protected  void doAfterLogin(SSOInfo ssoInfo)
          Actions to perform after a successful login
protected  void doAfterLogout(SSOInfo ssoInfo)
          Actions to perform after a successful logout
protected  IStageInstance execute()
          Executes the appropriate tasks to serve the request.
 ControllerException getAuthenticationException()
           
 String getChannelID()
           
protected  IDIFContext getContext()
          Inspector for the execution context.
protected  IIdentityManager getIdentityManager()
          Inspector for the identity manager.
protected  Map<String,String> getMessages()
          Lazy loading getter of messages
protected  SSOInfo getSSOInfo()
          Used to inject the SSO Info for the dispatcher authentication process
protected  boolean handleException(Exception exception)
          Handles the occurred exception to redirect to a given handler and perform cleanup actions
protected abstract  void handleNonAuthorizedAccess(IStageInstance stageInstance, ControllerException exception)
          Handles a non authorized access
protected  DispatcherAuthenticationResult performAuthentication()
          Implements the authentication execution logic
static void performCleanup(IDIFContext context, boolean success)
          Perform any clean up tasks that have been contributed by ...
protected  void postAuthentication(DispatcherAuthenticationResult result)
          Post Authentication execution
protected  void preAuthentication()
          Pre Authentication execution
 void setAuthenticationException(ControllerException authenticationException)
           
protected  void validate(Boolean isRedirection)
          Validates the session and the stage.
protected  boolean validateUserCredentials(String userId, String password)
          Validate the user credentials
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INVALID_STAGE_ERROR_MESSAGE

public static final String INVALID_STAGE_ERROR_MESSAGE
The messae for invalid stage requests

See Also:
Constant Field Values

authenticationException

protected ControllerException authenticationException
If an authentication error has occurred


difContext

protected IDIFContext difContext
The execution context.


theAuthenticationManager

protected IAuthenticationManager theAuthenticationManager
The Authentication Manager


theAuthorizationManager

protected IAuthorizationManager theAuthorizationManager
The authorization manager.


theConfigurations

protected pt.digitalis.utils.config.IConfigurations theConfigurations
The configuration manager.


theIdentityManager

protected IIdentityManager theIdentityManager
The identity manager.


theSessionManager

protected ISessionManager theSessionManager
The session manager.


theStage

protected IStage theStage
The stage to be executed.

Constructor Detail

AbstractDIFDispatcher

public AbstractDIFDispatcher(IIdentityManager theIdentityManager,
                             IAuthenticationManager theAuthenticationManager,
                             IAuthorizationManager theAuthorizationManager,
                             ISessionManager theSessionManager,
                             pt.digitalis.utils.config.IConfigurations theConfigurationManager)
Default constructor. This constructor must be inherited in the extended classes and injected with the instances from the IoC

Parameters:
theIdentityManager - the identity manager
theAuthenticationManager - the authentication manager
theAuthorizationManager - the authorization manager
theSessionManager - the authentication manager
theConfigurationManager - the configurations manager
Method Detail

performCleanup

public static final void performCleanup(IDIFContext context,
                                        boolean success)
                                 throws ControllerException
Perform any clean up tasks that have been contributed by ...

Parameters:
context - the context
success - T if the stage was successfully executed
Throws:
ControllerException

authenticate

protected void authenticate()
                     throws ControllerException
Authenticates a user on the framework. The method is defined with protected scope to allow overriding on the subclasses.

Throws:
ControllerException - when any runtime exception is thrown or the authentication process has failed

authorize

protected void authorize()
                  throws ControllerException
Check the user permissions to run a given stage. The method is defined with protected scope to allow overriding on the subclasses.

Throws:
ControllerException - when any runtime exception is thrown

checkLicense

protected boolean checkLicense()
This method checks if the license is valid.

Returns:
T if stage is registered, F otherwise

conclude

protected void conclude()
                 throws ControllerException
Concludes the execution cycle. Touches the session to ensure it stays alive and returns any service objects to the pool (not implemented as of version 0.0.1). If session is not active, it's not kept alive and thus on the next request the access will be denied. 'Finalize' would be better name but it's forbidden due to a name-clash with java.lang.Object's finalize() method.

Throws:
ControllerException - when any runtime exception is thrown

createResponse

protected DIFResponse createResponse(IStageInstance stageInstance)
                              throws ControllerException
Generates the response that will be sent back to AbstractChAL from the request's execution context.

Parameters:
stageInstance - the executed stage instance
Returns:
The response to send back to AbstractChAL
Throws:
ControllerException - if an exception has occurred

dispatch

public final DIFResponse dispatch(IDIFRequest difRequest)
                           throws BusinessFlowException,
                                  ControllerException
Description copied from interface: IDIFDispatcher
This method serves as an interface between the AbstractDIFDispatcher and the calling AbstractChAL. It is invoked by the AbstractChAL on a AbstractDIFDispatcher object. The method verifies the request's integrity, generates the appropriate context and schedules the request for service. When the execution is finished it returns the response to the AbstractChAL. If some step on the execution flow doesn't happen as expected, an exception is raised.

Specified by:
dispatch in interface IDIFDispatcher
Parameters:
difRequest - The AbstractChAL-originated DIFRequest object
Returns:
The response object to be delivered to the calling AbstractChAL
Throws:
BusinessFlowException - when an exception is thrown by the stage's init/execute steps
ControllerException - when any runtime exception is thrown in a controller step
See Also:
IDIFDispatcher.dispatch(pt.digitalis.dif.controller.interfaces.IDIFRequest)

doAfterLogin

protected void doAfterLogin(SSOInfo ssoInfo)
Actions to perform after a successful login

Parameters:
ssoInfo - the single sign-on object

doAfterLogout

protected void doAfterLogout(SSOInfo ssoInfo)
Actions to perform after a successful logout

Parameters:
ssoInfo - the single sign-on object

execute

protected IStageInstance execute()
                          throws BusinessFlowException,
                                 ControllerException
Executes the appropriate tasks to serve the request.

Returns:
the executed stage instance
Throws:
BusinessFlowException - when an exception is thrown by the stage's init/execute steps
ControllerException - when any runtime exception is thrown

getAuthenticationException

public ControllerException getAuthenticationException()
Returns:
the authenticationException

getChannelID

public String getChannelID()
Specified by:
getChannelID in interface IDIFDispatcher
Returns:
the channel ID read from the Channel annotation

getContext

protected IDIFContext getContext()
Inspector for the execution context.

Returns:
the execution context

getIdentityManager

protected IIdentityManager getIdentityManager()
Inspector for the identity manager.

Returns:
the defined identity manager

getMessages

protected Map<String,String> getMessages()
Lazy loading getter of messages

Returns:
the messages

getSSOInfo

protected SSOInfo getSSOInfo()
Used to inject the SSO Info for the dispatcher authentication process

Returns:
the SSOInfo if available

handleException

protected boolean handleException(Exception exception)
                           throws BusinessFlowException,
                                  ControllerException
Handles the occurred exception to redirect to a given handler and perform cleanup actions

Parameters:
exception - the raised exception
Returns:
T if the exception was handled and should not be re-throwned
Throws:
BusinessFlowException
ControllerException

handleNonAuthorizedAccess

protected abstract void handleNonAuthorizedAccess(IStageInstance stageInstance,
                                                  ControllerException exception)
                                           throws ControllerException
Handles a non authorized access

Parameters:
stageInstance - the stage instance requested
exception - the exception thrown
Throws:
ControllerException - if the error was not a non authorized access

performAuthentication

protected DispatcherAuthenticationResult performAuthentication()
                                                        throws ControllerException
Implements the authentication execution logic

Returns:
the authentication result
Throws:
ControllerException

postAuthentication

protected void postAuthentication(DispatcherAuthenticationResult result)
Post Authentication execution

Parameters:
result - the DispatcherAuthenticationResult

preAuthentication

protected void preAuthentication()
Pre Authentication execution


setAuthenticationException

public void setAuthenticationException(ControllerException authenticationException)
Parameters:
authenticationException - the authenticationException to set

validate

protected final void validate(Boolean isRedirection)
                       throws ControllerException
Validates the session and the stage. This method always runs. To avoid overriding on base classes it is declared final. Session validation includes checking if the stage is active and hasn't timed out. Stage validation includes checking if the stage is registrable and if so checks if the license is valid.

Parameters:
isRedirection -
Throws:
ControllerException - when any runtime exception is thrown

validateUserCredentials

protected boolean validateUserCredentials(String userId,
                                          String password)
                                   throws IdentityManagerException,
                                          ControllerException
Validate the user credentials

Parameters:
userId - the userId
password - the password
Returns:
validation result
Throws:
IdentityManagerException - if a IdentityManager Exception occurs.
ControllerException


Copyright © 2014 Digitalis Informática Lda. All Rights Reserved.