View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.springframework.extensions.webscripts.connector;
20  
21  import org.springframework.extensions.config.RemoteConfigElement.ConnectorDescriptor;
22  
23  /**
24   * An implementation of an Alfresco Connector that can be used to conncet
25   * to an Alfresco Repository and issue URL invokes against it.
26   * 
27   * The Alfresco Connector extends the Http Connector and provides the
28   * additional functionality of stamping a ticket onto the outgoing request.
29   * 
30   * The ticket is retrieved from the connector session.
31   * 
32   * @author muzquiano
33   */
34  public class AlfrescoConnector extends HttpConnector
35  {
36      private static final String UNAUTHENTICATED_MODE_GUEST = "guest";
37      private static final String PARAM_TICKETNAME_ALF_TICKET = "alf_ticket";
38  
39      /**
40       * Instantiates a new alfresco connector.
41       * 
42       * @param descriptor the descriptor
43       * @param endpoint the endpoint
44       */
45      public AlfrescoConnector(ConnectorDescriptor descriptor, String endpoint)
46      {
47          super(descriptor, endpoint);
48      }
49  
50      /* (non-Javadoc)
51       * @see org.alfresco.connector.HttpConnector#stampCredentials(org.alfresco.connector.RemoteClient, org.alfresco.connector.ConnectorContext)
52       */
53      @Override
54      protected void applyRequestAuthentication(RemoteClient remoteClient, ConnectorContext context)
55      {
56          // support for Alfresco ticket-based authentication - retrieving the ticket
57          // from the connector context is a special case for Flash based apps that do
58          // not share the same session and get at user connector session information
59          String alfTicket = null;
60          
61          if (context != null)
62          {
63              alfTicket = context.getParameters().get(PARAM_TICKETNAME_ALF_TICKET);
64          }
65          
66          if (getCredentials() != null)
67          {
68              // if this connector is managing session info
69              if (getConnectorSession() != null)
70              {
71                  // apply alfresco ticket from connector session - i.e. previous login attempt
72                  alfTicket = (String)getConnectorSession().getParameter(AlfrescoAuthenticator.CS_PARAM_ALF_TICKET);
73              }
74          }
75          
76          if (alfTicket != null)
77          {
78              remoteClient.setTicket(alfTicket);
79              remoteClient.setTicketName(PARAM_TICKETNAME_ALF_TICKET);
80          }
81          else
82          {
83              // otherwise, if we don't have an alfresco ticket
84              // we can slip into "guest mode"
85              String unauthenticatedMode = this.descriptor.getUnauthenticatedMode();
86              if (UNAUTHENTICATED_MODE_GUEST.equalsIgnoreCase(unauthenticatedMode))
87              {
88                  remoteClient.setTicketName("guest");
89                  remoteClient.setTicket("true");
90              }
91          }
92      }
93  }