001/* LoginModule.java -- interface for login implementations.
002   Copyright (C) 2004  Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package javax.security.auth.spi;
040
041import java.util.Map;
042
043import javax.security.auth.Subject;
044import javax.security.auth.callback.CallbackHandler;
045import javax.security.auth.login.LoginException;
046
047/**
048 * The base interface for login methods in the Java Authentication and
049 * Authorization Service (JAAS).
050 *
051 * <p>This interface is used by service providers that implement login
052 * services, and is used internally by the JAAS system. It is not useful
053 * to application programmers, who should use the {@link
054 * javax.security.auth.login.LoginContext} instead.
055 *
056 * @author Casey Marshall (csm@gnu.org)
057 */
058public interface LoginModule
059{
060  /**
061   * Abort the current login attempt. This is called after {@link #login()}
062   * if the overall login attempt fails (that is, if one of the other login
063   * modules that is REQUIRED or REQUISITE fails). This method should clean
064   * up this module's saved state, if any.
065   *
066   * @return True if the abort succeeded, or false if this module should
067   * be ignored.
068   * @throws LoginException If the abort fails.
069   */
070  boolean abort() throws LoginException;
071
072  /**
073   * Commit the current login attempt. This is called after {@link
074   * #login()} if the overall login attempt succeeds (that is, all
075   * methods have satisfied all REQUIRED, REQUISITE, SUFFICIENT and
076   * OPTIONAL module requirements).
077   *
078   * @return True if the commit succeeded, or false if this module
079   * should be ignored.
080   * @throws LoginException If the commit fails.
081   */
082  boolean commit() throws LoginException;
083
084  /**
085   * Initializes this login module. This method is called when the
086   * instance implementing this interface is instantiated, and should
087   * perform any initialization based on the given parameters.
088   * Implementations should ignore state variables and options they do
089   * not recognize.
090   *
091   * @param subject The subject being authenticated.
092   * @param handler The callback handler for user input.
093   * @param sharedState A mapping that is shared between all login
094   * modules.
095   * @param options A mapping of options given to this module.
096   */
097  void initialize(Subject subject, CallbackHandler handler,
098                  Map<String, ?> sharedState, Map<String, ?> options);
099
100  /**
101   * Authenticates a subject to the system. This is the primary
102   * mechanism by which subjects are authenticated, and typically
103   * implementations will ask for credentials (for example, a user
104   * name and password) which will then be verified.
105   *
106   * @return True if the subject was authenticated, or false if this
107   * module should be ignored.
108   * @throws LoginException If this method fails.
109   */
110  boolean login() throws LoginException;
111
112  /**
113   * Logs a subject out. This is primarily used for modules that must
114   * destroy or remove the authentication state associated with a
115   * logged-in subject.
116   *
117   * @return True if the logout succeeds, or false if this module
118   * should be ignored.
119   * @throws LoginException If this method fails.
120   */
121  boolean logout() throws LoginException;
122}