View Javadoc

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 javax.net.ssl.HostnameVerifier;
25  import javax.net.ssl.SSLSocketFactory;
26  import javax.net.ssl.X509TrustManager;
27  import javax.xml.ws.handler.HandlerResolver;
28  
29  import org.apache.chemistry.opencmis.commons.SessionParameter;
30  import org.w3c.dom.Element;
31  
32  /**
33   * Authentication provider class.
34   */
35  public abstract class AbstractAuthenticationProvider implements SessionAwareAuthenticationProvider {
36  
37      private static final long serialVersionUID = 1L;
38  
39      private BindingSession session;
40  
41      /**
42       * Sets the {@link BindingSession} the authentication provider lives in.
43       */
44      @Override
45      public void setSession(BindingSession session) {
46          this.session = session;
47      }
48  
49      /**
50       * Returns {@link BindingSession}.
51       */
52      public BindingSession getSession() {
53          return session;
54      }
55  
56      @Override
57      public Map<String, List<String>> getHTTPHeaders(String url) {
58          return null;
59      }
60  
61      @Override
62      public Element getSOAPHeaders(Object portObject) {
63          return null;
64      }
65  
66      @Override
67      public HandlerResolver getHandlerResolver() {
68          return null;
69      }
70  
71      @Override
72      public void putResponseHeaders(String url, int statusCode, Map<String, List<String>> headers) {
73      }
74  
75      @Override
76      public SSLSocketFactory getSSLSocketFactory() {
77          return null;
78      }
79  
80      @Override
81      public HostnameVerifier getHostnameVerifier() {
82          return null;
83      }
84  
85      /**
86       * Gets the trust manager corresponding to the SSL socket factory.
87       * 
88       * @return a {@link X509TrustManager} or {@code null}
89       */
90      public X509TrustManager getTrustManager() {
91          return null;
92      }
93  
94      /**
95       * Gets the user name from the session.
96       * 
97       * @return the user name or {@code null} if the user name is not set
98       */
99      protected String getUser() {
100         Object userObject = getSession().get(SessionParameter.USER);
101         if (userObject instanceof String) {
102             return (String) userObject;
103         }
104 
105         return null;
106     }
107 
108     /**
109      * Gets the password from the session.
110      * 
111      * @return the password or {@code null} if the password is not set
112      */
113     protected String getPassword() {
114         Object passwordObject = getSession().get(SessionParameter.PASSWORD);
115         if (passwordObject instanceof String) {
116             return (String) passwordObject;
117         }
118 
119         return null;
120     }
121 
122     /**
123      * Gets the bearer token from the session.
124      * 
125      * @return the bearer token or {@code null} if the token is not set
126      */
127     protected String getBearerToken() {
128         Object tokenObject = getSession().get(SessionParameter.OAUTH_ACCESS_TOKEN);
129         if (tokenObject instanceof String) {
130             return (String) tokenObject;
131         }
132 
133         return null;
134     }
135 
136     /**
137      * Gets the proxy user name from the session.
138      * 
139      * @return the proxy user name or {@code null} if the user name is not set
140      */
141     protected String getProxyUser() {
142         Object userObject = getSession().get(SessionParameter.PROXY_USER);
143         if (userObject instanceof String) {
144             return (String) userObject;
145         }
146 
147         return null;
148     }
149 
150     /**
151      * Gets the proxy password from the session.
152      * 
153      * @return the proxy password or {@code null} if the password is not set
154      */
155     protected String getProxyPassword() {
156         Object passwordObject = getSession().get(SessionParameter.PROXY_PASSWORD);
157         if (passwordObject instanceof String) {
158             return (String) passwordObject;
159         }
160 
161         return null;
162     }
163 
164     /**
165      * Gets the CSRF header name.
166      * 
167      * @return the CSRF header name or {@code null} if the CSRF header name is
168      *         not set
169      */
170     protected String getCsrfHeader() {
171         Object csrfHeaderObject = getSession().get(SessionParameter.CSRF_HEADER);
172         if (csrfHeaderObject instanceof String) {
173             return (String) csrfHeaderObject;
174         }
175 
176         return null;
177     }
178 }