Search in sources :

Example 86 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler in project jspwiki by apache.

the class CookieAssertionLoginModuleTest method testLogout.

public final void testLogout() {
    MockHttpServletRequest request = m_engine.newHttpRequest();
    Cookie cookie = new Cookie(CookieAssertionLoginModule.PREFS_COOKIE_NAME, "Bullwinkle");
    request.setCookies(new Cookie[] { cookie });
    try {
        CallbackHandler handler = new WebContainerCallbackHandler(m_engine, request);
        LoginModule module = new CookieAssertionLoginModule();
        module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
        module.login();
        module.commit();
        Set<Principal> principals = m_subject.getPrincipals();
        Assert.assertEquals(1, principals.size());
        Assert.assertTrue(principals.contains(new WikiPrincipal("Bullwinkle")));
        Assert.assertFalse(principals.contains(Role.ANONYMOUS));
        Assert.assertFalse(principals.contains(Role.ALL));
        module.logout();
        Assert.assertEquals(0, principals.size());
    } catch (LoginException e) {
        System.err.println(e.getMessage());
        Assert.assertTrue(false);
    }
}
Also used : Cookie(javax.servlet.http.Cookie) CallbackHandler(javax.security.auth.callback.CallbackHandler) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest) LoginModule(javax.security.auth.spi.LoginModule) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) LoginException(javax.security.auth.login.LoginException) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal)

Example 87 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler in project jspwiki by apache.

the class UserDatabaseLoginModuleTest method testLogout.

public final void testLogout() {
    try {
        CallbackHandler handler = new WikiCallbackHandler(m_engine, null, "user", "password");
        LoginModule module = new UserDatabaseLoginModule();
        module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
        module.login();
        module.commit();
        Set<Principal> principals = m_subject.getPrincipals();
        Assert.assertEquals(1, principals.size());
        Assert.assertTrue(principals.contains(new WikiPrincipal("user", WikiPrincipal.LOGIN_NAME)));
        Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
        Assert.assertFalse(principals.contains(Role.ALL));
        module.logout();
        Assert.assertEquals(0, principals.size());
    } catch (LoginException e) {
        System.err.println(e.getMessage());
        Assert.assertTrue(false);
    }
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) LoginException(javax.security.auth.login.LoginException) LoginModule(javax.security.auth.spi.LoginModule) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal)

Example 88 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler in project jspwiki by apache.

the class UserDatabaseLoginModuleTest method testLogin.

public final void testLogin() {
    try {
        // Log in with a user that isn't in the database
        CallbackHandler handler = new WikiCallbackHandler(m_engine, null, "user", "password");
        LoginModule module = new UserDatabaseLoginModule();
        module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
        module.login();
        module.commit();
        Set<Principal> principals = m_subject.getPrincipals();
        Assert.assertEquals(1, principals.size());
        Assert.assertTrue(principals.contains(new WikiPrincipal("user", WikiPrincipal.LOGIN_NAME)));
        Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
        Assert.assertFalse(principals.contains(Role.ALL));
        // Login with a user that IS in the database
        m_subject = new Subject();
        handler = new WikiCallbackHandler(m_engine, null, "janne", "myP@5sw0rd");
        module = new UserDatabaseLoginModule();
        module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
        module.login();
        module.commit();
        principals = m_subject.getPrincipals();
        Assert.assertEquals(1, principals.size());
        Assert.assertTrue(principals.contains(new WikiPrincipal("janne", WikiPrincipal.LOGIN_NAME)));
        Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
        Assert.assertFalse(principals.contains(Role.ALL));
    } catch (LoginException e) {
        System.err.println(e.getMessage());
        Assert.assertTrue(false);
    }
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) LoginException(javax.security.auth.login.LoginException) LoginModule(javax.security.auth.spi.LoginModule) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) Subject(javax.security.auth.Subject)

Example 89 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler in project teiid by teiid.

the class AdminFactory method createAdmin.

/**
 * Creates a ServerAdmin with the specified connection properties.
 * @param userName
 * @param password
 * @param serverURL
 * @param applicationName
 * @return
 * @throws AdminException
 */
public Admin createAdmin(String host, int port, String userName, char[] password) throws AdminException {
    if (host == null) {
        // $NON-NLS-1$
        host = "localhost";
    }
    if (port < 0) {
        port = 9990;
    }
    try {
        CallbackHandler cbh = new AuthenticationCallbackHandler(userName, password);
        ModelControllerClient newClient = ModelControllerClient.Factory.create(host, port, cbh);
        List<String> nodeTypes = Util.getNodeTypes(newClient, new DefaultOperationRequestAddress());
        if (!nodeTypes.isEmpty()) {
            // $NON-NLS-1$
            boolean domainMode = nodeTypes.contains("server-group");
            LOGGER.info(// $NON-NLS-1$
            "Connected to " + // $NON-NLS-1$ //$NON-NLS-2$
            (domainMode ? "domain controller at " : "standalone controller at ") + host + ":" + // $NON-NLS-1$
            port);
            return new AdminImpl(newClient);
        }
        LOGGER.info(AdminPlugin.Util.gs(AdminPlugin.Event.TEIID70051, host, port));
    } catch (UnknownHostException e) {
        throw new AdminProcessingException(AdminPlugin.Event.TEIID70000, AdminPlugin.Util.gs(AdminPlugin.Event.TEIID70000, host, e.getLocalizedMessage()));
    }
    return null;
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) UnknownHostException(java.net.UnknownHostException) DefaultOperationRequestAddress(org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress)

Example 90 with CallbackHandler

use of javax.security.auth.callback.CallbackHandler in project jmulticard by ctt-gob-es.

the class TestJseProvider method testProviderWithCustomConnection.

static void testProviderWithCustomConnection() throws Exception {
    final Provider p = new DnieProvider(new SmartcardIoConnection());
    Security.addProvider(p);
    // $NON-NLS-1$
    final KeyStore ks = KeyStore.getInstance("DNI");
    final CallbackHandler callbackHandler;
    // $NON-NLS-1$
    callbackHandler = (CallbackHandler) Class.forName("es.gob.jmulticard.ui.passwordcallback.gui.DnieCallbackHandler").getConstructor().newInstance();
    final LoadStoreParameter lsp = new LoadStoreParameter() {

        @Override
        public ProtectionParameter getProtectionParameter() {
            return new KeyStore.CallbackHandlerProtection(callbackHandler);
        }
    };
    ks.load(lsp);
    final Enumeration<String> aliases = ks.aliases();
    while (aliases.hasMoreElements()) {
        System.out.println(aliases.nextElement());
    }
    // $NON-NLS-1$
    final Signature signature = Signature.getInstance("SHA1withRSA");
    // $NON-NLS-1$
    signature.initSign((PrivateKey) ks.getKey("CertFirmaDigital", PASSWORD));
    // $NON-NLS-1$
    signature.update("Hola Mundo!!".getBytes());
    signature.sign();
    // $NON-NLS-1$
    System.out.println("Firma generada correctamente");
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) DnieProvider(es.gob.jmulticard.jse.provider.DnieProvider) Signature(java.security.Signature) SmartcardIoConnection(es.gob.jmulticard.jse.smartcardio.SmartcardIoConnection) KeyStore(java.security.KeyStore) Provider(java.security.Provider) DnieProvider(es.gob.jmulticard.jse.provider.DnieProvider) LoadStoreParameter(java.security.KeyStore.LoadStoreParameter)

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