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 The Apache MINA Project (dev@mina.apache.org)
33   * @version $Rev: 685703 $, $Date: 2008-08-14 00:14:47 +0200 (Thu, 14 Aug 2008) $
34   * @since MINA 2.0.0-M3
35   */
36  public enum HttpAuthenticationMethods {
37  
38      NO_AUTH(1), BASIC(2), NTLM(3), DIGEST(4);
39      
40      private final int id;
41      
42      private HttpAuthenticationMethods(int id) {
43      	this.id = id;
44      }
45  
46  	public int getId() {
47  		return id;
48  	}
49  
50  	/**
51       * Creates an {@link AbstractAuthLogicHandler} to handle this authentication mechanism. 
52       */
53      public AbstractAuthLogicHandler getNewHandler(ProxyIoSession proxyIoSession)
54              throws ProxyAuthException {
55          switch (this) {
56          case BASIC:
57              return new HttpBasicAuthLogicHandler(proxyIoSession);
58  
59          case DIGEST:
60              HttpDigestAuthLogicHandler authHandler = new HttpDigestAuthLogicHandler(
61                      proxyIoSession);
62              return authHandler;
63  
64          case NTLM:
65              return new HttpNTLMAuthLogicHandler(proxyIoSession);
66  
67          case NO_AUTH:
68              return new HttpNoAuthLogicHandler(proxyIoSession);
69  
70          default:
71              return null;
72          }
73      }
74  }