Search in sources :

Example 11 with GroupPrincipalCallback

use of javax.security.auth.message.callback.GroupPrincipalCallback in project tomee by apache.

the class TheServerAuthModule 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) {
        callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, "test"), new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) };
    } else {
        callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) };
    }
    try {
        handler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw (AuthException) new AuthException().initCause(e);
    }
    cdi(messageInfo, "vr");
    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)

Example 12 with GroupPrincipalCallback

use of javax.security.auth.message.callback.GroupPrincipalCallback in project tomee by apache.

the class ConnectorCallbackHandler method handle.

public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (final Callback callback : callbacks) {
        // jaspi to server communication
        if (callback instanceof CallerPrincipalCallback) {
            callerPrincipal = ((CallerPrincipalCallback) callback).getPrincipal();
        } else if (callback instanceof GroupPrincipalCallback) {
            groupsArray = ((GroupPrincipalCallback) callback).getGroups();
        } else if (callback instanceof PasswordValidationCallback) {
            final PasswordValidationCallback passwordValidationCallback = (PasswordValidationCallback) callback;
            final String userName = passwordValidationCallback.getUsername();
            final char[] password = passwordValidationCallback.getPassword();
            final SecurityService securityService = SystemInstance.get().getComponent(SecurityService.class);
            try {
                final Object loginObj = securityService.login(securityRealmName, userName, password == null ? "" : new String(password));
                securityService.associate(loginObj);
                callerPrincipal = securityService.getCallerPrincipal();
                passwordValidationCallback.setResult(true);
            } catch (final LoginException e) {
                passwordValidationCallback.setResult(false);
            }
        } else // server to jaspi communication
        if (callback instanceof CertStoreCallback) {
        //NOPMD
        // TODO implement me
        } else if (callback instanceof PrivateKeyCallback) {
        //NOPMD
        // TODO implement me
        } else if (callback instanceof SecretKeyCallback) {
        //NOPMD
        // TODO implement me
        } else if (callback instanceof TrustStoreCallback) {
        //NOPMD
        // TODO implement me
        } else {
            throw new UnsupportedCallbackException(callback);
        }
    }
}
Also used : SecretKeyCallback(javax.security.auth.message.callback.SecretKeyCallback) TrustStoreCallback(javax.security.auth.message.callback.TrustStoreCallback) CertStoreCallback(javax.security.auth.message.callback.CertStoreCallback) CallerPrincipalCallback(javax.security.auth.message.callback.CallerPrincipalCallback) GroupPrincipalCallback(javax.security.auth.message.callback.GroupPrincipalCallback) TrustStoreCallback(javax.security.auth.message.callback.TrustStoreCallback) GroupPrincipalCallback(javax.security.auth.message.callback.GroupPrincipalCallback) PasswordValidationCallback(javax.security.auth.message.callback.PasswordValidationCallback) CallerPrincipalCallback(javax.security.auth.message.callback.CallerPrincipalCallback) CertStoreCallback(javax.security.auth.message.callback.CertStoreCallback) PrivateKeyCallback(javax.security.auth.message.callback.PrivateKeyCallback) SecretKeyCallback(javax.security.auth.message.callback.SecretKeyCallback) Callback(javax.security.auth.callback.Callback) SecurityService(org.apache.openejb.spi.SecurityService) PasswordValidationCallback(javax.security.auth.message.callback.PasswordValidationCallback) LoginException(javax.security.auth.login.LoginException) PrivateKeyCallback(javax.security.auth.message.callback.PrivateKeyCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 13 with GroupPrincipalCallback

use of javax.security.auth.message.callback.GroupPrincipalCallback in project tomcat by apache.

the class CallbackHandlerImpl method handle.

@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    String name = null;
    Principal principal = null;
    Subject subject = null;
    String[] groups = null;
    if (callbacks != null) {
        // Process the callbacks
        for (Callback callback : callbacks) {
            if (callback instanceof CallerPrincipalCallback) {
                CallerPrincipalCallback cpc = (CallerPrincipalCallback) callback;
                name = cpc.getName();
                principal = cpc.getPrincipal();
                subject = cpc.getSubject();
            } else if (callback instanceof GroupPrincipalCallback) {
                GroupPrincipalCallback gpc = (GroupPrincipalCallback) callback;
                groups = gpc.getGroups();
            } else {
                log.error(sm.getString("callbackHandlerImpl.jaspicCallbackMissing", callback.getClass().getName()));
            }
        }
        // Create the GenericPrincipal
        Principal gp = getPrincipal(principal, name, groups);
        if (subject != null && gp != null) {
            subject.getPrivateCredentials().add(gp);
        }
    }
}
Also used : 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) GenericPrincipal(org.apache.catalina.realm.GenericPrincipal) Principal(java.security.Principal) Subject(javax.security.auth.Subject)

Example 14 with GroupPrincipalCallback

use of javax.security.auth.message.callback.GroupPrincipalCallback in project jetty.project by eclipse.

the class BaseAuthModule method login.

protected boolean login(Subject clientSubject, String username, Credential credential, String authMethod, MessageInfo messageInfo) throws IOException, UnsupportedCallbackException {
    CredentialValidationCallback credValidationCallback = new CredentialValidationCallback(clientSubject, username, credential);
    callbackHandler.handle(new Callback[] { credValidationCallback });
    if (credValidationCallback.getResult()) {
        Set<LoginCallbackImpl> loginCallbacks = clientSubject.getPrivateCredentials(LoginCallbackImpl.class);
        if (!loginCallbacks.isEmpty()) {
            LoginCallbackImpl loginCallback = loginCallbacks.iterator().next();
            CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, loginCallback.getUserPrincipal());
            GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, loginCallback.getRoles());
            callbackHandler.handle(new Callback[] { callerPrincipalCallback, groupPrincipalCallback });
        }
        messageInfo.getMap().put(JaspiMessageInfo.AUTH_METHOD_KEY, authMethod);
    }
    return credValidationCallback.getResult();
}
Also used : LoginCallbackImpl(org.eclipse.jetty.security.authentication.LoginCallbackImpl) CallerPrincipalCallback(javax.security.auth.message.callback.CallerPrincipalCallback) GroupPrincipalCallback(javax.security.auth.message.callback.GroupPrincipalCallback) CredentialValidationCallback(org.eclipse.jetty.security.jaspi.callback.CredentialValidationCallback)

Example 15 with GroupPrincipalCallback

use of javax.security.auth.message.callback.GroupPrincipalCallback 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

GroupPrincipalCallback (javax.security.auth.message.callback.GroupPrincipalCallback)20 CallerPrincipalCallback (javax.security.auth.message.callback.CallerPrincipalCallback)19 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)15 AuthException (javax.security.auth.message.AuthException)14 IOException (java.io.IOException)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 Callback (javax.security.auth.callback.Callback)12 Principal (java.security.Principal)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 Subject (javax.security.auth.Subject)3 PasswordValidationCallback (javax.security.auth.message.callback.PasswordValidationCallback)3 CertStoreCallback (javax.security.auth.message.callback.CertStoreCallback)2 PrivateKeyCallback (javax.security.auth.message.callback.PrivateKeyCallback)2 SecretKeyCallback (javax.security.auth.message.callback.SecretKeyCallback)2 TrustStoreCallback (javax.security.auth.message.callback.TrustStoreCallback)2 LoginCallbackImpl (org.eclipse.jetty.security.authentication.LoginCallbackImpl)2 CredentialValidationCallback (org.eclipse.jetty.security.jaspi.callback.CredentialValidationCallback)2 UserIdentity (org.eclipse.jetty.server.UserIdentity)2 LoginException (javax.security.auth.login.LoginException)1 AuthStatus (javax.security.auth.message.AuthStatus)1