Search in sources :

Example 1 with RequestSet

use of com.iplanet.services.comm.share.RequestSet in project OpenAM by OpenRock.

the class PLLRequestServlet method doPost.

/*
     * doPost() Accepts POST requests, reads Inpt Stream, forwards the
     * RequestSet XML Flushes the ResponseSet XML to OutputStream @param
     * HttpServletRequest Reference to HttpServletRequest object @param
     * HttpServletResponse Reference to HttpServletResponse object
     * 
     * @see javax.servlet.http.HttpServlet
     */
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException {
    PLLAuditor auditor = newAuditor(req);
    try {
        int length = req.getContentLength();
        if (length == -1) {
            PLLServer.pllDebug.warning(PLLBundle.getString("unknownLength"));
            throw servletException("unknownLength");
        }
        if (length > maxContentLength) {
            PLLServer.pllDebug.error("content length exceeded configured max request size - " + length);
            throw servletException("largeContentLength");
        }
        byte[] reqData = new byte[length];
        InputStream in = req.getInputStream();
        int rlength = 0;
        int offset = 0;
        while (rlength != length) {
            int r = in.read(reqData, offset, length - offset);
            if (r == -1) {
                throw servletException("readRequestError");
            }
            rlength += r;
            offset += r;
        }
        String xml = new String(reqData, 0, length, "UTF-8");
        RequestSet set = RequestSet.parseXML(xml);
        String svcid = set.getServiceID();
        if (!AUTH_SVC_ID.equalsIgnoreCase(svcid)) {
            if (PLLServer.pllDebug.messageEnabled()) {
                PLLServer.pllDebug.message("\nReceived RequestSet XML :\n" + xml);
            }
        }
        String responseXML = handleRequest(auditor, set, req, res);
        res.setContentLength(responseXML.getBytes("UTF-8").length);
        OutputStreamWriter out = new OutputStreamWriter(res.getOutputStream(), "UTF-8");
        try {
            out.write(responseXML);
            out.flush();
        } catch (IOException e) {
            throw e;
        } finally {
            try {
                out.close();
            } catch (Exception ex) {
            }
        }
    } catch (IOException | ServletException | RuntimeException e) {
        auditor.auditAccessFailure(e.getMessage());
        throw e;
    }
}
Also used : ServletException(javax.servlet.ServletException) RequestSet(com.iplanet.services.comm.share.RequestSet) InputStream(java.io.InputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 2 with RequestSet

use of com.iplanet.services.comm.share.RequestSet in project OpenAM by OpenRock.

the class ResourceResultCache method sendPLLRequest.

/**
     * Return a PolicyService object based on the XML document received
     * from remote Policy Server. This is in response to a request that we
     * send to the Policy server.
     * @param policyServiceUrl The URL of the Policy Service
     * @param preq The SessionRequest XML document
     * @return PolicyService 
     * @exception SendRequestException is thrown if there was an error in
     * sending the XML document or PolicyException if there are any parsing
     * errors.     
     */
public static PolicyService sendPLLRequest(URL policyServiceUrl, PolicyRequest preq) throws SendRequestException, PolicyException {
    String lbcookie = null;
    try {
        lbcookie = getLBCookie(preq);
    } catch (Exception e) {
        throw new SendRequestException(e);
    }
    PolicyService policyService = new PolicyService();
    policyService.setMethodID(PolicyService.POLICY_REQUEST_ID);
    policyService.setPolicyRequest(preq);
    String xmlString = policyService.toXMLString();
    Request request = new Request(xmlString);
    RequestSet requestSet = new RequestSet(PolicyService.POLICY_SERVICE);
    requestSet.addRequest(request);
    if (debug.messageEnabled()) {
        debug.message("ResourceResultCache.sendPLLRequest:" + "sending PLL request to URL=" + policyServiceUrl + ":\nPLL message=" + xmlString);
    }
    Vector responses = PLLClient.send(policyServiceUrl, lbcookie, requestSet);
    Response response = (Response) responses.elementAt(0);
    PolicyService ps = PolicyService.parseXML(response.getContent());
    if (debug.messageEnabled()) {
        debug.message("ResourceResultCache.sendPLLRequest:" + "result=" + ps.toXMLString());
    }
    return ps;
}
Also used : SendRequestException(com.iplanet.services.comm.client.SendRequestException) AdvicesHandleableByAMResponse(com.sun.identity.policy.remote.AdvicesHandleableByAMResponse) PolicyResponse(com.sun.identity.policy.remote.PolicyResponse) Response(com.iplanet.services.comm.share.Response) RequestSet(com.iplanet.services.comm.share.RequestSet) PolicyService(com.sun.identity.policy.remote.PolicyService) PolicyListenerRequest(com.sun.identity.policy.remote.PolicyListenerRequest) Request(com.iplanet.services.comm.share.Request) ResourceResultRequest(com.sun.identity.policy.remote.ResourceResultRequest) RemoveListenerRequest(com.sun.identity.policy.remote.RemoveListenerRequest) AdvicesHandleableByAMRequest(com.sun.identity.policy.remote.AdvicesHandleableByAMRequest) PolicyRequest(com.sun.identity.policy.remote.PolicyRequest) Vector(java.util.Vector) JSONException(org.json.JSONException) PolicyException(com.sun.identity.policy.PolicyException) SendRequestException(com.iplanet.services.comm.client.SendRequestException) PolicyEvaluationException(com.sun.identity.policy.remote.PolicyEvaluationException) URLNotFoundException(com.iplanet.services.naming.URLNotFoundException) SSOException(com.iplanet.sso.SSOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AlreadyRegisteredException(com.iplanet.services.comm.client.AlreadyRegisteredException) IOException(java.io.IOException) SessionException(com.iplanet.dpro.session.SessionException)

Example 3 with RequestSet

use of com.iplanet.services.comm.share.RequestSet in project OpenAM by OpenRock.

the class SessionPLLSender method sendPLLRequest.

/**
     * Returns a Session Response object based on the XML document received from
     * remote Session Server. This is in response to a request that we send to
     * the session server.
     *
     * @param svcurl The URL of the Session Service.
     * @param sreq The Session Request XML document.
     * @return a Vector of responses from the remote server
     * @exception com.iplanet.dpro.session.SessionException if there was an error in sending the XML
     *            document or if the response has multiple components.
     */
public SessionResponse sendPLLRequest(URL svcurl, SessionRequest sreq) throws SessionException {
    try {
        String cookies = sessionCookies.getCookieName() + "=" + sreq.getSessionID();
        if (!SystemProperties.isServerMode()) {
            SessionID sessionID = new SessionID(sreq.getSessionID());
            cookies = cookies + ";" + sessionCookies.getLBCookie(sessionID);
        }
        final Request req = new Request(sreq.toXMLString());
        final RequestSet set = new RequestSet(SESSION_SERVICE);
        set.addRequest(req);
        final Vector responses = PLLClient.send(svcurl, cookies, set);
        if (responses.size() != 1) {
            throw new SessionException(SessionBundle.rbName, "unexpectedResponse", null);
        }
        final Response res = (Response) responses.elementAt(0);
        return SessionResponse.parseXML(res.getContent());
    } catch (Exception e) {
        throw new SessionException(e);
    }
}
Also used : Response(com.iplanet.services.comm.share.Response) SessionResponse(com.iplanet.dpro.session.share.SessionResponse) RequestSet(com.iplanet.services.comm.share.RequestSet) SessionRequest(com.iplanet.dpro.session.share.SessionRequest) Request(com.iplanet.services.comm.share.Request) SessionException(com.iplanet.dpro.session.SessionException) SessionID(com.iplanet.dpro.session.SessionID) Vector(java.util.Vector) SessionException(com.iplanet.dpro.session.SessionException)

Example 4 with RequestSet

use of com.iplanet.services.comm.share.RequestSet in project OpenAM by OpenRock.

the class WebtopNaming method getNamingTable.

private static Hashtable getNamingTable(URL nameurl) throws Exception {
    Hashtable nametbl = null;
    NamingRequest nrequest = new NamingRequest(NamingRequest.reqVersion);
    Request request = new Request(nrequest.toXMLString());
    RequestSet set = new RequestSet(NAMING_SERVICE);
    set.addRequest(request);
    Vector responses = null;
    try {
        responses = PLLClient.send(nameurl, set);
        if (responses.size() != 1) {
            throw new Exception(NamingBundle.getString("unexpectedResponse"));
        }
        Response res = (Response) responses.elementAt(0);
        NamingResponse nres = NamingResponse.parseXML(res.getContent());
        if (nres.getException() != null) {
            throw new Exception(nres.getException());
        }
        nametbl = nres.getNamingTable();
    } catch (SendRequestException sre) {
        debug.error("Naming service connection failed for " + nameurl, sre);
    } catch (Exception e) {
        debug.error("getNamingTable: ", e);
    }
    return nametbl;
}
Also used : NamingResponse(com.iplanet.services.naming.share.NamingResponse) Response(com.iplanet.services.comm.share.Response) SendRequestException(com.iplanet.services.comm.client.SendRequestException) NamingRequest(com.iplanet.services.naming.share.NamingRequest) RequestSet(com.iplanet.services.comm.share.RequestSet) Hashtable(java.util.Hashtable) Request(com.iplanet.services.comm.share.Request) NamingRequest(com.iplanet.services.naming.share.NamingRequest) NamingResponse(com.iplanet.services.naming.share.NamingResponse) Vector(java.util.Vector) SendRequestException(com.iplanet.services.comm.client.SendRequestException) MalformedURLException(java.net.MalformedURLException)

Example 5 with RequestSet

use of com.iplanet.services.comm.share.RequestSet in project OpenAM by OpenRock.

the class AuthXMLHandler method processRequest.

/* process the request */
private Response processRequest(PLLAuditor auditor, Request req, HttpServletRequest servletReq, HttpServletResponse servletRes) {
    // this call is to create a http session so that the JSESSIONID cookie
    // is created. The appserver(8.1) load balancer plugin relies on the
    // JSESSIONID cookie to set its JROUTE sticky cookie.
    debug.message("=======================Entering processRequest");
    servletReq.getSession(true);
    String content = req.getContent();
    AuthXMLResponse authResponse = null;
    // Check for mis-routed requests
    String cookieURL = null;
    int index = content.indexOf(AuthXMLTags.AUTH_ID_HANDLE);
    if (index != -1) {
        // Check for mis-routed requests, get server URL for
        // AuthIdentifier
        int beginIndex = content.indexOf('"', index);
        int endIndex = content.indexOf('"', beginIndex + 1);
        String authIdentifier = content.substring(beginIndex + 1, endIndex);
        if (debug.messageEnabled()) {
            debug.message("authIdentifier = " + authIdentifier + "beginIndex = " + beginIndex + "endIndex =" + endIndex);
        }
        if (!authIdentifier.equals("0")) {
            try {
                SessionID sessionID = new SessionID(authIdentifier);
                URL sessionServerURL = SESSION_SERVICE_URL_SERVICE.getSessionServiceURL(sessionID);
                StringBuilder srtBuff = new StringBuilder(100);
                srtBuff.append(sessionServerURL.getProtocol()).append("://").append(sessionServerURL.getHost()).append(":").append(Integer.toString(sessionServerURL.getPort())).append(serviceURI);
                cookieURL = srtBuff.toString();
            } catch (Exception exp) {
                debug.error("Error in getting URL from session", exp);
                cookieURL = null;
            }
        }
    }
    if ((cookieURL != null) && (cookieURL.trim().length() != 0) && !(AuthUtils.isLocalServer(cookieURL, serviceURI))) {
        // Routing to the correct server, the looks like a mis-routed 
        // requested.
        HashMap cookieTable = new HashMap();
        Map headers = new HashMap();
        Enumeration headerNames = servletReq.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String headerName = (String) headerNames.nextElement();
            List headerValues = new ArrayList();
            Enumeration enum1 = servletReq.getHeaders(headerName);
            while (enum1.hasMoreElements()) {
                headerValues.add(enum1.nextElement());
            }
            headers.put(headerName, headerValues);
        }
        if (debug.messageEnabled()) {
            debug.message("Headers: " + headers);
        }
        PLLClient.parseCookies(headers, cookieTable);
        if (debug.messageEnabled()) {
            debug.message("Cookies: " + cookieTable);
        }
        RequestSet set = new RequestSet(AuthXMLTags.AUTH_SERVICE);
        set.addRequest(req);
        try {
            Vector responses = PLLClient.send(new URL(cookieURL), set, cookieTable);
            if (!responses.isEmpty()) {
                auditor.auditAccessAttempt();
                // Just record result as success here to avoid parsing response
                auditor.auditAccessSuccess();
                debug.message("=====================Returning redirected");
                return ((Response) responses.elementAt(0));
            }
        } catch (Exception e) {
            debug.error("Error in misrouted ", e);
            // Attempt to contact server failed
            authResponse = new AuthXMLResponse(AuthXMLRequest.NewAuthContext);
            setErrorCode(authResponse, e);
            auditor.auditAccessAttempt();
            auditor.auditAccessFailure(authResponse.errorCode, authResponse.authErrorMessage);
            return new Response(authResponse.toXMLString());
        }
    }
    // Either local request or new request, handle it locally
    try {
        AuthXMLRequest sreq = AuthXMLRequest.parseXML(content, servletReq);
        sreq.setHttpServletRequest(servletReq);
        authResponse = processAuthXMLRequest(content, auditor, sreq, servletReq, servletRes);
    } catch (AuthException e) {
        debug.error("Got Auth Exception", e);
        authResponse = new AuthXMLResponse(AuthXMLRequest.NewAuthContext);
        authResponse.setErrorCode(e.getErrorCode());
    } catch (Exception ex) {
        debug.error("Error while processing xml request", ex);
        authResponse = new AuthXMLResponse(AuthXMLRequest.NewAuthContext);
        setErrorCode(authResponse, ex);
    }
    debug.message("=======================Returning");
    if (authResponse.isException) {
        auditor.auditAccessFailure(authResponse.errorCode, authResponse.authErrorMessage);
    } else {
        auditor.auditAccessSuccess();
    }
    return new Response(authResponse.toXMLString());
}
Also used : Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AuthException(com.sun.identity.authentication.service.AuthException) URL(java.net.URL) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) AuthException(com.sun.identity.authentication.service.AuthException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(com.iplanet.services.comm.share.Response) RequestSet(com.iplanet.services.comm.share.RequestSet) List(java.util.List) ArrayList(java.util.ArrayList) SessionID(com.iplanet.dpro.session.SessionID) Map(java.util.Map) HashMap(java.util.HashMap) Vector(java.util.Vector)

Aggregations

RequestSet (com.iplanet.services.comm.share.RequestSet)8 Response (com.iplanet.services.comm.share.Response)6 Vector (java.util.Vector)6 Request (com.iplanet.services.comm.share.Request)5 SSOException (com.iplanet.sso.SSOException)3 IOException (java.io.IOException)3 URL (java.net.URL)3 HashMap (java.util.HashMap)3 SessionException (com.iplanet.dpro.session.SessionException)2 SessionID (com.iplanet.dpro.session.SessionID)2 SendRequestException (com.iplanet.services.comm.client.SendRequestException)2 URLNotFoundException (com.iplanet.services.naming.URLNotFoundException)2 AuthException (com.sun.identity.authentication.service.AuthException)2 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)2 MalformedURLException (java.net.MalformedURLException)2 Map (java.util.Map)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 ThreadPoolException (com.iplanet.am.util.ThreadPoolException)1 SessionRequest (com.iplanet.dpro.session.share.SessionRequest)1 SessionResponse (com.iplanet.dpro.session.share.SessionResponse)1