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