001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.mina.proxy.handlers.http; 021 022import org.apache.mina.proxy.ProxyAuthException; 023import org.apache.mina.proxy.handlers.http.basic.HttpBasicAuthLogicHandler; 024import org.apache.mina.proxy.handlers.http.basic.HttpNoAuthLogicHandler; 025import org.apache.mina.proxy.handlers.http.digest.HttpDigestAuthLogicHandler; 026import org.apache.mina.proxy.handlers.http.ntlm.HttpNTLMAuthLogicHandler; 027import org.apache.mina.proxy.session.ProxyIoSession; 028 029/** 030 * HttpAuthenticationMethods.java - Enumerates all known http authentication methods. 031 * 032 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 033 * @since MINA 2.0.0-M3 034 */ 035public enum HttpAuthenticationMethods { 036 037 NO_AUTH(1), BASIC(2), NTLM(3), DIGEST(4); 038 039 private final int id; 040 041 private HttpAuthenticationMethods(int id) { 042 this.id = id; 043 } 044 045 /** 046 * @return the authentication mechanism id. 047 */ 048 public int getId() { 049 return id; 050 } 051 052 /** 053 * Creates an {@link AbstractAuthLogicHandler} to handle the authentication mechanism. 054 * 055 * @param proxyIoSession the proxy session object 056 * @return a new logic handler 057 * @throws ProxyAuthException If we get an error during the proxy authentication 058 */ 059 public AbstractAuthLogicHandler getNewHandler(ProxyIoSession proxyIoSession) throws ProxyAuthException { 060 return getNewHandler(this.id, proxyIoSession); 061 } 062 063 /** 064 * Creates an {@link AbstractAuthLogicHandler} to handle the authentication mechanism. 065 * 066 * @param method the authentication mechanism to use 067 * @param proxyIoSession the proxy session object 068 * @return a new logic handler 069 * @throws ProxyAuthException If we get an error during the proxy authentication 070 */ 071 public static AbstractAuthLogicHandler getNewHandler(int method, ProxyIoSession proxyIoSession) 072 throws ProxyAuthException { 073 074 if (method == BASIC.id) 075 return new HttpBasicAuthLogicHandler(proxyIoSession); 076 else if (method == DIGEST.id) 077 return new HttpDigestAuthLogicHandler(proxyIoSession); 078 else if (method == NTLM.id) 079 return new HttpNTLMAuthLogicHandler(proxyIoSession); 080 else if (method == NO_AUTH.id) 081 return new HttpNoAuthLogicHandler(proxyIoSession); 082 else 083 return null; 084 } 085}