org.alfresco.bm.http
Class AuthenticatedHttpEventProcessor

java.lang.Object
  extended by org.alfresco.bm.event.AbstractEventProcessor
      extended by org.alfresco.bm.http.AuthenticatedHttpEventProcessor
All Implemented Interfaces:
EventProcessor, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware
Direct Known Subclasses:
CreateUser

public abstract class AuthenticatedHttpEventProcessor
extends AbstractEventProcessor

A base class used for EventProcessors that makes use of HTTP-calls that should be done when authenticated against Alfresco. Subclasses can just do the HTTP-call(s) without having to worry about authentication. Use #executeHttpMethodAuthenticated(HttpMethod, String) instead of using HttpClient manually or #executeHttpMethodAsAdmin(HttpMethod) to run as Alfresco Administrator.

Supports both BASIC Authentication (default) and Ticket-based authentication. In case ticket-based authentication is used, the ticket value is stored on the userdata-provider and a new ticket is fetched transparantly when the ticket is expired.

Author:
Frederik Heremans

Nested Class Summary
static interface AuthenticatedHttpEventProcessor.HttpRequestCallback<T>
          Callback used when executing HTTP-request.
 
Field Summary
 
Fields inherited from class org.alfresco.bm.event.AbstractEventProcessor
DEFAULT_WARN_DELAY, logger
 
Constructor Summary
AuthenticatedHttpEventProcessor(HttpClientProvider httpProvider, AuthenticationDetailsProvider authDetailProvider)
           
 
Method Summary
protected
<T> T
executeHttpMethodAsAdmin(org.apache.commons.httpclient.HttpMethod method, AuthenticatedHttpEventProcessor.HttpRequestCallback<T> callback)
          Execute the given method, authenticated as the Alfresco Administrator.
protected
<T> T
executeHttpMethodAuthenticated(org.apache.commons.httpclient.HttpMethod method, String userName, AuthenticatedHttpEventProcessor.HttpRequestCallback<T> callback)
          Execute the given method, authenticated as the given user.
 AuthenticationDetailsProvider getAuthDetailProvider()
           
 HttpClientProvider getHttpProvider()
           
abstract  EventResult processEvent(Event event)
          Process an event.
 void setTicketBasedAuthentication(boolean ticketBasedAuthentication)
          Enable ticket-based authentication.
 
Methods inherited from class org.alfresco.bm.event.AbstractEventProcessor
getWarnDelay, register, setBeanName, setEventName, setEventNames, setRegistry, setWarnDelay
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuthenticatedHttpEventProcessor

public AuthenticatedHttpEventProcessor(HttpClientProvider httpProvider,
                                       AuthenticationDetailsProvider authDetailProvider)
Parameters:
httpProvider - provider class for http-client
authDetailProvider - provider for authentication details
Method Detail

setTicketBasedAuthentication

public void setTicketBasedAuthentication(boolean ticketBasedAuthentication)
Enable ticket-based authentication. If set to false, BASIC Authentication will be used instead. Defaults to false.

Parameters:
ticketBasedAuthentication - whether or not to use ticket for authentication

getHttpProvider

public HttpClientProvider getHttpProvider()
Returns:
the HttpClientProvider used by this class.

getAuthDetailProvider

public AuthenticationDetailsProvider getAuthDetailProvider()
Returns:
the AuthenticationDetailsProvider used by this class.

processEvent

public abstract EventResult processEvent(Event event)
                                  throws Exception
Description copied from interface: EventProcessor
Process an event.

NOTE: All errors are treated as terminal i.e. there will be no follow-up events published. The event and result services are provided to allow event processing to be aware of previous and future work. If the service is used to modify queues, the results could be unexpected e.g. clearing the queue will not always mean that no more events will be processed.

Parameters:
event - the event (along with associated data)
Returns:
the result of the process (includes errors and next events)
Throws:
Exception

executeHttpMethodAuthenticated

protected <T> T executeHttpMethodAuthenticated(org.apache.commons.httpclient.HttpMethod method,
                                               String userName,
                                               AuthenticatedHttpEventProcessor.HttpRequestCallback<T> callback)
Execute the given method, authenticated as the given user. Automatically closes the response-stream to release the connection. If response should be extracted, this should be done in the AuthenticatedHttpEventProcessor.HttpRequestCallback.

Parameters:
method - method to execute
userName - name of user to authenticate
callback - called after http-call is executed. When callback returns, the response stream is closed, so all respose-related operations should be done in the callback. Can be null.
Returns:
result returned by the callback or status-code if no callback is given.

executeHttpMethodAsAdmin

protected <T> T executeHttpMethodAsAdmin(org.apache.commons.httpclient.HttpMethod method,
                                         AuthenticatedHttpEventProcessor.HttpRequestCallback<T> callback)
Execute the given method, authenticated as the Alfresco Administrator.

Parameters:
method - method to execute
callback - called after http-call is executed. When callback returns, the response stream is closed, so all respose-related operations should be done in the callback. Can be null.
Returns:
result returned by the callback or null if no callback is given.


Copyright © 2012. All Rights Reserved.