Search in sources :

Example 96 with CallbackHandler

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

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

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

Example 99 with CallbackHandler

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

the class GuestLoginModuleTest method testLoginWithDefaults.

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

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            assertEquals("Should have no Callbacks", 0, callbacks.length);
        }
    });
    context.login();
    Subject subject = context.getSubject();
    assertEquals("Should have two principals", 2, subject.getPrincipals().size());
    assertEquals("Should have one user principal", 1, subject.getPrincipals(UserPrincipal.class).size());
    assertTrue("User principal is 'guest'", subject.getPrincipals(UserPrincipal.class).contains(new UserPrincipal("guest")));
    assertEquals("Should have one group principal", 1, subject.getPrincipals(RolePrincipal.class).size());
    assertTrue("Role principal is 'guests'", subject.getPrincipals(RolePrincipal.class).contains(new RolePrincipal("guests")));
    context.logout();
    assertEquals("Should have zero principals", 0, subject.getPrincipals().size());
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) LoginContext(javax.security.auth.login.LoginContext) Callback(javax.security.auth.callback.Callback) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) RolePrincipal(org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal) Subject(javax.security.auth.Subject) UserPrincipal(org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal) Test(org.junit.Test)

Example 100 with CallbackHandler

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

the class GuestLoginModuleTest method testLogin.

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

        @Override
        public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            assertEquals("Should have no Callbacks", 0, callbacks.length);
        }
    });
    context.login();
    Subject subject = context.getSubject();
    assertEquals("Should have two principals", 2, subject.getPrincipals().size());
    assertEquals("Should have one user principal", 1, subject.getPrincipals(UserPrincipal.class).size());
    assertTrue("User principal is 'foo'", subject.getPrincipals(UserPrincipal.class).contains(new UserPrincipal("foo")));
    assertEquals("Should have one group principal", 1, subject.getPrincipals(RolePrincipal.class).size());
    assertTrue("Role principal is 'bar'", subject.getPrincipals(RolePrincipal.class).contains(new RolePrincipal("bar")));
    context.logout();
    assertEquals("Should have zero principals", 0, subject.getPrincipals().size());
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) LoginContext(javax.security.auth.login.LoginContext) Callback(javax.security.auth.callback.Callback) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) RolePrincipal(org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal) Subject(javax.security.auth.Subject) UserPrincipal(org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal) Test(org.junit.Test)

Aggregations

CallbackHandler (javax.security.auth.callback.CallbackHandler)274 Crypto (org.apache.wss4j.common.crypto.Crypto)82 IOException (java.io.IOException)75 Callback (javax.security.auth.callback.Callback)73 Element (org.w3c.dom.Element)70 Subject (javax.security.auth.Subject)68 PasswordCallback (javax.security.auth.callback.PasswordCallback)63 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)61 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)60 Document (org.w3c.dom.Document)60 LoginContext (javax.security.auth.login.LoginContext)55 NameCallback (javax.security.auth.callback.NameCallback)51 LoginException (javax.security.auth.login.LoginException)44 Principal (java.security.Principal)42 ReceivedToken (org.apache.cxf.sts.request.ReceivedToken)42 TokenValidator (org.apache.cxf.sts.token.validator.TokenValidator)38 SAMLTokenValidator (org.apache.cxf.sts.token.validator.SAMLTokenValidator)36 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)34 Test (org.junit.Test)34 ArrayList (java.util.ArrayList)32