Path: blob/master/test/jdk/sun/security/krb5/auto/CleanState.java
41152 views
/*1* Copyright (c) 2008, 2018, 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*/2223/*24* @test25* @bug 6716534 819448626* @summary Krb5LoginModule has not cleaned temp info between authentication attempts27* @library /test/lib28* @compile -XDignore.symbol.file CleanState.java29* @run main jdk.test.lib.FileInstaller TestHosts TestHosts30* @run main/othervm -Djdk.net.hosts.file=TestHosts CleanState31*/32import com.sun.security.auth.module.Krb5LoginModule;33import java.util.HashMap;34import java.util.Map;35import javax.security.auth.Subject;36import javax.security.auth.callback.Callback;37import javax.security.auth.callback.CallbackHandler;38import javax.security.auth.callback.NameCallback;39import javax.security.auth.callback.PasswordCallback;4041public class CleanState {42public static void main(String[] args) throws Exception {43CleanState x = new CleanState();44new OneKDC(null);45x.go();46}4748void go() throws Exception {49Krb5LoginModule krb5 = new Krb5LoginModule();5051final String name = OneKDC.USER;52final char[] password = OneKDC.PASS;53char[] badpassword = "hellokitty".toCharArray();5455Map<String,String> map = new HashMap<>();56map.put("useTicketCache", "false");57map.put("doNotPrompt", "false");58map.put("tryFirstPass", "true");59Map<String,Object> shared = new HashMap<>();60shared.put("javax.security.auth.login.name", name);61shared.put("javax.security.auth.login.password", badpassword);6263krb5.initialize(new Subject(), new CallbackHandler() {64@Override65public void handle(Callback[] callbacks) {66for(Callback callback: callbacks) {67if (callback instanceof NameCallback) {68((NameCallback)callback).setName(name);69}70if (callback instanceof PasswordCallback) {71((PasswordCallback)callback).setPassword(password);72}73}74}75}, shared, map);76krb5.login();77}78}798081