1 // ======================================================================== 2 // Copyright (c) 2008-2009 Mort Bay Consulting Pty. Ltd. 3 // ------------------------------------------------------------------------ 4 // All rights reserved. This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v1.0 6 // and Apache License v2.0 which accompanies this distribution. 7 // The Eclipse Public License is available at 8 // http://www.eclipse.org/legal/epl-v10.html 9 // The Apache License v2.0 is available at 10 // http://www.opensource.org/licenses/apache2.0.php 11 // You may elect to redistribute this code under either of these licenses. 12 // ======================================================================== 13 14 package org.eclipse.jetty.security; 15 16 import java.util.Set; 17 18 import javax.servlet.ServletContext; 19 import javax.servlet.ServletRequest; 20 import javax.servlet.ServletResponse; 21 22 import org.eclipse.jetty.server.Authentication; 23 import org.eclipse.jetty.server.Authentication.User; 24 import org.eclipse.jetty.server.Server; 25 26 /** 27 * Authenticator Interface 28 * <p> 29 * An Authenticator is responsible for checking requests and sending 30 * response challenges in order to authenticate a request. 31 * Various types of {@link Authentication} are returned in order to 32 * signal the next step in authentication. 33 * 34 * @version $Rev: 4793 $ $Date: 2009-03-19 00:00:01 +0100 (Thu, 19 Mar 2009) $ 35 */ 36 public interface Authenticator 37 { 38 /* ------------------------------------------------------------ */ 39 /** 40 * Configure the Authenticator 41 * @param configuration 42 */ 43 void setConfiguration(AuthConfiguration configuration); 44 45 /* ------------------------------------------------------------ */ 46 /** 47 * @return The name of the authentication method 48 */ 49 String getAuthMethod(); 50 51 /* ------------------------------------------------------------ */ 52 /** Validate a response 53 * @param request The request 54 * @param response The response 55 * @param mandatory True if authentication is mandatory. 56 * @return An Authentication. If Authentication is successful, this will be a {@link org.eclipse.jetty.server.Authentication.User}. If a response has 57 * been sent by the Authenticator (which can be done for both successful and unsuccessful authentications), then the result will 58 * implement {@link org.eclipse.jetty.server.Authentication.ResponseSent}. If Authentication is not manditory, then a 59 * {@link org.eclipse.jetty.server.Authentication.Deferred} may be returned. 60 * 61 * @throws ServerAuthException 62 */ 63 Authentication validateRequest(ServletRequest request, ServletResponse response, boolean mandatory) throws ServerAuthException; 64 65 /* ------------------------------------------------------------ */ 66 /** 67 * @param request 68 * @param response 69 * @param mandatory 70 * @param validatedUser 71 * @return true if response is secure 72 * @throws ServerAuthException 73 */ 74 boolean secureResponse(ServletRequest request, ServletResponse response, boolean mandatory, User validatedUser) throws ServerAuthException; 75 76 77 /* ------------------------------------------------------------ */ 78 /* ------------------------------------------------------------ */ 79 /* ------------------------------------------------------------ */ 80 /** 81 * Authenticator Configuration 82 */ 83 interface AuthConfiguration 84 { 85 String getAuthMethod(); 86 String getRealmName(); 87 88 /** Get a SecurityHandler init parameter 89 * @see SecurityHandler#getInitParameter(String) 90 * @param param parameter name 91 * @return Parameter value or null 92 */ 93 String getInitParameter(String param); 94 95 /* ------------------------------------------------------------ */ 96 /** Get a SecurityHandler init parameter names 97 * @see SecurityHandler#getInitParameterNames() 98 * @return Set of parameter names 99 */ 100 Set<String> getInitParameterNames(); 101 102 LoginService getLoginService(); 103 IdentityService getIdentityService(); 104 boolean isSessionRenewedOnAuthentication(); 105 } 106 107 /* ------------------------------------------------------------ */ 108 /* ------------------------------------------------------------ */ 109 /* ------------------------------------------------------------ */ 110 /** 111 * Authenticator Factory 112 */ 113 interface Factory 114 { 115 Authenticator getAuthenticator(Server server, ServletContext context, AuthConfiguration configuration, IdentityService identityService, LoginService loginService); 116 } 117 }