Search in sources :

Example 66 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException 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 67 with UnsupportedCallbackException

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

the class Krb5LoginModuleTest method loginSuccess.

@Test
public void loginSuccess() throws Exception {
    Krb5LoginModule underTest = new Krb5LoginModule();
    final Subject subject = new Subject();
    underTest.initialize(subject, new CallbackHandler() {

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            ((Krb5Callback) callbacks[0]).setPeerPrincipal(new UserPrincipal("A"));
        }
    }, null, null);
    assertTrue(underTest.login());
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) Callback(javax.security.auth.callback.Callback) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 68 with UnsupportedCallbackException

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

the class Krb5LoginModuleTest method loginFail.

@Test
public void loginFail() throws Exception {
    Krb5LoginModule underTest = new Krb5LoginModule();
    final Subject subject = new Subject();
    underTest.initialize(subject, new CallbackHandler() {

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
        }
    }, null, null);
    assertFalse(underTest.login());
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) Callback(javax.security.auth.callback.Callback) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 69 with UnsupportedCallbackException

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

the class TextFileCertificateLoginModuleTest method getJaasCertificateCallbackHandler.

private JaasCallbackHandler getJaasCertificateCallbackHandler(String user) {
    JMXPrincipal principal = new JMXPrincipal(user);
    X509Certificate cert = new StubX509Certificate(principal);
    return new JaasCallbackHandler(null, null, null) {

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            for (Callback callback : callbacks) {
                if (callback instanceof CertificateCallback) {
                    CertificateCallback certCallback = (CertificateCallback) callback;
                    certCallback.setCertificates(new X509Certificate[] { cert });
                } else {
                    throw new UnsupportedCallbackException(callback);
                }
            }
        }
    };
}
Also used : CertificateCallback(org.apache.activemq.artemis.spi.core.security.jaas.CertificateCallback) Callback(javax.security.auth.callback.Callback) JMXPrincipal(javax.management.remote.JMXPrincipal) CertificateCallback(org.apache.activemq.artemis.spi.core.security.jaas.CertificateCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) X509Certificate(javax.security.cert.X509Certificate) JaasCallbackHandler(org.apache.activemq.artemis.spi.core.security.jaas.JaasCallbackHandler)

Example 70 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException 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)

Aggregations

UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)332 Callback (javax.security.auth.callback.Callback)213 IOException (java.io.IOException)201 NameCallback (javax.security.auth.callback.NameCallback)182 PasswordCallback (javax.security.auth.callback.PasswordCallback)177 LoginException (javax.security.auth.login.LoginException)89 CallbackHandler (javax.security.auth.callback.CallbackHandler)63 FailedLoginException (javax.security.auth.login.FailedLoginException)45 LoginContext (javax.security.auth.login.LoginContext)43 Subject (javax.security.auth.Subject)36 Principal (java.security.Principal)34 AuthorizeCallback (javax.security.sasl.AuthorizeCallback)31 RealmCallback (javax.security.sasl.RealmCallback)27 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 HashMap (java.util.HashMap)23 CallerPrincipalCallback (javax.security.auth.message.callback.CallerPrincipalCallback)23 Test (org.junit.Test)21 GroupPrincipalCallback (javax.security.auth.message.callback.GroupPrincipalCallback)20 SaslException (javax.security.sasl.SaslException)19 AuthException (javax.security.auth.message.AuthException)18