Search in sources :

Example 76 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project testcases by coheigea.

the class SAML2CallbackHandler method handle.

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof SAMLCallback) {
            SAMLCallback callback = (SAMLCallback) callbacks[i];
            callback.setSamlVersion(Version.SAML_20);
            callback.setIssuer(issuer);
            if (conditions != null) {
                callback.setConditions(conditions);
            }
            SubjectBean subjectBean = new SubjectBean(subjectName, subjectQualifier, confirmationMethod);
            if (subjectNameIDFormat != null) {
                subjectBean.setSubjectNameIDFormat(subjectNameIDFormat);
            }
            subjectBean.setSubjectConfirmationData(subjectConfirmationData);
            callback.setSubject(subjectBean);
            createAndSetStatement(callback);
        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}
Also used : SubjectBean(org.apache.wss4j.common.saml.bean.SubjectBean) SAMLCallback(org.apache.wss4j.common.saml.SAMLCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 77 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project testcases by coheigea.

the class ClaimsCallbackHandler method handle.

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof ClaimsCallback) {
            ClaimsCallback callback = (ClaimsCallback) callbacks[i];
            callback.setClaims(createClaims());
        } else {
            throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
        }
    }
}
Also used : ClaimsCallback(org.apache.cxf.ws.security.trust.claims.ClaimsCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 78 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project apex-core by apache.

the class DefaultCallbackHandlerTest method testHandler.

@Test
public void testHandler() {
    DefaultCallbackHandler handler = new DefaultCallbackHandler();
    SecurityContext context = new SecurityContext();
    handler.setup(context);
    Callback[] callbacks = new Callback[3];
    callbacks[0] = new NameCallback("UserName:");
    callbacks[1] = new PasswordCallback("Password:", false);
    callbacks[2] = new RealmCallback("Realm:");
    try {
        handler.handle(callbacks);
        Assert.assertEquals("Username", "user1", ((NameCallback) callbacks[0]).getName());
        Assert.assertEquals("Password", "pass", new String(((PasswordCallback) callbacks[1]).getPassword()));
        Assert.assertEquals("Realm", "default", ((RealmCallback) callbacks[2]).getText());
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    } catch (UnsupportedCallbackException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : RealmCallback(javax.security.sasl.RealmCallback) 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) RealmCallback(javax.security.sasl.RealmCallback) Test(org.junit.Test)

Example 79 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project apex-core by apache.

the class DefaultCallbackHandler method processCallback.

protected void processCallback(Callback callback) throws IOException, UnsupportedCallbackException {
    if (callback instanceof NameCallback) {
        NameCallback namecb = (NameCallback) callback;
        namecb.setName(context.getValue(SecurityContext.USER_NAME));
    } else if (callback instanceof PasswordCallback) {
        PasswordCallback passcb = (PasswordCallback) callback;
        passcb.setPassword(context.getValue(SecurityContext.PASSWORD));
    } else if (callback instanceof RealmCallback) {
        RealmCallback realmcb = (RealmCallback) callback;
        realmcb.setText(context.getValue(SecurityContext.REALM));
    } else if (callback instanceof TextOutputCallback) {
        TextOutputCallback textcb = (TextOutputCallback) callback;
        if (textcb.getMessageType() == TextOutputCallback.INFORMATION) {
            logger.info(textcb.getMessage());
        } else if (textcb.getMessageType() == TextOutputCallback.WARNING) {
            logger.warn(textcb.getMessage());
        } else if (textcb.getMessageType() == TextOutputCallback.ERROR) {
            logger.error(textcb.getMessage());
        } else {
            logger.debug("Auth message type {}, message {}", textcb.getMessageType(), textcb.getMessage());
        }
    } else {
        throw new UnsupportedCallbackException(callback);
    }
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) RealmCallback(javax.security.sasl.RealmCallback)

Example 80 with UnsupportedCallbackException

use of javax.security.auth.callback.UnsupportedCallbackException in project javaee7-samples by javaee-samples.

the class TestServerAuthModule method validateRequest.

@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {
    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    Callback[] callbacks;
    if (request.getParameter("doLogin") != null) {
        // For the test perform a login by directly "returning" the details of the authenticated user.
        // Normally credentials would be checked and the details fetched from some repository
        callbacks = new Callback[] { // The name of the authenticated user
        new CallerPrincipalCallback(clientSubject, "test"), // the roles of the authenticated user
        new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) };
    } else {
        // The JASPIC protocol for "do nothing"
        callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) };
    }
    try {
        // Communicate the details of the authenticated user to the container. In many
        // cases the handler will just store the details and the container will actually handle
        // the login after we return from this method.
        handler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw (AuthException) new AuthException().initCause(e);
    }
    return SUCCESS;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CallerPrincipalCallback(javax.security.auth.message.callback.CallerPrincipalCallback) GroupPrincipalCallback(javax.security.auth.message.callback.GroupPrincipalCallback) GroupPrincipalCallback(javax.security.auth.message.callback.GroupPrincipalCallback) CallerPrincipalCallback(javax.security.auth.message.callback.CallerPrincipalCallback) Callback(javax.security.auth.callback.Callback) AuthException(javax.security.auth.message.AuthException) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) Principal(java.security.Principal)

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