1 /*
2 * ====================================================================
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ====================================================================
19 *
20 * This software consists of voluntary contributions made by many
21 * individuals on behalf of the Apache Software Foundation. For more
22 * information on the Apache Software Foundation, please see
23 * <http://www.apache.org/>.
24 */
25
26 package org.apache.http.impl.auth;
27
28 import org.apache.http.Header;
29 import org.apache.http.HttpRequest;
30 import org.apache.http.auth.AuthenticationException;
31 import org.apache.http.auth.Credentials;
32 import org.apache.http.protocol.HttpContext;
33 import org.ietf.jgss.GSSException;
34 import org.ietf.jgss.Oid;
35
36 /**
37 * KERBEROS authentication scheme.
38 *
39 * @since 4.2
40 */
41 public class KerberosScheme extends GGSSchemeBase {
42
43 private static final String KERBEROS_OID = "1.2.840.113554.1.2.2";
44
45 public KerberosScheme(boolean stripPort) {
46 super(stripPort);
47 }
48
49 public KerberosScheme() {
50 super(false);
51 }
52
53 public String getSchemeName() {
54 return "Kerberos";
55 }
56
57 /**
58 * Produces KERBEROS authorization Header based on token created by
59 * processChallenge.
60 *
61 * @param credentials not used by the KERBEROS scheme.
62 * @param request The request being authenticated
63 *
64 * @throws AuthenticationException if authentication string cannot
65 * be generated due to an authentication failure
66 *
67 * @return KERBEROS authentication Header
68 */
69 @Override
70 public Header authenticate(
71 final Credentials credentials,
72 final HttpRequest request,
73 final HttpContext context) throws AuthenticationException {
74 return super.authenticate(credentials, request, context);
75 }
76
77 @Override
78 protected byte[] generateToken(final byte[] input, final String authServer) throws GSSException {
79 return generateGSSToken(input, new Oid(KERBEROS_OID), authServer);
80 }
81
82 /**
83 * There are no valid parameters for KERBEROS authentication so this
84 * method always returns <code>null</code>.
85 *
86 * @return <code>null</code>
87 */
88 public String getParameter(String name) {
89 if (name == null) {
90 throw new IllegalArgumentException("Parameter name may not be null");
91 }
92 return null;
93 }
94
95 /**
96 * The concept of an authentication realm is not supported by the Negotiate
97 * authentication scheme. Always returns <code>null</code>.
98 *
99 * @return <code>null</code>
100 */
101 public String getRealm() {
102 return null;
103 }
104
105 /**
106 * Returns <tt>true</tt>. KERBEROS authentication scheme is connection based.
107 *
108 * @return <tt>true</tt>.
109 */
110 public boolean isConnectionBased() {
111 return true;
112 }
113
114 }