2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.server;
21 import javax.servlet.ServletRequest;
22 import javax.servlet.ServletResponse;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
27 /* ------------------------------------------------------------ */
28 /** The Authentication state of a request.
30 * The Authentication state can be one of several sub-types that
31 * reflects where the request is in the many different authentication
32 * cycles. Authentication might not yet be checked or it might be checked
33 * and failed, checked and deferred or succeeded.
36 public interface Authentication
38 /* ------------------------------------------------------------ */
39 public static class Failed extends QuietServletException
41 public Failed(String message)
47 /* ------------------------------------------------------------ */
48 /** A successful Authentication with User information.
50 public interface User extends Authentication
52 String getAuthMethod();
53 UserIdentity getUserIdentity();
54 boolean isUserInRole(UserIdentity.Scope scope,String role);
58 /* ------------------------------------------------------------ */
59 /** A wrapped authentication with methods provide the
60 * wrapped request/response for use by the application
62 public interface Wrapped extends Authentication
64 HttpServletRequest getHttpServletRequest();
65 HttpServletResponse getHttpServletResponse();
68 /* ------------------------------------------------------------ */
69 /** A deferred authentication with methods to progress
70 * the authentication process.
72 public interface Deferred extends Authentication
74 /* ------------------------------------------------------------ */
75 /** Authenticate if possible without sending a challenge.
76 * This is used to check credentials that have been sent for
77 * non-manditory authentication.
78 * @return The new Authentication state.
80 Authentication authenticate(ServletRequest request);
82 /* ------------------------------------------------------------ */
83 /** Authenticate and possibly send a challenge.
84 * This is used to initiate authentication for previously
85 * non-manditory authentication.
86 * @return The new Authentication state.
88 Authentication authenticate(ServletRequest request,ServletResponse response);
91 /* ------------------------------------------------------------ */
92 /** Login with the LOGIN authenticator
95 * @return The new Authentication state
97 Authentication login(String username,Object password,ServletRequest request);
101 /* ------------------------------------------------------------ */
102 /** Authentication Response sent state.
103 * Responses are sent by authenticators either to issue an
104 * authentication challenge or on successful authentication in
105 * order to redirect the user to the original URL.
107 public interface ResponseSent extends Authentication
111 /* ------------------------------------------------------------ */
112 /** An Authentication Challenge has been sent.
114 public interface Challenge extends ResponseSent
118 /* ------------------------------------------------------------ */
119 /** An Authentication Failure has been sent.
121 public interface Failure extends ResponseSent
125 public interface SendSuccess extends ResponseSent
129 /* ------------------------------------------------------------ */
130 /** Unauthenticated state.
132 * This convenience instance is for non mandatory authentication where credentials
133 * have been presented and checked, but failed authentication.
135 public final static Authentication UNAUTHENTICATED = new Authentication(){@Override
136 public String toString(){return "UNAUTHENTICATED";}};
138 /* ------------------------------------------------------------ */
139 /** Authentication not checked
141 * This convenience instance us for non mandatory authentication when no
142 * credentials are present to be checked.
144 public final static Authentication NOT_CHECKED = new Authentication(){@Override
145 public String toString(){return "NOT CHECKED";}};
147 /* ------------------------------------------------------------ */
148 /** Authentication challenge sent.
150 * This convenience instance is for when an authentication challenge has been sent.
152 public final static Authentication SEND_CONTINUE = new Authentication.Challenge(){@Override
153 public String toString(){return "CHALLENGE";}};
155 /* ------------------------------------------------------------ */
156 /** Authentication failure sent.
158 * This convenience instance is for when an authentication failure has been sent.
160 public final static Authentication SEND_FAILURE = new Authentication.Failure(){@Override
161 public String toString(){return "FAILURE";}};
162 public final static Authentication SEND_SUCCESS = new SendSuccess(){@Override
163 public String toString(){return "SEND_SUCCESS";}};