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.security;
23 import javax.servlet.ServletContext;
24 import javax.servlet.ServletRequest;
25 import javax.servlet.ServletResponse;
27 import org.eclipse.jetty.server.Authentication;
28 import org.eclipse.jetty.server.Authentication.User;
29 import org.eclipse.jetty.server.Server;
32 * Authenticator Interface
34 * An Authenticator is responsible for checking requests and sending
35 * response challenges in order to authenticate a request.
36 * Various types of {@link Authentication} are returned in order to
37 * signal the next step in authentication.
39 * @version $Rev: 4793 $ $Date: 2009-03-19 00:00:01 +0100 (Thu, 19 Mar 2009) $
41 public interface Authenticator
43 /* ------------------------------------------------------------ */
45 * Configure the Authenticator
46 * @param configuration
48 void setConfiguration(AuthConfiguration configuration);
50 /* ------------------------------------------------------------ */
52 * @return The name of the authentication method
54 String getAuthMethod();
57 /* ------------------------------------------------------------ */
59 * Called prior to validateRequest. The authenticator can
60 * manipulate the request to update it with information that
61 * can be inspected prior to validateRequest being called.
62 * The primary purpose of this method is to satisfy the Servlet
63 * Spec 3.1 section 13.6.3 on handling Form authentication
64 * where the http method of the original request causing authentication
65 * is not the same as the http method resulting from the redirect
66 * after authentication.
69 void prepareRequest(ServletRequest request);
72 /* ------------------------------------------------------------ */
73 /** Validate a request
74 * @param request The request
75 * @param response The response
76 * @param mandatory True if authentication is mandatory.
77 * @return An Authentication. If Authentication is successful, this will be a {@link org.eclipse.jetty.server.Authentication.User}. If a response has
78 * been sent by the Authenticator (which can be done for both successful and unsuccessful authentications), then the result will
79 * implement {@link org.eclipse.jetty.server.Authentication.ResponseSent}. If Authentication is not manditory, then a
80 * {@link org.eclipse.jetty.server.Authentication.Deferred} may be returned.
82 * @throws ServerAuthException
84 Authentication validateRequest(ServletRequest request, ServletResponse response, boolean mandatory) throws ServerAuthException;
86 /* ------------------------------------------------------------ */
91 * @param validatedUser
92 * @return true if response is secure
93 * @throws ServerAuthException
95 boolean secureResponse(ServletRequest request, ServletResponse response, boolean mandatory, User validatedUser) throws ServerAuthException;
98 /* ------------------------------------------------------------ */
99 /* ------------------------------------------------------------ */
100 /* ------------------------------------------------------------ */
102 * Authenticator Configuration
104 interface AuthConfiguration
106 String getAuthMethod();
107 String getRealmName();
109 /** Get a SecurityHandler init parameter
110 * @see SecurityHandler#getInitParameter(String)
111 * @param param parameter name
112 * @return Parameter value or null
114 String getInitParameter(String param);
116 /* ------------------------------------------------------------ */
117 /** Get a SecurityHandler init parameter names
118 * @see SecurityHandler#getInitParameterNames()
119 * @return Set of parameter names
121 Set<String> getInitParameterNames();
123 LoginService getLoginService();
124 IdentityService getIdentityService();
125 boolean isSessionRenewedOnAuthentication();
128 /* ------------------------------------------------------------ */
129 /* ------------------------------------------------------------ */
130 /* ------------------------------------------------------------ */
132 * Authenticator Factory
136 Authenticator getAuthenticator(Server server, ServletContext context, AuthConfiguration configuration, IdentityService identityService, LoginService loginService);