Search in sources :

Example 21 with AuthException

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

the class AdminConsoleAuthModule method saveRequestAndForwardToLogin.

private AuthStatus saveRequestAndForwardToLogin(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws AuthException {
    // Save original request path
    String originalPath = request.getRequestURI();
    String queryString = request.getQueryString();
    if (queryString != null && !queryString.isEmpty()) {
        originalPath += "?" + queryString;
    }
    session.setAttribute(ORIG_REQUEST_PATH, originalPath);
    // Forward to login page
    try {
        request.getRequestDispatcher(loginPage).forward(request, response);
        return SEND_CONTINUE;
    } catch (Exception ex) {
        throw (AuthException) new AuthException().initCause(ex);
    }
}
Also used : AuthException(javax.security.auth.message.AuthException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) AuthException(javax.security.auth.message.AuthException)

Example 22 with AuthException

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

the class AdminConsoleAuthModule method redirectBack.

private AuthStatus redirectBack(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws AuthException {
    try {
        // Redirect...
        String origRequest = (String) session.getAttribute(ORIG_REQUEST_PATH);
        // every page
        if (origRequest == null || "/favicon.ico".equals(origRequest)) {
            origRequest = "/index.jsf";
        }
        logger.log(INFO, "Redirecting to {0}", origRequest);
        response.sendRedirect(response.encodeRedirectURL(origRequest));
        return SEND_CONTINUE;
    } catch (Exception ex) {
        throw (AuthException) new AuthException().initCause(ex);
    }
}
Also used : AuthException(javax.security.auth.message.AuthException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) AuthException(javax.security.auth.message.AuthException)

Example 23 with AuthException

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

the class GFServerConfigProvider method createModuleInfo.

/**
 * Instantiate+initialize module class
 */
static ModuleInfo createModuleInfo(Entry entry, CallbackHandler handler, String type, Map<String, Object> properties) throws AuthException {
    try {
        // instantiate module using no-arg constructor
        Object newModule = entry.newInstance();
        Map<String, Object> map = properties;
        Map<String, Object> entryOptions = entry.getOptions();
        if (entryOptions != null) {
            if (map == null) {
                map = new HashMap<>();
            } else {
                map = new HashMap<>(map);
            }
            map.putAll(entryOptions);
        }
        // No doPrivilege at this point, need to revisit
        if (SERVER.equals(type)) {
            if (newModule instanceof ServerAuthModule) {
                ServerAuthModule sam = (ServerAuthModule) newModule;
                sam.initialize(entry.getRequestPolicy(), entry.getResponsePolicy(), handler, map);
            } else if (newModule instanceof com.sun.enterprise.security.jauth.ServerAuthModule) {
                // TODO REMOVE
                com.sun.enterprise.security.jauth.ServerAuthModule sam0 = (com.sun.enterprise.security.jauth.ServerAuthModule) newModule;
                AuthPolicy requestPolicy = (entry.getRequestPolicy() != null) ? new AuthPolicy(entry.getRequestPolicy()) : null;
                AuthPolicy responsePolicy = (entry.getResponsePolicy() != null) ? new AuthPolicy(entry.getResponsePolicy()) : null;
                sam0.initialize(requestPolicy, responsePolicy, handler, map);
            }
        } else {
            // CLIENT
            if (newModule instanceof ClientAuthModule) {
                ClientAuthModule cam = (ClientAuthModule) newModule;
                cam.initialize(entry.getRequestPolicy(), entry.getResponsePolicy(), handler, map);
            } else if (newModule instanceof com.sun.enterprise.security.jauth.ClientAuthModule) {
                // TODO REMOVE
                com.sun.enterprise.security.jauth.ClientAuthModule cam0 = (com.sun.enterprise.security.jauth.ClientAuthModule) newModule;
                AuthPolicy requestPolicy = new AuthPolicy(entry.getRequestPolicy());
                AuthPolicy responsePolicy = new AuthPolicy(entry.getResponsePolicy());
                cam0.initialize(requestPolicy, responsePolicy, handler, map);
            }
        }
        return new ModuleInfo(newModule, map);
    } catch (Exception e) {
        if (e instanceof AuthException) {
            throw (AuthException) e;
        }
        AuthException ae = new AuthException();
        ae.initCause(e);
        throw ae;
    }
}
Also used : ServerAuthModule(javax.security.auth.message.module.ServerAuthModule) AuthException(javax.security.auth.message.AuthException) PendingException(com.sun.enterprise.security.jauth.PendingException) FailureException(com.sun.enterprise.security.jauth.FailureException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) AuthException(javax.security.auth.message.AuthException) AuthPolicy(com.sun.enterprise.security.jauth.AuthPolicy) ClientAuthModule(javax.security.auth.message.module.ClientAuthModule)

Example 24 with AuthException

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

the class ClientAuthConfigImpl method createAuthContext.

@Override
@SuppressWarnings("unchecked")
protected <M> M createAuthContext(String authContextID, Map<String, ?> properties) throws AuthException {
    if (!authContextHelper.isProtected(new ClientAuthModule[0], authContextID)) {
        return null;
    }
    ClientAuthContext context = new ClientAuthContext() {

        ClientAuthModule[] module = init();

        ClientAuthModule[] init() throws AuthException {
            ClientAuthModule[] clientModules;
            try {
                clientModules = authContextHelper.getModules(new ClientAuthModule[0], authContextID);
            } catch (AuthException ae) {
                logIfLevel(SEVERE, ae, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "unable to load client auth modules");
                throw ae;
            }
            MessagePolicy requestPolicy = policyDelegate.getRequestPolicy(authContextID, properties);
            MessagePolicy responsePolicy = policyDelegate.getResponsePolicy(authContextID, properties);
            boolean noModules = true;
            for (int i = 0; i < clientModules.length; i++) {
                if (clientModules[i] != null) {
                    if (isLoggable(FINE)) {
                        logIfLevel(FINE, null, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "initializing module");
                    }
                    noModules = false;
                    checkMessageTypes(clientModules[i].getSupportedMessageTypes());
                    clientModules[i].initialize(requestPolicy, responsePolicy, callbackHandler, authContextHelper.getInitProperties(i, properties));
                }
            }
            if (noModules) {
                logIfLevel(WARNING, null, "CLientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "contains no Auth Modules");
            }
            return clientModules;
        }

        @Override
        public AuthStatus validateResponse(MessageInfo arg0, Subject arg1, Subject arg2) throws AuthException {
            AuthStatus[] status = new AuthStatus[module.length];
            for (int i = 0; i < module.length; i++) {
                if (module[i] == null) {
                    continue;
                }
                if (isLoggable(FINE)) {
                    logIfLevel(FINE, null, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "calling vaidateResponse on module");
                }
                status[i] = module[i].validateResponse(arg0, arg1, arg2);
                if (authContextHelper.exitContext(validateResponseSuccessValues, i, status[i])) {
                    return authContextHelper.getReturnStatus(validateResponseSuccessValues, SEND_FAILURE, status, i);
                }
            }
            return authContextHelper.getReturnStatus(validateResponseSuccessValues, SEND_FAILURE, status, status.length - 1);
        }

        @Override
        public AuthStatus secureRequest(MessageInfo arg0, Subject arg1) throws AuthException {
            AuthStatus[] status = new AuthStatus[module.length];
            for (int i = 0; i < module.length; i++) {
                if (module[i] == null) {
                    continue;
                }
                if (isLoggable(FINE)) {
                    logIfLevel(FINE, null, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "calling secureResponse on module");
                }
                status[i] = module[i].secureRequest(arg0, arg1);
                if (authContextHelper.exitContext(secureResponseSuccessValues, i, status[i])) {
                    return authContextHelper.getReturnStatus(secureResponseSuccessValues, AuthStatus.SEND_FAILURE, status, i);
                }
            }
            return authContextHelper.getReturnStatus(secureResponseSuccessValues, AuthStatus.SEND_FAILURE, status, status.length - 1);
        }

        @Override
        public void cleanSubject(MessageInfo arg0, Subject arg1) throws AuthException {
            for (int i = 0; i < module.length; i++) {
                if (module[i] == null) {
                    continue;
                }
                if (isLoggable(FINE)) {
                    logIfLevel(FINE, null, "ClientAuthContext: ", authContextID, "of AppContext: ", getAppContext(), "calling cleanSubject on module");
                }
                module[i].cleanSubject(arg0, arg1);
            }
        }
    };
    return (M) context;
}
Also used : MessagePolicy(javax.security.auth.message.MessagePolicy) ClientAuthModule(javax.security.auth.message.module.ClientAuthModule) AuthStatus(javax.security.auth.message.AuthStatus) AuthException(javax.security.auth.message.AuthException) ClientAuthContext(javax.security.auth.message.config.ClientAuthContext) Subject(javax.security.auth.Subject) MessageInfo(javax.security.auth.message.MessageInfo)

Example 25 with AuthException

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

the class JAASAuthContextHelper method getModules.

/**
 * this implementation does not depend on authContextID
 *
 * @param <M>
 * @param template
 * @param authContextID (ignored by this context system)
 * @return
 * @throws AuthException
 */
@Override
public <M> M[] getModules(M[] template, String authContextID) throws AuthException {
    loadConstructors(template, authContextID);
    ArrayList<M> list = new ArrayList<M>();
    for (int i = 0; i < constructors.length; i++) {
        if (constructors[i] == null) {
            list.add(i, null);
        } else {
            final int j = i;
            try {
                list.add(j, doPrivileged(new PrivilegedExceptionAction<M>() {

                    @Override
                    @SuppressWarnings("unchecked")
                    public M run() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
                        return (M) constructors[j].newInstance(ARGS);
                    }
                }));
            } catch (PrivilegedActionException pae) {
                throw (AuthException) new AuthException().initCause(pae.getCause());
            }
        }
    }
    return list.toArray(template);
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) ArrayList(java.util.ArrayList) AuthException(javax.security.auth.message.AuthException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Aggregations

AuthException (javax.security.auth.message.AuthException)40 IOException (java.io.IOException)25 HttpServletRequest (javax.servlet.http.HttpServletRequest)23 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)21 CallerPrincipalCallback (javax.security.auth.message.callback.CallerPrincipalCallback)16 Principal (java.security.Principal)15 GroupPrincipalCallback (javax.security.auth.message.callback.GroupPrincipalCallback)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)13 Callback (javax.security.auth.callback.Callback)10 Subject (javax.security.auth.Subject)7 ServerAuthContext (javax.security.auth.message.config.ServerAuthContext)7 MessageInfo (javax.security.auth.message.MessageInfo)6 AuthStatus (javax.security.auth.message.AuthStatus)5 MalformedURLException (java.net.MalformedURLException)3 PrivilegedActionException (java.security.PrivilegedActionException)3 ServerAuthConfig (javax.security.auth.message.config.ServerAuthConfig)3 ServerAuthModule (javax.security.auth.message.module.ServerAuthModule)3 HttpSession (javax.servlet.http.HttpSession)3 SecurityContext (com.sun.enterprise.security.SecurityContext)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2