Search in sources :

Example 6 with Krb5LoginModule

use of com.sun.security.auth.module.Krb5LoginModule in project jdk8u_jdk by JetBrains.

the class Context method fromUserPass.

/**
     * Logins with username/password as an existing Subject. The
     * same subject can be used multiple times to simulate multiple logins.
     * @param s existing subject
     */
public static Context fromUserPass(Subject s, String user, char[] pass, boolean storeKey) throws Exception {
    Context out = new Context();
    out.name = user;
    out.s = s;
    Krb5LoginModule krb5 = new Krb5LoginModule();
    Map<String, String> map = new HashMap<>();
    Map<String, Object> shared = new HashMap<>();
    if (pass != null) {
        map.put("useFirstPass", "true");
        shared.put("javax.security.auth.login.name", user);
        shared.put("javax.security.auth.login.password", pass);
    } else {
        map.put("doNotPrompt", "true");
        map.put("useTicketCache", "true");
        if (user != null) {
            map.put("principal", user);
        }
    }
    if (storeKey) {
        map.put("storeKey", "true");
    }
    krb5.initialize(out.s, null, shared, map);
    krb5.login();
    krb5.commit();
    return out;
}
Also used : LoginContext(javax.security.auth.login.LoginContext) ExtendedGSSContext(com.sun.security.jgss.ExtendedGSSContext) GSSContext(org.ietf.jgss.GSSContext) Krb5LoginModule(com.sun.security.auth.module.Krb5LoginModule) HashMap(java.util.HashMap)

Aggregations

Krb5LoginModule (com.sun.security.auth.module.Krb5LoginModule)6 HashMap (java.util.HashMap)5 Subject (javax.security.auth.Subject)3 ExtendedGSSContext (com.sun.security.jgss.ExtendedGSSContext)2 LoginContext (javax.security.auth.login.LoginContext)2 GSSContext (org.ietf.jgss.GSSContext)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Callback (javax.security.auth.callback.Callback)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 NameCallback (javax.security.auth.callback.NameCallback)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1