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(HttpRequestBase, String) instead of using HttpClient manually or #executeHttpMethodAsAdmin(HttpRequestBase) 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 user data-provider and a new ticket is fetched transparantly when the ticket is expired.

Author:
Frederik Heremans, Derek Hulley

Field Summary
 
Fields inherited from class org.alfresco.bm.event.AbstractEventProcessor
DEFAULT_WARN_DELAY, logger
 
Constructor Summary
AuthenticatedHttpEventProcessor(org.alfresco.http.HttpClientProvider httpClientProvider, org.alfresco.http.AuthenticationDetailsProvider authDetailProvider, String baseUrl)
           
 
Method Summary
protected
<T> T
executeHttpMethodAsAdmin(org.apache.http.client.methods.HttpRequestBase request, org.alfresco.http.HttpRequestCallback<T> callback)
          Execute the given method, authenticated as the Alfresco Administrator.
protected
<T> T
executeHttpMethodAsUser(org.apache.http.client.methods.HttpRequestBase request, String username, org.alfresco.http.HttpRequestCallback<T> callback)
          Execute the given method, authenticated as the given user.
 org.alfresco.http.AuthenticationDetailsProvider getAuthDetailProvider()
           
 String getFullUrlForPath(String path)
           
 org.alfresco.http.HttpClientProvider getHttpProvider()
           
protected  void releaseResources(org.apache.http.client.methods.HttpRequestBase request, org.apache.http.HttpResponse response)
          Release resources associated with an HTTP request.
 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
 
Methods inherited from interface org.alfresco.bm.event.EventProcessor
processEvent
 

Constructor Detail

AuthenticatedHttpEventProcessor

public AuthenticatedHttpEventProcessor(org.alfresco.http.HttpClientProvider httpClientProvider,
                                       org.alfresco.http.AuthenticationDetailsProvider authDetailProvider,
                                       String baseUrl)
Parameters:
httpClientProvider - provider class for http-client
authDetailProvider - provider for authentication details
baseUrl - the URL to append to
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 org.alfresco.http.HttpClientProvider getHttpProvider()
Returns:
the HttpClientProvider used by this class.

getAuthDetailProvider

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

getFullUrlForPath

public String getFullUrlForPath(String path)
Parameters:
path - relative path of the URL from alfresco host.
Returns:
full URL including hostname and port for the given path.

executeHttpMethodAsUser

protected <T> T executeHttpMethodAsUser(org.apache.http.client.methods.HttpRequestBase request,
                                        String username,
                                        org.alfresco.http.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 HttpRequestCallback.

Parameters:
request - request to execute
username - name of user to authenticate as
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:
whatever the callback dictates

executeHttpMethodAsAdmin

protected <T> T executeHttpMethodAsAdmin(org.apache.http.client.methods.HttpRequestBase request,
                                         org.alfresco.http.HttpRequestCallback<T> callback)
Execute the given method, authenticated as the Alfresco Administrator.

Parameters:
request - request 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:
whatever the callback dictates

releaseResources

protected void releaseResources(org.apache.http.client.methods.HttpRequestBase request,
                                org.apache.http.HttpResponse response)
Release resources associated with an HTTP request. This method handles exceptions internall so no try-catch is required.

Parameters:
request - the HTTP request that might have open resources (null allowed)


Copyright © 2012. All Rights Reserved.