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 /** No authentication */ 37 NO_AUTH(1), 38 39 /** Basic authentication */ 40 BASIC(2), 41 42 /** NTLM (Microsoft) authentication */ 43 NTLM(3), 44 45 /** Digest authentication */ 46 DIGEST(4); 47 48 private final int id; 49 50 private HttpAuthenticationMethods(int id) { 51 this.id = id; 52 } 53 54 /** 55 * @return the authentication mechanism id. 56 */ 57 public int getId() { 58 return id; 59 } 60 61 /** 62 * Creates an {@link AbstractAuthLogicHandler} to handle the authentication mechanism. 63 * 64 * @param proxyIoSession the proxy session object 65 * @return a new logic handler 66 * @throws ProxyAuthException If we get an error during the proxy authentication 67 */ 68 public AbstractAuthLogicHandler getNewHandler(ProxyIoSession proxyIoSession) throws ProxyAuthException { 69 return getNewHandler(this.id, proxyIoSession); 70 } 71 72 /** 73 * Creates an {@link AbstractAuthLogicHandler} to handle the authentication mechanism. 74 * 75 * @param method the authentication mechanism to use 76 * @param proxyIoSession the proxy session object 77 * @return a new logic handler 78 * @throws ProxyAuthException If we get an error during the proxy authentication 79 */ 80 public static AbstractAuthLogicHandler getNewHandler(int method, ProxyIoSession proxyIoSession) 81 throws ProxyAuthException { 82 83 if (method == BASIC.id) 84 return new HttpBasicAuthLogicHandler(proxyIoSession); 85 else if (method == DIGEST.id) 86 return new HttpDigestAuthLogicHandler(proxyIoSession); 87 else if (method == NTLM.id) 88 return new HttpNTLMAuthLogicHandler(proxyIoSession); 89 else if (method == NO_AUTH.id) 90 return new HttpNoAuthLogicHandler(proxyIoSession); 91 else 92 return null; 93 } 94 }