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   */
20  package org.apache.mina.proxy.handlers.http;
21  
22  import org.apache.mina.proxy.ProxyAuthException;
23  import org.apache.mina.proxy.handlers.http.basic.HttpBasicAuthLogicHandler;
24  import org.apache.mina.proxy.handlers.http.basic.HttpNoAuthLogicHandler;
25  import org.apache.mina.proxy.handlers.http.digest.HttpDigestAuthLogicHandler;
26  import org.apache.mina.proxy.handlers.http.ntlm.HttpNTLMAuthLogicHandler;
27  import org.apache.mina.proxy.session.ProxyIoSession;
28  
29  /**
30   * HttpAuthenticationMethods.java - Enumerates all known http authentication methods.
31   * 
32   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
33   * @since MINA 2.0.0-M3
34   */
35  public enum HttpAuthenticationMethods {
36  
37      NO_AUTH(1), BASIC(2), NTLM(3), DIGEST(4);
38  
39      private final int id;
40  
41      private HttpAuthenticationMethods(int id) {
42          this.id = id;
43      }
44  
45      /**
46       * @return the authentication mechanism id.
47       */
48      public int getId() {
49          return id;
50      }
51  
52      /**
53       * Creates an {@link AbstractAuthLogicHandler} to handle the authentication mechanism.
54       * 
55       * @param proxyIoSession the proxy session object
56       * @return a new logic handler 
57       * @throws ProxyAuthException If we get an error during the proxy authentication
58       */
59      public AbstractAuthLogicHandler getNewHandler(ProxyIoSession proxyIoSession) throws ProxyAuthException {
60          return getNewHandler(this.id, proxyIoSession);
61      }
62  
63      /**
64       * Creates an {@link AbstractAuthLogicHandler} to handle the authentication mechanism.
65       * 
66       * @param method the authentication mechanism to use
67       * @param proxyIoSession the proxy session object
68       * @return a new logic handler 
69       * @throws ProxyAuthException If we get an error during the proxy authentication
70       */
71      public static AbstractAuthLogicHandler getNewHandler(int method, ProxyIoSession proxyIoSession)
72              throws ProxyAuthException {
73  
74          if (method == BASIC.id)
75              return new HttpBasicAuthLogicHandler(proxyIoSession);
76          else if (method == DIGEST.id)
77              return new HttpDigestAuthLogicHandler(proxyIoSession);
78          else if (method == NTLM.id)
79              return new HttpNTLMAuthLogicHandler(proxyIoSession);
80          else if (method == NO_AUTH.id)
81              return new HttpNoAuthLogicHandler(proxyIoSession);
82          else
83              return null;
84      }
85  }