1069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project/*
2069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/AuthScheme.java $
3069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Revision: 537144 $
4069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Date: 2007-05-11 02:30:13 -0700 (Fri, 11 May 2007) $
5069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
6069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * ====================================================================
7069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
8069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  Licensed to the Apache Software Foundation (ASF) under one or more
9069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  contributor license agreements.  See the NOTICE file distributed with
10069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  this work for additional information regarding copyright ownership.
11069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  The ASF licenses this file to You under the Apache License, Version 2.0
12069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  (the "License"); you may not use this file except in compliance with
13069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  the License.  You may obtain a copy of the License at
14069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
15069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
16069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
17069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  Unless required by applicable law or agreed to in writing, software
18069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  distributed under the License is distributed on an "AS IS" BASIS,
19069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  See the License for the specific language governing permissions and
21069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  limitations under the License.
22069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * ====================================================================
23069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
24069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * This software consists of voluntary contributions made by many
25069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * individuals on behalf of the Apache Software Foundation.  For more
26069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * information on the Apache Software Foundation, please see
27069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <http://www.apache.org/>.
28069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
29069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */
30069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
31069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectpackage org.apache.http.auth;
32069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
33069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.Header;
34069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.HttpRequest;
35069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
36069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project/**
37069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <p>
38069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * This interface represents an abstract challenge-response oriented
39069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * authentication scheme.
40069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * </p>
41069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <p>
42069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * An authentication scheme should be able to support the following
43069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * functions:
44069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <ul>
45069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *   <li>Parse and process the challenge sent by the targer server
46069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *       in response to request for a protected resource
47069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *   <li>Provide its textual designation
48069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *   <li>Provide its parameters, if available
49069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *   <li>Provide the realm this authentication scheme is applicable to,
50069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *       if available
51069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *   <li>Generate authorization string for the given set of credentials,
52069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *       request method and URI as specificed in the HTTP request line
53069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *       in response to the actual authorization challenge
54069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * </ul>
55069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * </p>
56069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <p>
57069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Authentication schemes may ignore method name and URI parameters
58069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * if they are not relevant for the given authentication mechanism
59069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * </p>
60069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <p>
61069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Authentication schemes may be stateful involving a series of
62069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * challenge-response exchanges
63069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * </p>
64069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
65069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
66069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author <a href="mailto:adrian@ephox.com">Adrian Sutton</a>
67069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
68069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @since 4.0
69069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */
70069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
71069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectpublic interface AuthScheme {
72069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
73069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
74069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Processes the given challenge token. Some authentication schemes
75069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * may involve multiple challenge-response exchanges. Such schemes must be able
76069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * to maintain the state information when dealing with sequential challenges
77069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
78069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param header the challenge header
79069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
80069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    void processChallenge(final Header header) throws MalformedChallengeException;
81069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
82069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
83069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Returns textual designation of the given authentication scheme.
84069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
85069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return the name of the given authentication scheme
86069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
87069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    String getSchemeName();
88069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
89069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
90069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Returns authentication parameter with the given name, if available.
91069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
92069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param name The name of the parameter to be returned
93069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
94069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return the parameter with the given name
95069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
96069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    String getParameter(final String name);
97069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
98069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
99069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Returns authentication realm. If the concept of an authentication
100069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * realm is not applicable to the given authentication scheme, returns
101069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * <code>null</code>.
102069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
103069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return the authentication realm
104069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
105069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    String getRealm();
106069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
107069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
108069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Tests if the authentication scheme is provides authorization on a per
109069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * connection basis instead of usual per request basis
110069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
111069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return <tt>true</tt> if the scheme is connection based, <tt>false</tt>
112069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * if the scheme is request based.
113069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
114069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    boolean isConnectionBased();
115069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
116069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
117069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Authentication process may involve a series of challenge-response exchanges.
118069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * This method tests if the authorization process has been completed, either
119069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * successfully or unsuccessfully, that is, all the required authorization
120069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * challenges have been processed in their entirety.
121069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
122069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return <tt>true</tt> if the authentication process has been completed,
123069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * <tt>false</tt> otherwise.
124069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
125069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    boolean isComplete();
126069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
127069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
128069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Produces an authorization string for the given set of {@link Credentials}.
129069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
130069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param credentials The set of credentials to be used for athentication
131069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param request The request being authenticated
132069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @throws AuthenticationException if authorization string cannot
133069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *   be generated due to an authentication failure
134069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
135069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return the authorization string
136069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
137069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    Header authenticate(Credentials credentials, HttpRequest request)
138069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            throws AuthenticationException;
139069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
140069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project}
141