Search in sources :

Example 21 with CallerPrincipalCallback

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

the class TomEEHttpMessageContext method notifyContainerAboutLogin.

@Override
public AuthenticationStatus notifyContainerAboutLogin(final Principal principal, final Set<String> groups) {
    try {
        handler.handle(new Callback[] { new CallerPrincipalCallback(clientSubject, principal), new GroupPrincipalCallback(clientSubject, groups.toArray(new String[groups.size()])) });
    } catch (final IOException | UnsupportedCallbackException e) {
        e.printStackTrace();
    }
    this.principal = principal;
    this.groups = groups;
    TomEESecurityContext.registerContainerAboutLogin(principal, groups);
    return SUCCESS;
}
Also used : CallerPrincipalCallback(javax.security.auth.message.callback.CallerPrincipalCallback) GroupPrincipalCallback(javax.security.auth.message.callback.GroupPrincipalCallback) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 22 with CallerPrincipalCallback

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

use of javax.security.auth.message.callback.CallerPrincipalCallback in project Payara by payara.

the class ConnectorCallbackHandler method processResults.

private void processResults(Callback[] mappedCallbacks, boolean hasCallerPrincipalCallback) {
    if (mappedCallbacks != null) {
        Subject s = new Subject();
        // Handle Single Principal as the caller identity
        if (!hasCallerPrincipalCallback) {
            Set<Principal> principals = executionSubject.getPrincipals();
            if (principals != null && principals.size() == 1) {
                // process if there is only one principal
                for (Principal p : principals) {
                    Principal mappedPrincipal = null;
                    if (needMapping) {
                        mappedPrincipal = getMappedPrincipal(p, null);
                    } else {
                        mappedPrincipal = p;
                    }
                    if (mappedPrincipal != null) {
                        s.getPrincipals().add(mappedPrincipal);
                    }
                }
                s.getPublicCredentials().addAll(executionSubject.getPublicCredentials());
                s.getPrivateCredentials().addAll(executionSubject.getPrivateCredentials());
            }
        }
        // TODO V3 what happens for Public/Private Credentials of Mapped case (Case II)
        for (Callback callback : mappedCallbacks) {
            if (callback instanceof CallerPrincipalCallback) {
                CallerPrincipalCallback cpc = (CallerPrincipalCallback) callback;
                s.getPrincipals().addAll(cpc.getSubject().getPrincipals());
                s.getPublicCredentials().addAll(cpc.getSubject().getPublicCredentials());
                s.getPrivateCredentials().addAll(cpc.getSubject().getPrivateCredentials());
            } else if (callback instanceof GroupPrincipalCallback) {
                GroupPrincipalCallback gpc = (GroupPrincipalCallback) callback;
                s.getPrincipals().addAll(gpc.getSubject().getPrincipals());
                s.getPublicCredentials().addAll(gpc.getSubject().getPublicCredentials());
                s.getPrivateCredentials().addAll(gpc.getSubject().getPrivateCredentials());
            } else if (callback instanceof PasswordValidationCallback) {
                PasswordValidationCallback pvc = (PasswordValidationCallback) callback;
                s.getPrincipals().addAll(pvc.getSubject().getPrincipals());
                s.getPublicCredentials().addAll(pvc.getSubject().getPublicCredentials());
                s.getPrivateCredentials().addAll(pvc.getSubject().getPrivateCredentials());
            }
        }
        SecurityContext.setCurrent(new SecurityContext(s));
    }
}
Also used : CallerPrincipalCallback(javax.security.auth.message.callback.CallerPrincipalCallback) GroupPrincipalCallback(javax.security.auth.message.callback.GroupPrincipalCallback) GroupPrincipalCallback(javax.security.auth.message.callback.GroupPrincipalCallback) PasswordValidationCallback(javax.security.auth.message.callback.PasswordValidationCallback) CallerPrincipalCallback(javax.security.auth.message.callback.CallerPrincipalCallback) Callback(javax.security.auth.callback.Callback) SecurityContext(com.sun.enterprise.security.SecurityContext) PasswordValidationCallback(javax.security.auth.message.callback.PasswordValidationCallback) Subject(javax.security.auth.Subject) Principal(java.security.Principal)

Example 24 with CallerPrincipalCallback

use of javax.security.auth.message.callback.CallerPrincipalCallback 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();
    HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage();
    if ("cdi".equals(request.getParameter("tech"))) {
        callCDIBean(request, response, "validateRequest");
    } else if ("ejb".equals(request.getParameter("tech"))) {
        callEJBBean(response, "validateRequest");
    }
    try {
        handler.handle(new Callback[] { new CallerPrincipalCallback(clientSubject, "test"), new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) });
        return SUCCESS;
    } catch (IOException | UnsupportedCallbackException e) {
        throw (AuthException) new AuthException().initCause(e);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CallerPrincipalCallback(javax.security.auth.message.callback.CallerPrincipalCallback) GroupPrincipalCallback(javax.security.auth.message.callback.GroupPrincipalCallback) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthException(javax.security.auth.message.AuthException) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 25 with CallerPrincipalCallback

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

the class TestServerAuthModule method validateRequest.

@SuppressWarnings("unchecked")
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {
    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    Callback[] callbacks;
    Principal userPrincipal = request.getUserPrincipal();
    if (userPrincipal != null && request.getParameter("continueSession") != null) {
        // ### If already authenticated before, continue this session
        // Execute protocol to signal container registered authentication session be used.
        callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, userPrincipal) };
    } else if (request.getParameter("doLogin") != null) {
        // ### If not authenticated before, do a new login if so requested
        // 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[] { request.getParameter("customPrincipal") == null ? // Name based Callback
        new CallerPrincipalCallback(clientSubject, "test") : // Custom principal based Callback
        new CallerPrincipalCallback(clientSubject, new MyPrincipal("test")), // the roles of the authenticated user
        new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) };
        // Tell container to register an authentication session.
        messageInfo.getMap().put("javax.servlet.http.registerSession", TRUE.toString());
    } else {
        // ### If no registered session and no login request "do nothing"
        // 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

CallerPrincipalCallback (javax.security.auth.message.callback.CallerPrincipalCallback)30 GroupPrincipalCallback (javax.security.auth.message.callback.GroupPrincipalCallback)24 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)21 IOException (java.io.IOException)18 Principal (java.security.Principal)17 AuthException (javax.security.auth.message.AuthException)16 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 Callback (javax.security.auth.callback.Callback)14 PasswordValidationCallback (javax.security.auth.message.callback.PasswordValidationCallback)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 Subject (javax.security.auth.Subject)4 CertStoreCallback (javax.security.auth.message.callback.CertStoreCallback)3 PrivateKeyCallback (javax.security.auth.message.callback.PrivateKeyCallback)3 SecretKeyCallback (javax.security.auth.message.callback.SecretKeyCallback)3 TrustStoreCallback (javax.security.auth.message.callback.TrustStoreCallback)3 Map (java.util.Map)2 HttpSession (javax.servlet.http.HttpSession)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