Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/security/auth/login/LoginContext/DefaultHandlerModule.java
38859 views
/*1* Copyright (c) 2000, 2004, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.*;24import java.io.IOException;25import javax.security.auth.*;26import javax.security.auth.callback.*;27import javax.security.auth.login.*;28import javax.security.auth.spi.*;2930public class DefaultHandlerModule implements LoginModule {3132// initial state33private Subject subject;34private CallbackHandler callbackHandler;35private Map sharedState;36private Map options;3738// username and password39private String username;40private char[] password;4142public void initialize(Subject subject, CallbackHandler callbackHandler,43Map<String,?> sharedState, Map<String,?> options) {4445this.subject = subject;46this.callbackHandler = callbackHandler;47this.sharedState = sharedState;48this.options = options;49}5051public boolean login() throws LoginException {5253// prompt for a username and password54if (callbackHandler == null) {55throw new LoginException("Error: no CallbackHandler available " +56"to garner authentication information from the user");57} else {58System.out.println("DefaultHandlerModule got CallbackHandler: " +59callbackHandler.toString());60}6162return true;63}6465public boolean commit() throws LoginException {66return true;67}6869public boolean abort() throws LoginException {70return true;71}7273public boolean logout() throws LoginException {74return true;75}76}777879