Search in sources :

Example 6 with Response

use of com.iplanet.services.comm.share.Response 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 7 with Response

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

the class SessionRequestHandler method processRequest.

private Response processRequest(final PLLAuditor auditor, final Request req, final HttpServletRequest servletRequest, final HttpServletResponse servletResponse) {
    final SessionRequest sreq = SessionRequest.parseXML(req.getContent());
    auditor.setMethod(sreq.getMethodName());
    SessionResponse sres = new SessionResponse(sreq.getRequestID(), sreq.getMethodID());
    Object context;
    try {
        // use remote client IP as default RestrictedToken context
        context = SessionUtils.getClientAddress(servletRequest);
        this.clientToken = null;
    } catch (Exception ex) {
        sessionDebug.error("SessionRequestHandler encounterd exception", ex);
        sres.setException(ex.getMessage());
        return auditedExceptionResponse(auditor, sres);
    }
    String requester = sreq.getRequester();
    if (requester != null) {
        try {
            context = RestrictedTokenContext.unmarshal(requester);
            if (context instanceof SSOToken) {
                SSOTokenManager ssoTokenManager = SSOTokenManager.getInstance();
                SSOToken adminToken = (SSOToken) context;
                if (!ssoTokenManager.isValidToken(adminToken)) {
                    sres.setException(SessionBundle.getString("appTokenInvalid") + requester);
                    return auditedExceptionResponse(auditor, sres);
                }
                this.clientToken = (SSOToken) context;
            }
        } catch (Exception ex) {
            if (sessionDebug.warningEnabled()) {
                sessionDebug.warning("SessionRequestHandler.processRequest:" + "app token invalid, sending Session response" + " with Exception");
            }
            sres.setException(SessionBundle.getString("appTokenInvalid") + requester);
            return auditedExceptionResponse(auditor, sres);
        }
    }
    try {
        sres = (SessionResponse) RestrictedTokenContext.doUsing(context, new RestrictedTokenAction() {

            public Object run() throws Exception {
                return processSessionRequest(auditor, sreq, servletRequest, servletResponse);
            }
        });
    } catch (Exception ex) {
        sessionDebug.error("SessionRequestHandler encounterd exception", ex);
        sres.setException(ex.getMessage());
    }
    if (sres.getException() == null) {
        auditor.auditAccessSuccess();
    } else {
        auditor.auditAccessFailure(sres.getException());
    }
    return new Response(sres.toXMLString());
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(com.iplanet.services.comm.share.Response) SessionResponse(com.iplanet.dpro.session.share.SessionResponse) SSOToken(com.iplanet.sso.SSOToken) SessionResponse(com.iplanet.dpro.session.share.SessionResponse) SessionRequest(com.iplanet.dpro.session.share.SessionRequest) SessionException(com.iplanet.dpro.session.SessionException) RestrictedTokenAction(com.sun.identity.session.util.RestrictedTokenAction)

Example 8 with Response

use of com.iplanet.services.comm.share.Response 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)

Example 9 with Response

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

the class AuthXMLHandler method process.

/**
     * process the request and return the response
     * @param requests Vector of
     *     <code>com.iplanet.services.comm.server.RequestHandler</code> objects.
     * @param servletRequest <code>HttpServletRequest</code>object for 
     *      this request.
     * @param servletResponse <code>HttpServletResponse</code> object for this
     *      request.
     * @param servletContext <code>servletContext</code> object for this request
     * @return <code>ResponseSet</code> object for the processed request.
     */
public ResponseSet process(PLLAuditor auditor, List<Request> requests, HttpServletRequest servletRequest, HttpServletResponse servletResponse, ServletContext servletContext) {
    ResponseSet rset = new ResponseSet(AuthXMLTags.AUTH_SERVICE);
    auditor.setComponent(AUTHENTICATION);
    for (Request req : requests) {
        Response res = processRequest(auditor, req, servletRequest, servletResponse);
        rset.addResponse(res);
    }
    return rset;
}
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 10 with Response

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

the class NamingService method processRequest.

private Response processRequest(Request req) {
    String content = req.getContent();
    NamingRequest nreq = NamingRequest.parseXML(content);
    NamingResponse nres = new NamingResponse(nreq.getRequestID());
    // get the version from nreq and check old
    float reqVersion = Float.valueOf(nreq.getRequestVersion()).floatValue();
    boolean limitNametable = (reqVersion > 1.0);
    // get the sesisonId from nreq
    String sessionId = nreq.getSessionId();
    try {
        if (sessionId == null) {
            nres.setNamingTable(NamingService.getNamingTable(limitNametable));
        } else {
            Hashtable tempHash = new Hashtable();
            tempHash = transferTable(NamingService.getNamingTable(limitNametable));
            Hashtable replacedTable = null;
            URL url = usePreferredNamingURL(nreq, reqVersion);
            if (url != null) {
                String uri = (reqVersion < 3.0) ? SystemProperties.get(Constants.AM_SERVICES_DEPLOYMENT_DESCRIPTOR) : WebtopNaming.getURI(url);
                if (uri.equals(Constants.EMPTY)) {
                    uri = SystemProperties.get(Constants.AM_SERVICES_DEPLOYMENT_DESCRIPTOR);
                    if (namingDebug.messageEnabled()) {
                        namingDebug.message("uri is blank; adding " + uri);
                    }
                }
                replacedTable = replaceTable(tempHash, url.getProtocol(), url.getHost(), Integer.toString(url.getPort()), uri);
            } else {
                replacedTable = replaceTable(tempHash, sessionId);
            }
            if (replacedTable == null) {
                nres.setException("SessionID ---" + sessionId + "---is Invalid");
            } else {
                nres.setNamingTable(replacedTable);
            }
            nres.setAttribute(Constants.NAMING_AM_LB_COOKIE, sessionCookies.getLBCookie(sessionId));
        }
    } catch (Exception e) {
        String errorMsg = "Failed to process naming request";
        namingDebug.error(errorMsg, e);
        if (e.getMessage() != null) {
            errorMsg = e.getMessage();
        }
        nres.setException(errorMsg);
    }
    // %uri with the actual value
    if (reqVersion < 3.0) {
        String uri = SystemProperties.get(Constants.AM_SERVICES_DEPLOYMENT_DESCRIPTOR);
        if (!uri.startsWith("/")) {
            uri = "/" + uri;
        }
        nres.replaceURI(uri);
    }
    return new Response(nres.toXMLString());
}
Also used : NamingResponse(com.iplanet.services.naming.share.NamingResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(com.iplanet.services.comm.share.Response) NamingRequest(com.iplanet.services.naming.share.NamingRequest) Hashtable(java.util.Hashtable) NamingResponse(com.iplanet.services.naming.share.NamingResponse) URL(java.net.URL) ServerEntryNotFoundException(com.iplanet.services.naming.ServerEntryNotFoundException) SMSException(com.sun.identity.sm.SMSException) MalformedURLException(java.net.MalformedURLException) SSOException(com.iplanet.sso.SSOException)

Aggregations

Response (com.iplanet.services.comm.share.Response)15 Request (com.iplanet.services.comm.share.Request)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 RequestSet (com.iplanet.services.comm.share.RequestSet)7 SSOException (com.iplanet.sso.SSOException)6 Vector (java.util.Vector)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 ResponseSet (com.iplanet.services.comm.share.ResponseSet)5 URL (java.net.URL)4 SessionException (com.iplanet.dpro.session.SessionException)3 SessionRequest (com.iplanet.dpro.session.share.SessionRequest)3 SessionResponse (com.iplanet.dpro.session.share.SessionResponse)3 SendRequestException (com.iplanet.services.comm.client.SendRequestException)3 NamingRequest (com.iplanet.services.naming.share.NamingRequest)3 NamingResponse (com.iplanet.services.naming.share.NamingResponse)3 SSOToken (com.iplanet.sso.SSOToken)3 SSOTokenManager (com.iplanet.sso.SSOTokenManager)3 MalformedURLException (java.net.MalformedURLException)3 SessionID (com.iplanet.dpro.session.SessionID)2 URLNotFoundException (com.iplanet.services.naming.URLNotFoundException)2