Path: blob/master/src/java.base/share/classes/java/security/AuthProvider.java
41152 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.security;2627import javax.security.auth.Subject;28import javax.security.auth.login.LoginException;29import javax.security.auth.callback.CallbackHandler;3031/**32* This class defines login and logout methods for a provider.33*34* <p> While callers may invoke {@code login} directly,35* the provider may also invoke {@code login} on behalf of callers36* if it determines that a login must be performed37* prior to certain operations.38*39* @since 1.540*/41public abstract class AuthProvider extends Provider {4243@java.io.Serial44private static final long serialVersionUID = 4197859053084546461L;4546/**47* Constructs a provider with the specified name, version number,48* and information.49*50* @param name the provider name.51* @param version the provider version number.52* @param info a description of the provider and its services.53* @deprecated use {@link #AuthProvider(String, String, String)} instead.54*/55@Deprecated(since="9")56protected AuthProvider(String name, double version, String info) {57super(name, Double.toString(version), info);58}5960/**61* Constructs a provider with the specified name, version string,62* and information.63*64* @param name the provider name.65* @param versionStr the provider version string.66* @param info a description of the provider and its services.67* @since 968*/69protected AuthProvider(String name, String versionStr, String info) {70super(name, versionStr, info);71}7273/**74* Log in to this provider.75*76* <p> The provider relies on a {@code CallbackHandler}77* to obtain authentication information from the caller78* (a PIN, for example). If the caller passes a {@code null}79* handler to this method, the provider uses the handler set in the80* {@code setCallbackHandler} method.81* If no handler was set in that method, the provider queries the82* <i>auth.login.defaultCallbackHandler</i> security property83* for the fully qualified class name of a default handler implementation.84* If the security property is not set,85* the provider is assumed to have alternative means86* for obtaining authentication information.87*88* @param subject the {@code Subject} which may contain89* principals/credentials used for authentication,90* or may be populated with additional principals/credentials91* after successful authentication has completed.92* This parameter may be {@code null}.93* @param handler the {@code CallbackHandler} used by94* this provider to obtain authentication information95* from the caller, which may be {@code null}96*97* @throws IllegalStateException if the provider requires configuration98* and {@link configure} has not been called99* @throws LoginException if the login operation fails100* @throws SecurityException if the caller does not pass a101* security check for102* {@code SecurityPermission("authProvider.name")},103* where {@code name} is the value returned by104* this provider's {@code getName} method105*/106public abstract void login(Subject subject, CallbackHandler handler)107throws LoginException;108109/**110* Log out from this provider.111*112* @throws IllegalStateException if the provider requires configuration113* and {@link configure} has not been called114* @throws LoginException if the logout operation fails115* @throws SecurityException if the caller does not pass a116* security check for117* {@code SecurityPermission("authProvider.name")},118* where {@code name} is the value returned by119* this provider's {@code getName} method120*/121public abstract void logout() throws LoginException;122123/**124* Set a {@code CallbackHandler}.125*126* <p> The provider uses this handler if one is not passed to the127* {@code login} method. The provider also uses this handler128* if it invokes {@code login} on behalf of callers.129* In either case if a handler is not set via this method,130* the provider queries the131* <i>auth.login.defaultCallbackHandler</i> security property132* for the fully qualified class name of a default handler implementation.133* If the security property is not set,134* the provider is assumed to have alternative means135* for obtaining authentication information.136*137* @param handler a {@code CallbackHandler} for obtaining138* authentication information, which may be {@code null}139*140* @throws IllegalStateException if the provider requires configuration141* and {@link configure} has not been called142* @throws SecurityException if the caller does not pass a143* security check for144* {@code SecurityPermission("authProvider.name")},145* where {@code name} is the value returned by146* this provider's {@code getName} method147*/148public abstract void setCallbackHandler(CallbackHandler handler);149}150151152