AuthScheme.java revision 417f3b92ba4549b2f22340e3107d869d2b9c5bb8
1/*
2 * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/AuthScheme.java $
3 * $Revision: 537144 $
4 * $Date: 2007-05-11 02:30:13 -0700 (Fri, 11 May 2007) $
5 *
6 * ====================================================================
7 *
8 *  Licensed to the Apache Software Foundation (ASF) under one or more
9 *  contributor license agreements.  See the NOTICE file distributed with
10 *  this work for additional information regarding copyright ownership.
11 *  The ASF licenses this file to You under the Apache License, Version 2.0
12 *  (the "License"); you may not use this file except in compliance with
13 *  the License.  You may obtain a copy of the License at
14 *
15 *      http://www.apache.org/licenses/LICENSE-2.0
16 *
17 *  Unless required by applicable law or agreed to in writing, software
18 *  distributed under the License is distributed on an "AS IS" BASIS,
19 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 *  See the License for the specific language governing permissions and
21 *  limitations under the License.
22 * ====================================================================
23 *
24 * This software consists of voluntary contributions made by many
25 * individuals on behalf of the Apache Software Foundation.  For more
26 * information on the Apache Software Foundation, please see
27 * <http://www.apache.org/>.
28 *
29 */
30
31package org.apache.http.auth;
32
33import org.apache.http.Header;
34import org.apache.http.HttpRequest;
35
36/**
37 * <p>
38 * This interface represents an abstract challenge-response oriented
39 * authentication scheme.
40 * </p>
41 * <p>
42 * An authentication scheme should be able to support the following
43 * functions:
44 * <ul>
45 *   <li>Parse and process the challenge sent by the targer server
46 *       in response to request for a protected resource
47 *   <li>Provide its textual designation
48 *   <li>Provide its parameters, if available
49 *   <li>Provide the realm this authentication scheme is applicable to,
50 *       if available
51 *   <li>Generate authorization string for the given set of credentials,
52 *       request method and URI as specificed in the HTTP request line
53 *       in response to the actual authorization challenge
54 * </ul>
55 * </p>
56 * <p>
57 * Authentication schemes may ignore method name and URI parameters
58 * if they are not relevant for the given authentication mechanism
59 * </p>
60 * <p>
61 * Authentication schemes may be stateful involving a series of
62 * challenge-response exchanges
63 * </p>
64 *
65 * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
66 * @author <a href="mailto:adrian@ephox.com">Adrian Sutton</a>
67 *
68 * @since 4.0
69 */
70
71public interface AuthScheme {
72
73    /**
74     * Processes the given challenge token. Some authentication schemes
75     * may involve multiple challenge-response exchanges. Such schemes must be able
76     * to maintain the state information when dealing with sequential challenges
77     *
78     * @param header the challenge header
79     */
80    void processChallenge(final Header header) throws MalformedChallengeException;
81
82    /**
83     * Returns textual designation of the given authentication scheme.
84     *
85     * @return the name of the given authentication scheme
86     */
87    String getSchemeName();
88
89    /**
90     * Returns authentication parameter with the given name, if available.
91     *
92     * @param name The name of the parameter to be returned
93     *
94     * @return the parameter with the given name
95     */
96    String getParameter(final String name);
97
98    /**
99     * Returns authentication realm. If the concept of an authentication
100     * realm is not applicable to the given authentication scheme, returns
101     * <code>null</code>.
102     *
103     * @return the authentication realm
104     */
105    String getRealm();
106
107    /**
108     * Tests if the authentication scheme is provides authorization on a per
109     * connection basis instead of usual per request basis
110     *
111     * @return <tt>true</tt> if the scheme is connection based, <tt>false</tt>
112     * if the scheme is request based.
113     */
114    boolean isConnectionBased();
115
116    /**
117     * Authentication process may involve a series of challenge-response exchanges.
118     * This method tests if the authorization process has been completed, either
119     * successfully or unsuccessfully, that is, all the required authorization
120     * challenges have been processed in their entirety.
121     *
122     * @return <tt>true</tt> if the authentication process has been completed,
123     * <tt>false</tt> otherwise.
124     */
125    boolean isComplete();
126
127    /**
128     * Produces an authorization string for the given set of {@link Credentials}.
129     *
130     * @param credentials The set of credentials to be used for athentication
131     * @param request The request being authenticated
132     * @throws AuthenticationException if authorization string cannot
133     *   be generated due to an authentication failure
134     *
135     * @return the authorization string
136     */
137    Header authenticate(Credentials credentials, HttpRequest request)
138            throws AuthenticationException;
139
140}
141