1/*
2 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 6716534
27 * @compile -XDignore.symbol.file CleanState.java
28 * @run main/othervm CleanState
29 * @summary Krb5LoginModule has not cleaned temp info between authentication attempts
30 */
31import com.sun.security.auth.module.Krb5LoginModule;
32import java.util.HashMap;
33import java.util.Map;
34import javax.security.auth.Subject;
35import javax.security.auth.callback.Callback;
36import javax.security.auth.callback.CallbackHandler;
37import javax.security.auth.callback.NameCallback;
38import javax.security.auth.callback.PasswordCallback;
39
40public class CleanState {
41    public static void main(String[] args) throws Exception {
42        CleanState x = new CleanState();
43        new OneKDC(null);
44        x.go();
45    }
46
47    void go() throws Exception {
48        Krb5LoginModule krb5 = new Krb5LoginModule();
49
50        final String name = OneKDC.USER;
51        final char[] password = OneKDC.PASS;
52        char[] badpassword = "hellokitty".toCharArray();
53
54        Map<String,String> map = new HashMap<>();
55        map.put("useTicketCache", "false");
56        map.put("doNotPrompt", "false");
57        map.put("tryFirstPass", "true");
58        Map<String,Object> shared = new HashMap<>();
59        shared.put("javax.security.auth.login.name", name);
60        shared.put("javax.security.auth.login.password", badpassword);
61
62        krb5.initialize(new Subject(), new CallbackHandler() {
63            @Override
64            public void handle(Callback[] callbacks) {
65                for(Callback callback: callbacks) {
66                    if (callback instanceof NameCallback) {
67                        ((NameCallback)callback).setName(name);
68                    }
69                    if (callback instanceof PasswordCallback) {
70                        ((PasswordCallback)callback).setPassword(password);
71                    }
72                }
73            }
74        }, shared, map);
75        krb5.login();
76    }
77}
78