View Javadoc

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   * SPNEGO (Simple and Protected GSSAPI Negotiation Mechanism) authentication
38   * scheme.
39   *
40   * @since 4.2
41   */
42  public class SPNegoScheme extends GGSSchemeBase {
43  
44      private static final String SPNEGO_OID = "1.3.6.1.5.5.2";
45  
46      public SPNegoScheme(boolean stripPort) {
47          super(stripPort);
48      }
49  
50      public SPNegoScheme() {
51          super(false);
52      }
53  
54      public String getSchemeName() {
55          return "Negotiate";
56      }
57  
58      /**
59       * Produces SPNEGO authorization Header based on token created by
60       * processChallenge.
61       *
62       * @param credentials not used by the SPNEGO scheme.
63       * @param request The request being authenticated
64       *
65       * @throws AuthenticationException if authentication string cannot
66       *   be generated due to an authentication failure
67       *
68       * @return SPNEGO authentication Header
69       */
70      @Override
71      public Header authenticate(
72              final Credentials credentials,
73              final HttpRequest request,
74              final HttpContext context) throws AuthenticationException {
75          return super.authenticate(credentials, request, context);
76      }
77  
78      @Override
79      protected byte[] generateToken(final byte[] input, final String authServer) throws GSSException {
80          return generateGSSToken(input, new Oid(SPNEGO_OID), authServer);
81      }
82  
83      /**
84       * There are no valid parameters for SPNEGO authentication so this
85       * method always returns <code>null</code>.
86       *
87       * @return <code>null</code>
88       */
89      public String getParameter(String name) {
90          if (name == null) {
91              throw new IllegalArgumentException("Parameter name may not be null");
92          }
93          return null;
94      }
95  
96      /**
97       * The concept of an authentication realm is not supported by the Negotiate
98       * authentication scheme. Always returns <code>null</code>.
99       *
100      * @return <code>null</code>
101      */
102     public String getRealm() {
103         return null;
104     }
105 
106     /**
107      * Returns <tt>true</tt>. SPNEGO authentication scheme is connection based.
108      *
109      * @return <tt>true</tt>.
110      */
111     public boolean isConnectionBased() {
112         return true;
113     }
114 
115 }