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.surf.exception.AuthenticationException;
22  
23  /**
24   * Interface that defines an Authenticator.  Authenticators are used to
25   * retrieve cookies and tokens from a remote service based on credentials
26   * which are locally managed and passed to the remote service.
27   * 
28   * Authenticator objects are used when a "token" must be passed to the endpoint
29   * and the current token is either invalid or non-existent. The Connectors must
30   * then handshake with the endpoint to acquire a token.
31   * 
32   * Tokens are not always necessary. An example is HTTP Basic Authentication
33   * where user names and passwords are sent on every request. Alternatively, of
34   * course, you may wish only to authenticate on the first request and then pass
35   * the Authenticate hash on every subsequent request.
36   * 
37   * In that case, the role of the authenticate() method would be to handshake
38   * with the endpoint to acquire this hash.
39   * 
40   * @author muzquiano
41   */
42  public interface Authenticator
43  {
44      /**
45       * Authenticate against the given Endpoint URL with the supplied Credentials
46       * 
47       * @return The connector session instance
48       * 
49       * @throws AuthenticationException on error
50       */
51      public ConnectorSession authenticate(String endpoint, Credentials credentials, ConnectorSession connectorSession)
52              throws AuthenticationException;
53  
54      /**
55       * Returns whether the current connector session has been authenticated or not
56       * 
57       * @param endpoint
58       * @param connectorSession
59       * @return
60       */
61      public boolean isAuthenticated(String endpoint, ConnectorSession connectorSession);
62  }