678N/A/*
3579N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
678N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
678N/A *
678N/A * This code is free software; you can redistribute it and/or modify it
678N/A * under the terms of the GNU General Public License version 2 only, as
678N/A * published by the Free Software Foundation.
678N/A *
678N/A * This code is distributed in the hope that it will be useful, but WITHOUT
678N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
678N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
678N/A * version 2 for more details (a copy is included in the LICENSE file that
678N/A * accompanied this code).
678N/A *
678N/A * You should have received a copy of the GNU General Public License version
678N/A * 2 along with this work; if not, write to the Free Software Foundation,
678N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
678N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
678N/A */
678N/A
678N/A/*
678N/A * @test
678N/A * @bug 6716534
3579N/A * @run main/othervm CleanState
678N/A * @summary Krb5LoginModule has not cleaned temp info between authentication attempts
678N/A */
678N/Aimport com.sun.security.auth.module.Krb5LoginModule;
678N/Aimport java.util.HashMap;
678N/Aimport java.util.Map;
678N/Aimport javax.security.auth.Subject;
678N/Aimport javax.security.auth.callback.Callback;
678N/Aimport javax.security.auth.callback.CallbackHandler;
678N/Aimport javax.security.auth.callback.NameCallback;
678N/Aimport javax.security.auth.callback.PasswordCallback;
678N/A
678N/Apublic class CleanState {
678N/A public static void main(String[] args) throws Exception {
678N/A CleanState x = new CleanState();
678N/A new OneKDC(null);
678N/A x.go();
678N/A }
678N/A
678N/A void go() throws Exception {
678N/A Krb5LoginModule krb5 = new Krb5LoginModule();
678N/A
678N/A final String name = OneKDC.USER;
678N/A final char[] password = OneKDC.PASS;
678N/A char[] badpassword = "hellokitty".toCharArray();
678N/A
3388N/A Map<String,String> map = new HashMap<>();
678N/A map.put("useTicketCache", "false");
678N/A map.put("doNotPrompt", "false");
678N/A map.put("tryFirstPass", "true");
3388N/A Map<String,Object> shared = new HashMap<>();
678N/A shared.put("javax.security.auth.login.name", name);
678N/A shared.put("javax.security.auth.login.password", badpassword);
678N/A
678N/A krb5.initialize(new Subject(), new CallbackHandler() {
678N/A @Override
678N/A public void handle(Callback[] callbacks) {
678N/A for(Callback callback: callbacks) {
678N/A if (callback instanceof NameCallback) {
678N/A ((NameCallback)callback).setName(name);
678N/A }
678N/A if (callback instanceof PasswordCallback) {
678N/A ((PasswordCallback)callback).setPassword(password);
678N/A }
678N/A }
678N/A }
678N/A }, shared, map);
678N/A krb5.login();
678N/A }
678N/A}