Search in sources :

Example 96 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project atlas by apache.

the class AtlasAuthenticationKerberosFilterTest method loginTestUser.

protected Subject loginTestUser() throws LoginException, IOException {
    LoginContext lc = new LoginContext(TEST_USER_JAAS_SECTION, new CallbackHandler() {

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback callback : callbacks) {
                if (callback instanceof PasswordCallback) {
                    PasswordCallback passwordCallback = (PasswordCallback) callback;
                    passwordCallback.setPassword(TESTPASS.toCharArray());
                }
                if (callback instanceof NameCallback) {
                    NameCallback nameCallback = (NameCallback) callback;
                    nameCallback.setName(TESTUSER);
                }
            }
        }
    });
    // attempt authentication
    lc.login();
    return lc.getSubject();
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) LoginContext(javax.security.auth.login.LoginContext) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 97 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project activemq-artemis by apache.

the class LDAPLoginModuleMaskPasswordTest method testLoginExternalCodecUnauthenticated.

@Test
public void testLoginExternalCodecUnauthenticated() throws LoginException {
    LoginContext context = new LoginContext("LDAPLoginExternalPasswordCodec", callbacks -> {
        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                ((NameCallback) callbacks[i]).setName("first");
            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback) callbacks[i]).setPassword("nosecret".toCharArray());
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
    });
    try {
        context.login();
    } catch (FailedLoginException le) {
        assertEquals(le.getMessage(), "Password does not match for user: first");
        return;
    }
    fail("Should have failed authenticating");
}
Also used : LoginContext(javax.security.auth.login.LoginContext) NameCallback(javax.security.auth.callback.NameCallback) FailedLoginException(javax.security.auth.login.FailedLoginException) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) Test(org.junit.Test)

Example 98 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project activemq-artemis by apache.

the class LDAPLoginModuleMaskPasswordTest method testLoginExternalCodec2.

@Test
public void testLoginExternalCodec2() throws LoginException {
    LoginContext context = new LoginContext("LDAPLoginExternalPasswordCodec2", callbacks -> {
        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                ((NameCallback) callbacks[i]).setName("first");
            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback) callbacks[i]).setPassword("secret".toCharArray());
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
    });
    context.login();
    context.logout();
}
Also used : LoginContext(javax.security.auth.login.LoginContext) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) Test(org.junit.Test)

Example 99 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project activemq-artemis by apache.

the class LDAPLoginModuleMaskPasswordTest method testLoginMaskedPasswordUnauthenticated.

@Test
public void testLoginMaskedPasswordUnauthenticated() throws LoginException {
    LoginContext context = new LoginContext("LDAPLoginMaskedPassword", callbacks -> {
        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                ((NameCallback) callbacks[i]).setName("first");
            } else if (callbacks[i] instanceof PasswordCallback) {
                ((PasswordCallback) callbacks[i]).setPassword("nosecret".toCharArray());
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        }
    });
    try {
        context.login();
    } catch (FailedLoginException le) {
        assertEquals(le.getMessage(), "Password does not match for user: first");
        return;
    }
    fail("Should have failed authenticating");
}
Also used : LoginContext(javax.security.auth.login.LoginContext) NameCallback(javax.security.auth.callback.NameCallback) FailedLoginException(javax.security.auth.login.FailedLoginException) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) Test(org.junit.Test)

Example 100 with PasswordCallback

use of javax.security.auth.callback.PasswordCallback in project activemq-artemis by apache.

the class LDAPLoginModuleTest method testLogin.

@Test
public void testLogin() throws LoginException {
    LoginContext context = new LoginContext("LDAPLogin", new CallbackHandler() {

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (int i = 0; i < callbacks.length; i++) {
                if (callbacks[i] instanceof NameCallback) {
                    ((NameCallback) callbacks[i]).setName("first");
                } else if (callbacks[i] instanceof PasswordCallback) {
                    ((PasswordCallback) callbacks[i]).setPassword("secret".toCharArray());
                } else {
                    throw new UnsupportedCallbackException(callbacks[i]);
                }
            }
        }
    });
    context.login();
    context.logout();
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) LoginContext(javax.security.auth.login.LoginContext) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) Test(org.junit.Test)

Aggregations

PasswordCallback (javax.security.auth.callback.PasswordCallback)316 NameCallback (javax.security.auth.callback.NameCallback)255 Callback (javax.security.auth.callback.Callback)207 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)167 IOException (java.io.IOException)102 LoginException (javax.security.auth.login.LoginException)72 CallbackHandler (javax.security.auth.callback.CallbackHandler)66 LoginContext (javax.security.auth.login.LoginContext)39 FailedLoginException (javax.security.auth.login.FailedLoginException)35 RealmCallback (javax.security.sasl.RealmCallback)35 Subject (javax.security.auth.Subject)31 Test (org.junit.Test)28 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)26 AuthorizeCallback (javax.security.sasl.AuthorizeCallback)26 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)24 Principal (java.security.Principal)21 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)18 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)18 HashMap (java.util.HashMap)16 Test (org.testng.annotations.Test)15