Search in sources :

Example 1 with ResponseSet

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

the class PolicyRequestHandler method process.

/**
     *  Process the requests aÎnd return the responses.
     *
     *  @param requests Requests specified in the policy request
     *  @return the set of the response
     */
public ResponseSet process(PLLAuditor auditor, List<Request> requests, HttpServletRequest servletRequest, HttpServletResponse servletResponse, ServletContext servletContext) {
    ResponseSet resSet = new ResponseSet(PolicyService.POLICY_SERVICE);
    int size = requests.size();
    auditor.setComponent(POLICY);
    for (Request req : requests) {
        Response res = null;
        try {
            res = processRequest(req, auditor);
        } catch (PolicyEvaluationException pe) {
            if (debug.messageEnabled()) {
                debug.message("PolicyRequesthandler.process" + " caught PolicyEvaluationException:", pe);
            }
            PolicyService ps = new PolicyService();
            try {
                String rev = getPolicyServiceRevision();
                ps.setRevision(rev);
            } catch (PolicyEvaluationException pee) {
                debug.error("PolicyRequesthandler.process" + " can not get service revision number, " + ",revision defaulting to :" + PolicyService.ON_ERROR_REVISION_NUMBER, pee);
                ps.setRevision(PolicyService.ON_ERROR_REVISION_NUMBER);
            }
            PolicyResponse pRes = new PolicyResponse();
            pRes.setMethodID(PolicyResponse.POLICY_EXCEPTION);
            pRes.setRequestId(pe.getRequestId());
            pRes.setExceptionMsg(pe.getMessage());
            pRes.setIssueInstant(System.currentTimeMillis());
            ps.setMethodID(PolicyService.POLICY_RESPONSE_ID);
            ps.setPolicyResponse(pRes);
            res = new Response(ps.toXMLString());
            auditor.auditAccessFailure(pe.getMessage());
        }
        if (res != null) {
            resSet.addResponse(res);
        }
    }
    return resSet;
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(com.iplanet.services.comm.share.Response) Request(com.iplanet.services.comm.share.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) ResponseSet(com.iplanet.services.comm.share.ResponseSet)

Example 2 with ResponseSet

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

the class PLLClient method send.

// The private method that implements the above interfaces.
// HashMap cookieTable passes in the cookies that will be replayed. It also
// is the place holder to retrieve additional cookies if any from the
// URL connection response.
private static Vector send(URL url, String cookies, RequestSet set, HashMap cookieTable) throws SendRequestException {
    HttpURLConnection conn = null;
    OutputStream out = null;
    BufferedReader in = null;
    try {
        if ((SiteMonitor.keepMonitoring == true) && !SiteMonitor.isAvailable(url)) {
            debug.error("Site " + url.toString() + " is down.");
            throw new SendRequestException("Site is down.");
        }
        conn = HttpURLConnectionManager.getConnection(url);
        conn.setDoOutput(true);
        conn.setUseCaches(useCache);
        conn.setRequestMethod("POST");
        // replay cookies
        StringBuffer cookieStr = null;
        if (cookies != null) {
            cookieStr = new StringBuffer();
            cookieStr.append(cookies);
        }
        if (cookieTable != null && !cookieTable.isEmpty()) {
            for (Iterator it = cookieTable.values().iterator(); it.hasNext(); ) {
                Cookie cookie = (Cookie) it.next();
                if (cookieStr == null) {
                    cookieStr = new StringBuffer();
                } else {
                    cookieStr.append(";");
                }
                cookieStr.append(cookie.getName()).append("=").append(cookie.getValue());
            }
        }
        if (cookieStr != null) {
            cookies = cookieStr.toString();
            if (debug.messageEnabled()) {
                debug.message("sending cookies: " + cookies);
            }
            conn.setRequestProperty("Cookie", cookies);
        }
        conn.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
        conn.setRequestProperty(TransactionIdHeader.NAME, AuditRequestContext.createSubTransactionIdValue());
        // Output ...
        String xml = set.toXMLString();
        // compute and set length, just in case iWS set arbitrary length
        int requestLength = xml.getBytes("UTF-8").length;
        conn.setRequestProperty("Content-Length", Integer.toString(requestLength));
        out = conn.getOutputStream();
        out.write(xml.getBytes("UTF-8"));
        out.flush();
        // Input ...
        in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
        StringBuilder in_buf = new StringBuilder();
        int len;
        char[] buf = new char[1024];
        while ((len = in.read(buf, 0, buf.length)) != -1) {
            in_buf.append(buf, 0, len);
        }
        String in_string = in_buf.toString();
        // retrieves cookies from the response
        Map headers = conn.getHeaderFields();
        if (cookieTable != null) {
            parseCookies(headers, cookieTable);
        }
        ResponseSet resset = ResponseSet.parseXML(in_string);
        return resset.getResponses();
    } catch (Exception e) {
        debug.warning("PLLClient.send: exception: ", e);
        throw new SendRequestException(e.getMessage());
    } finally {
        IOUtils.closeIfNotNull(out);
        IOUtils.closeIfNotNull(in);
        if (conn != null) {
            // to allow connection re-use when an IOException occurs, the
            // error stream should be read and then closed.
            InputStream errorStream = conn.getErrorStream();
            if (errorStream != null) {
                try {
                    debug.warning("Error stream content is " + IOUtils.readStream(errorStream));
                } catch (IOException ioe) {
                    debug.warning("Error while reading the error stream", ioe);
                }
            }
        }
    }
}
Also used : Cookie(javax.servlet.http.Cookie) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ResponseSet(com.iplanet.services.comm.share.ResponseSet) IOException(java.io.IOException) IOException(java.io.IOException) HttpURLConnection(java.net.HttpURLConnection) BufferedReader(java.io.BufferedReader) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ResponseSet

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

the class LogService method process.

/**
     * The method which accepts the request set, parses the xml request and
     * executes the appropriate log operation.
     * @param requests
     * @param servletRequest
     * @param servletResponse
     * @return The response set which contains the result of the log operation.
     */
public ResponseSet process(PLLAuditor auditor, List<Request> requests, HttpServletRequest servletRequest, HttpServletResponse servletResponse, ServletContext servletContext) {
    if (Debug.messageEnabled()) {
        Debug.message("LogService.process() called :requests are");
        for (Request req : requests) {
            Debug.message("xml = " + req.getContent());
        }
    }
    ResponseSet rset = new ResponseSet(LOG_SERVICE);
    for (Request req : requests) {
        // remember sid string is the last item in the log tag
        String xmlRequestString = req.getContent();
        Response res;
        if ((xmlRequestString == null) || xmlRequestString.equals("null")) {
            Debug.error("Received a null log request");
            res = new Response("NULL_LOG_REQUEST");
            rset.addResponse(res);
        } else {
            int l = xmlRequestString.length();
            int sidi = xmlRequestString.indexOf("sid=");
            int sidj = xmlRequestString.indexOf("</log");
            loggedBySid = xmlRequestString.substring((sidi + 5), (sidj - 2));
            try {
                //NOTE source ip address restrictions are temporary kludge
                // for 6.1 session hijacking hotpatch
                InetAddress remoteClient = SessionUtils.getClientAddress(servletRequest);
                SSOToken ssoToken = RestrictedTokenHelper.resolveRestrictedToken(loggedBySid, remoteClient);
                SSOTokenManager ssom = SSOTokenManager.getInstance();
                if (!ssom.isValidToken(ssoToken)) {
                    String loggedByID = ssoToken.getPrincipal().getName();
                    Debug.error("LogService::process(): access denied for" + " user :" + loggedByID);
                    res = new Response("UNAUTHORIZED");
                    rset.addResponse(res);
                    return rset;
                }
            } catch (SSOException e) {
                Debug.error("LogService::process(): SSOException", e);
                res = new Response("UNAUTHORIZED");
                rset.addResponse(res);
                return rset;
            } catch (Exception e) {
                Debug.error("LogService::process(): ", e);
                res = new Response("ERROR");
                rset.addResponse(res);
            }
            try {
                ByteArrayInputStream bin = new ByteArrayInputStream(xmlRequestString.getBytes("UTF-8"));
                LogOperation op = (LogOperation) parser.parse(bin);
                res = op.execute(auditEventPublisher, auditEventFactory);
            } catch (Exception e) {
                Debug.error("LogService::process():", e);
                // FORMAT ERROR RESPONSE HERE
                res = new Response("ERROR");
                if (MonitoringUtil.isRunning()) {
                    SsoServerLoggingSvcImpl slsi = Agent.getLoggingSvcMBean();
                    SsoServerLoggingHdlrEntryImpl slei = slsi.getHandler(SsoServerLoggingSvcImpl.REMOTE_HANDLER_NAME);
                    slei.incHandlerFailureCount(1);
                }
            }
            rset.addResponse(res);
        }
    }
    return rset;
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) SSOToken(com.iplanet.sso.SSOToken) Request(com.iplanet.services.comm.share.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) ResponseSet(com.iplanet.services.comm.share.ResponseSet) SSOException(com.iplanet.sso.SSOException) SSOException(com.iplanet.sso.SSOException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(com.iplanet.services.comm.share.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) InetAddress(java.net.InetAddress) SsoServerLoggingSvcImpl(com.sun.identity.monitoring.SsoServerLoggingSvcImpl) SsoServerLoggingHdlrEntryImpl(com.sun.identity.monitoring.SsoServerLoggingHdlrEntryImpl)

Example 4 with ResponseSet

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

the class PLLRequestServlet method handleRequest.

/*
     * handleRequest() used by doPost method. Gets the corresponding service
     * handler and obtains ResponseSet from it.
     * 
     * @param String XML RequestSet String - Conforming to RequestSet.dtd @param
     * req HttpServletRequest object @param res HttpServletResponse object
     * @return String XML ResponseSet String - Conforming to ResponseSet.dtd
     * 
     * @see sunir.share.profile.service.server.http.RequestProcessor
     */
private String handleRequest(PLLAuditor auditor, RequestSet set, HttpServletRequest req, HttpServletResponse res) throws ServletException {
    if (!isValid(set)) {
        throw servletException("invalidRequestSet");
    }
    String svcid = set.getServiceID();
    RequestHandler handler = getServiceHandler(svcid);
    if (handler == null) {
        throw servletException("noRequestHandler");
    }
    ResponseSet rset = handler.process(auditor, set.getRequests(), req, res, getServletConfig().getServletContext());
    rset.setRequestSetID(set.getRequestSetID());
    return rset.toXMLString();
}
Also used : ResponseSet(com.iplanet.services.comm.share.ResponseSet)

Example 5 with ResponseSet

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

the class NamingService method process.

public ResponseSet process(PLLAuditor auditor, List<Request> requests, HttpServletRequest servletRequest, HttpServletResponse servletResponse, ServletContext servletContext) {
    ResponseSet rset = new ResponseSet(NAMING_SERVICE_PACKAGE);
    for (Request req : requests) {
        Response res = processRequest(req);
        rset.addResponse(res);
    }
    return rset;
}
Also used : NamingResponse(com.iplanet.services.naming.share.NamingResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(com.iplanet.services.comm.share.Response) Request(com.iplanet.services.comm.share.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) NamingRequest(com.iplanet.services.naming.share.NamingRequest) ResponseSet(com.iplanet.services.comm.share.ResponseSet)

Aggregations

ResponseSet (com.iplanet.services.comm.share.ResponseSet)7 Request (com.iplanet.services.comm.share.Request)5 Response (com.iplanet.services.comm.share.Response)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 SessionRequest (com.iplanet.dpro.session.share.SessionRequest)1 SessionResponse (com.iplanet.dpro.session.share.SessionResponse)1 NamingRequest (com.iplanet.services.naming.share.NamingRequest)1 NamingResponse (com.iplanet.services.naming.share.NamingResponse)1 SSOException (com.iplanet.sso.SSOException)1 SSOToken (com.iplanet.sso.SSOToken)1 SSOTokenManager (com.iplanet.sso.SSOTokenManager)1 SsoServerLoggingHdlrEntryImpl (com.sun.identity.monitoring.SsoServerLoggingHdlrEntryImpl)1 SsoServerLoggingSvcImpl (com.sun.identity.monitoring.SsoServerLoggingSvcImpl)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1