Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/security/auth/login/LoginContext/ModuleSubjectModule.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 ModuleSubjectModule 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;4142// first attempt, fail. second attempt, succeed43private int attemptNumber = 1;4445public void initialize(Subject subject, CallbackHandler callbackHandler,46Map<String,?> sharedState, Map<String,?> options) {4748this.subject = subject;49this.callbackHandler = callbackHandler;50this.sharedState = sharedState;51this.options = options;52}5354public boolean login() throws LoginException {5556if (attemptNumber == 1) {57attemptNumber = 2;58throw new LoginException("attempt 1 fails");59}60return true;61}6263public boolean commit() throws LoginException {6465com.sun.security.auth.NTUserPrincipal p = new66com.sun.security.auth.NTUserPrincipal("testPrincipal");67subject.getPrincipals().add(p);68return true;69}7071public boolean abort() throws LoginException {72return true;73}7475public boolean logout() throws LoginException {76return true;77}78}798081