Search in sources :

Example 6 with L10NMessageImpl

use of com.sun.identity.shared.locale.L10NMessageImpl in project OpenAM by OpenRock.

the class RestAuthenticationHandler method authenticate.

/**
     * Handles either the creation or retrieval of the Login Process, dependent on if the request is a new
     * authentication request or a continuation of one.
     *
     * @param request The HttpServletRequest.
     * @param response The HttpServletResponse.
     * @param postBody The post body of the request.
     * @param authIndexType The authentication index type.
     * @param indexValue The authentication index value.
     * @param sessionUpgradeSSOTokenId The SSO Token Id of the user's current session, null if not performing a session
     *                                 upgrade.
     * @return The Response of the authentication request.
     */
private JsonValue authenticate(HttpServletRequest request, HttpServletResponse response, JsonValue postBody, String authIndexType, String indexValue, String sessionUpgradeSSOTokenId) throws RestAuthException {
    LoginProcess loginProcess = null;
    try {
        AuthIndexType indexType = getAuthIndexType(authIndexType);
        String authId = null;
        String sessionId = null;
        if (postBody != null) {
            authId = getAuthId(postBody);
            if (authId != null) {
                SignedJwt jwt = authIdHelper.reconstructAuthId(authId);
                sessionId = getSessionId(jwt);
                indexType = getAuthIndexType(jwt);
                indexValue = getAuthIndexValue(jwt);
                String realmDN = getRealmDomainName(jwt);
                AuditRequestContext.putProperty(SESSION_ID, sessionId);
                authIdHelper.verifyAuthId(realmDN, authId);
            }
        }
        LoginConfiguration loginConfiguration = new LoginConfiguration().httpRequest(request).httpResponse(response).indexType(indexType).indexValue(indexValue).sessionId(sessionId).forceAuth(request.getParameter(AuthUtils.FORCE_AUTH)).sessionUpgrade(sessionUpgradeSSOTokenId);
        loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
        return processAuthentication(request, response, postBody, authId, loginProcess, loginConfiguration);
    } catch (RestAuthException e) {
        if (loginProcess != null) {
            String failureUrl = urlValidator.getRedirectUrl(loginProcess.getAuthContext().getOrgDN(), loginProcess.getFailureURL(), null);
            e.setFailureUrl(failureUrl);
        }
        throw e;
    } catch (L10NMessageImpl e) {
        throw new RestAuthException(amAuthErrorCodeResponseStatusMapping.getAuthLoginExceptionResponseStatus(e.getErrorCode()), e);
    } catch (JsonException e) {
        throw new RestAuthException(ResourceException.INTERNAL_ERROR, e);
    } catch (SignatureException e) {
        throw new RestAuthException(ResourceException.INTERNAL_ERROR, e);
    } catch (AuthLoginException e) {
        throw new RestAuthException(amAuthErrorCodeResponseStatusMapping.getAuthLoginExceptionResponseStatus(e.getErrorCode()), e);
    } catch (JwsSigningException jse) {
        DEBUG.error("JwsSigningException", jse);
        throw new RestAuthException(ResourceException.INTERNAL_ERROR, "JwsSigningException, " + jse.getMessage());
    }
}
Also used : RestAuthException(org.forgerock.openam.core.rest.authn.exceptions.RestAuthException) JsonException(org.forgerock.json.JsonException) JwsSigningException(org.forgerock.json.jose.exceptions.JwsSigningException) L10NMessageImpl(com.sun.identity.shared.locale.L10NMessageImpl) AuthIndexType(org.forgerock.openam.core.rest.authn.core.AuthIndexType) LoginConfiguration(org.forgerock.openam.core.rest.authn.core.LoginConfiguration) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SignedJwt(org.forgerock.json.jose.jws.SignedJwt) SignatureException(java.security.SignatureException) LoginProcess(org.forgerock.openam.core.rest.authn.core.LoginProcess)

Example 7 with L10NMessageImpl

use of com.sun.identity.shared.locale.L10NMessageImpl in project OpenAM by OpenRock.

the class PLLNotificationServlet method doPost.

/*
     * Accepts POST requests, reads Inpt Stream, forwards the NotificationSet
     * XML Flushes the ResponseSet XML to OutputStream @param
     * HttpServletNotification Reference to HttpServletNotification object
     * @param HttpServletResponse Reference to HttpServletResponse object
     * 
     * @see javax.servlet.http.HttpServlet
     */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
    // Check content length
    try {
        RequestUtils.checkContentLength(request);
    } catch (L10NMessageImpl e) {
        ISLocaleContext localeContext = new ISLocaleContext();
        localeContext.setLocale(request);
        java.util.Locale locale = localeContext.getLocale();
        throw new ServletException(e.getL10NMessage(locale));
    }
    int length = request.getContentLength();
    if (length == -1) {
        throw new ServletException(PLLBundle.getString("unknownLength"));
    }
    byte[] reqData = new byte[length];
    InputStream in = request.getInputStream();
    int rlength = 0;
    int offset = 0;
    while (rlength != length) {
        int r = in.read(reqData, offset, length - offset);
        if (r == -1) {
            throw new ServletException(PLLBundle.getString("readRequestError"));
        }
        rlength += r;
        offset += r;
    }
    String xml = new String(reqData, 0, length, "UTF-8");
    ServletOutputStream out = response.getOutputStream();
    try {
        try {
            handleNotification(xml);
            out.print("OK");
        } catch (ServletException e) {
            out.print("NOT OK");
        }
        out.flush();
    } finally {
        if (out != null) {
            out.close();
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) ServletOutputStream(javax.servlet.ServletOutputStream) L10NMessageImpl(com.sun.identity.shared.locale.L10NMessageImpl) InputStream(java.io.InputStream) ISLocaleContext(com.sun.identity.common.ISLocaleContext)

Example 8 with L10NMessageImpl

use of com.sun.identity.shared.locale.L10NMessageImpl in project OpenAM by OpenRock.

the class AuthContext method getSSOToken.

/**
     * Returns the Single-Sign-On (SSO) Token for the authenticated
     * user. If the user has not successfully authenticated
     * <code>Exception</code> will be thrown.
     * <p>
     * Single sign token can be used as the authenticated token.
     *
     * @return Single-Sign-On token for the valid user after successful
     *         authentication.
     * @throws L10NMessageImpl if the user is not authenticated or an error is
     *         encountered in retrieving the user's single sign on token.
     * @supported.api
     */
public SSOToken getSSOToken() throws L10NMessageImpl {
    if (localFlag) {
        if (!acLocal.getStatus().equals(Status.SUCCESS)) {
            throw new L10NMessageImpl(amAuthContext, "statusNotSuccess", null);
        }
        return (acLocal.getSSOToken());
    } else {
        // Get the loginStatus node
        if (!loginStatus.equals(Status.SUCCESS)) {
            throw new L10NMessageImpl(amAuthContext, "statusNotSuccess", null);
        }
        Node loginStatusNode = XMLUtils.getRootNode(receivedDocument, AuthXMLTags.LOGIN_STATUS);
        if (loginStatusNode == null) {
            throw new L10NMessageImpl(amAuthContext, "noStatusNode", null);
        }
        String ssoTokenIDTmp = XMLUtils.getNodeAttributeValue(loginStatusNode, AuthXMLTags.SSOTOKEN);
        try {
            return new com.iplanet.sso.providers.dpro.SSOProviderImpl().createSSOToken(ssoTokenIDTmp, true);
        } catch (SSOException ssoe) {
            throw new L10NMessageImpl(amAuthContext, "createSSOTokenError", null);
        }
    }
}
Also used : L10NMessageImpl(com.sun.identity.shared.locale.L10NMessageImpl) Node(org.w3c.dom.Node) SSOException(com.iplanet.sso.SSOException)

Example 9 with L10NMessageImpl

use of com.sun.identity.shared.locale.L10NMessageImpl in project OpenAM by OpenRock.

the class AuthContext method processRequest.

protected Document processRequest(String xmlRequest) throws AuthLoginException {
    Document doc = null;
    try {
        Request request = new Request(xmlRequest);
        RequestSet set = new RequestSet(AuthXMLTags.AUTH_SERVICE);
        set.addRequest(request);
        URL url = authServiceURL;
        if (url.getProtocol().equals("https") && (nickName != null)) {
            Class[] paramtype = { String.class };
            Object[] param = { nickName };
            String protHandler = protHandlerPkg + ".https.Handler";
            Constructor construct = Class.forName(protHandler).getConstructor(paramtype);
            URLStreamHandler handler = (URLStreamHandler) construct.newInstance(param);
            url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile(), handler);
        }
        if (authDebug.messageEnabled()) {
            authDebug.message("Service URL : " + url.toString());
        }
        Vector responses = PLLClient.send(url, set, cookieTable);
        if ((responses.isEmpty()) || (responses.size() != 1)) {
            throw new L10NMessageImpl(amAuthContext, "responseError", null);
        }
        Response res = (Response) responses.elementAt(0);
        String responseStr = (String) res.getContent();
        doc = XMLUtils.getXMLDocument(new ByteArrayInputStream(responseStr.getBytes("UTF-8")));
    } catch (Exception e) {
        authDebug.message("error in getting service url", e);
        throw new AuthLoginException(amAuthContext, "xmlProcessError", null, e);
    }
    return (doc);
}
Also used : Constructor(java.lang.reflect.Constructor) L10NMessageImpl(com.sun.identity.shared.locale.L10NMessageImpl) Request(com.iplanet.services.comm.share.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) RemoteHttpServletRequest(org.forgerock.openam.authentication.service.protocol.RemoteHttpServletRequest) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) Document(org.w3c.dom.Document) URL(java.net.URL) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) AMSecurityPropertiesException(com.sun.identity.security.AMSecurityPropertiesException) IOException(java.io.IOException) AuthException(com.sun.identity.authentication.service.AuthException) URLStreamHandler(java.net.URLStreamHandler) RemoteHttpServletResponse(org.forgerock.openam.authentication.service.protocol.RemoteHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(com.iplanet.services.comm.share.Response) RequestSet(com.iplanet.services.comm.share.RequestSet) ByteArrayInputStream(java.io.ByteArrayInputStream) Vector(java.util.Vector)

Example 10 with L10NMessageImpl

use of com.sun.identity.shared.locale.L10NMessageImpl in project OpenAM by OpenRock.

the class Gateway method doPost.

/**
     * Performs the HTTP POST operation. 
     */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // Obtain goto URL and check if there are auth parameters
    String authScheme = null;
    String authLevel = null;
    String gotoUrl = null;
    ActionDecision ad = null;
    Map advices = null;
    String orgName = null;
    // Check content length
    try {
        RequestUtils.checkContentLength(request);
    } catch (L10NMessageImpl e) {
        ISLocaleContext localeContext = new ISLocaleContext();
        localeContext.setLocale(request);
        java.util.Locale locale = localeContext.getLocale();
        if (debug.messageEnabled()) {
            debug.message("GatewayServlet: " + e.getL10NMessage(locale));
        }
        throw new ServletException(e.getL10NMessage(locale));
    }
    // Construct the default forwarding URL
    StringBuilder forwardUrl = new StringBuilder(200);
    forwardUrl.append(LOGIN_URL);
    String queryString = request.getQueryString();
    Enumeration paramNames = request.getParameterNames();
    while ((queryString != null) && paramNames.hasMoreElements()) {
        String key = (String) paramNames.nextElement();
        if (key.equalsIgnoreCase(GOTO_URL)) {
            gotoUrl = request.getParameter(key);
        } else if (key.equalsIgnoreCase(AUTH_SCHEME)) {
            authScheme = request.getParameter(key);
        } else if (key.equalsIgnoreCase(AUTH_LEVEL)) {
            authLevel = request.getParameter(key);
        }
    }
    if (debug.messageEnabled()) {
        debug.message("GatewayServlet: queryString : " + queryString);
        debug.message("GatewayServlet: gotoUrl : " + gotoUrl);
    }
    if (gotoUrl != null) {
        ad = getActionDecision(gotoUrl);
        if (ad != null) {
            advices = ad.getAdvices();
            orgName = getOrgNameFromAdvice(advices);
        }
    }
    AuthServiceConfigInfo info = null;
    // Construct the forward URL
    if ((gotoUrl != null) && ((authScheme == null) && (authLevel == null))) {
        if (debug.messageEnabled()) {
            debug.message("GatewayServlet: gotoUrl : " + gotoUrl);
        }
        // we have only goto URL, hence find from policy if there are
        // any advices on authentication modules
        forwardUrl.append('?').append(queryString);
        String advice = getPolicyAdvice(ad);
        info = getGWServletUtilsFromMap(advices);
        if (advice != null) {
            StringBuffer adv = new StringBuffer();
            int index1 = advice.indexOf("=");
            if (index1 != -1) {
                adv = adv.append(advice.substring(0, index1 + 1));
                int index2 = advice.indexOf(":");
                if (index2 != -1) {
                    orgName = advice.substring(index1 + 1, index2);
                    adv = adv.append(advice.substring(index2 + 1));
                    advice = adv.toString();
                }
            }
        }
        if (debug.messageEnabled()) {
            debug.message("GatewayServlet: advice from getPolicyAdvice(): " + advice);
        }
        if (advice != null && advice.length() > 0) {
            forwardUrl.append('&').append(advice);
        }
    } else if ((authScheme != null) || (authLevel != null)) {
        // Either query string contains goto url & auth parameters
        // which could be auth level or module, or no goto url
        forwardUrl.append('?').append(queryString);
        if (authScheme != null) {
            info = getGWServletUtilsByScheme(orgName, authScheme);
        } else if (authLevel != null) {
            info = getGWServletUtilsByLevel(orgName, authLevel);
        }
    }
    // If module is Cert, redirect to Cert module URL
    String fUrl = forwardUrl.toString();
    if (debug.messageEnabled()) {
        debug.message("GatewayServlet >>> Need to change URL !");
        debug.message("OLD URL : " + fUrl);
    }
    if ((info != null) && (info.getPortNumber() != null)) {
        fUrl = CERT_PROTOCOL + request.getServerName() + ":" + info.getPortNumber() + SystemProperties.get(AuthXMLTags.SERVER_DEPLOY_URI) + fUrl;
        if ((orgName != null) && (fUrl.indexOf("org=") == -1)) {
            fUrl = fUrl + "&" + ORG_NAME + "=" + DNtoName(orgName);
        }
        response.sendRedirect(fUrl);
    } else {
        // Forward the request to Login servlet
        if ((orgName != null) && (fUrl.indexOf("org=") == -1)) {
            fUrl = fUrl + "&" + ORG_NAME + "=" + DNtoName(orgName);
        }
        // Forward the request to Login servlet
        RequestDispatcher dispatcher = config.getServletContext().getRequestDispatcher(fUrl);
        dispatcher.forward(request, response);
    }
    if (debug.messageEnabled()) {
        debug.message("New URL : " + fUrl);
    }
}
Also used : Enumeration(java.util.Enumeration) L10NMessageImpl(com.sun.identity.shared.locale.L10NMessageImpl) ActionDecision(com.sun.identity.policy.ActionDecision) RequestDispatcher(javax.servlet.RequestDispatcher) ServletException(javax.servlet.ServletException) ISLocaleContext(com.sun.identity.common.ISLocaleContext) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

L10NMessageImpl (com.sun.identity.shared.locale.L10NMessageImpl)11 SSOException (com.iplanet.sso.SSOException)4 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)4 ISLocaleContext (com.sun.identity.common.ISLocaleContext)4 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 ModelControlException (com.iplanet.jato.model.ModelControlException)2 HttpCallback (com.sun.identity.authentication.spi.HttpCallback)2 RedirectCallback (com.sun.identity.authentication.spi.RedirectCallback)2 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)2 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)2 NameCallback (javax.security.auth.callback.NameCallback)2 PasswordCallback (javax.security.auth.callback.PasswordCallback)2 RequestDispatcher (javax.servlet.RequestDispatcher)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 SessionID (com.iplanet.dpro.session.SessionID)1 InternalSession (com.iplanet.dpro.session.service.InternalSession)1 CompleteRequestException (com.iplanet.jato.CompleteRequestException)1 RequestContextImpl (com.iplanet.jato.RequestContextImpl)1