This project has retired. For details please refer to its Attic page.
AbstractAuthenticationProvider xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.client.bindings.spi;
20  
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.apache.chemistry.opencmis.commons.SessionParameter;
25  import org.w3c.dom.Element;
26  
27  /**
28   * Authentication provider class.
29   */
30  public abstract class AbstractAuthenticationProvider implements SessionAwareAuthenticationProvider {
31  
32      private static final long serialVersionUID = 1L;
33  
34      private BindingSession session;
35  
36      /**
37       * Sets the {@link BindingSession} the authentication provider lives in.
38       */
39      public void setSession(BindingSession session) {
40          this.session = session;
41      }
42  
43      /**
44       * Returns {@link BindingSession}.
45       */
46      public BindingSession getSession() {
47          return session;
48      }
49  
50      public Map<String, List<String>> getHTTPHeaders(String url) {
51          return null;
52      }
53  
54      public Element getSOAPHeaders(Object portObject) {
55          return null;
56      }
57  
58      public void putResponseHeaders(String url, int statusCode, Map<String, List<String>> headers) {
59      }
60  
61      /**
62       * Gets the user name from the session.
63       * 
64       * @return the user name or <code>null</code> if the user name is not set
65       */
66      protected String getUser() {
67          Object userObject = getSession().get(SessionParameter.USER);
68          if (userObject instanceof String) {
69              return (String) userObject;
70          }
71  
72          return null;
73      }
74  
75      /**
76       * Gets the password from the session.
77       * 
78       * @return the password or <code>null</code> if the password is not set
79       */
80      protected String getPassword() {
81          Object passwordObject = getSession().get(SessionParameter.PASSWORD);
82          if (passwordObject instanceof String) {
83              return (String) passwordObject;
84          }
85  
86          return null;
87      }
88  
89      /**
90       * Gets the proxy user name from the session.
91       * 
92       * @return the proxy user name or <code>null</code> if the user name is not
93       *         set
94       */
95      protected String getProxyUser() {
96          Object userObject = getSession().get(SessionParameter.PROXY_USER);
97          if (userObject instanceof String) {
98              return (String) userObject;
99          }
100 
101         return null;
102     }
103 
104     /**
105      * Gets the proxy password from the session.
106      * 
107      * @return the proxy password or <code>null</code> if the password is not
108      *         set
109      */
110     protected String getProxyPassword() {
111         Object passwordObject = getSession().get(SessionParameter.PROXY_PASSWORD);
112         if (passwordObject instanceof String) {
113             return (String) passwordObject;
114         }
115 
116         return null;
117     }
118 }