Search in sources :

Example 1 with Response

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

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

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

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

the class ResourceResultCache method getResultsFromServer.

/**
     * Returns a set of <code>ResourceResult</code> objects from server.
     * Fresh resource results 
     * are fetched from policy server and returned.
     * @param appToken application sso token to identify the client to policy
     * service
     *
     * @param serviceName name of service for which to get resource results
     * @param token session token of user for whom to get resource results
     * @param resourceName resource name for which to get resource results
     * @param scope the scope to be used while getting resource results
     * @param actionNames action names for which to get resource results
     * @param env environment map to use to get resource results
     *
     * @return a set of <code>ResourceResult</code> objects
     *
     * @throws PolicyException if can not get resource results
     * @throws SSOException if session token is not valid
     * @throws InvalidAppSSOTokenException if application session token 
     * is not valid
     */
private Set getResultsFromServer(SSOToken appToken, String serviceName, SSOToken token, String resourceName, String scope, Set actionNames, Map env) throws InvalidAppSSOTokenException, SSOException, PolicyException {
    Set resourceResults = null;
    Response response = null;
    try {
        URL policyServiceUrl = getPolicyServiceURL(token);
        if (debug.messageEnabled()) {
            debug.message("ResourceResultCache.getResultsFromServer():" + ":serviceName=" + serviceName + ":token=" + token.getPrincipal().getName() + ":resourceName=" + resourceName + ":scope=" + scope + ":actionNames=" + actionNames + ":env" + ":policyServiceURL=" + policyServiceUrl + ":entering");
        }
        ResourceResultRequest rrRequest = new ResourceResultRequest();
        rrRequest.setServiceName(serviceName);
        rrRequest.setResourceName(resourceName);
        rrRequest.setResourceScope(scope);
        rrRequest.setUserSSOToken(token.getTokenID().toString());
        Set responseAttributes = null;
        if (env != null) {
            rrRequest.setEnvParms(env);
            responseAttributes = getResponseAttributes(env);
            if (debug.messageEnabled()) {
                debug.message("ResourceResultCache.getResultsFromServer():" + "responseAttributes to get=" + responseAttributes);
            }
            if (responseAttributes != null) {
                rrRequest.setResponseAttributes(responseAttributes);
            }
        }
        PolicyRequest policyRequest = new PolicyRequest();
        policyRequest.setAppSSOToken(appToken.getTokenID().toString());
        policyRequest.setMethodID(PolicyRequest.POLICY_REQUEST_GET_RESOURCE_RESULTS);
        policyRequest.setRequestId(newRequestID());
        policyRequest.setResourceResultRequest(rrRequest);
        PolicyService ps = sendPLLRequest(policyServiceUrl, policyRequest);
        if (ps != null) {
            PolicyResponse pr = ps.getPolicyResponse();
            String exceptionMessage = pr.getExceptionMsg();
            if (exceptionMessage != null) {
                if (exceptionMessage.indexOf(PolicyResponse.APP_SSO_TOKEN_INVALID) >= 0) {
                    if (debug.warningEnabled()) {
                        debug.warning("ResourceResultCache." + "getResultsFromServer():" + " response exception " + exceptionMessage);
                        debug.warning("ResourceResultCache." + "getResultsFromServer():" + " appSSOToken is invalid");
                        debug.warning("ResourceResultCache." + "throwing InvalidAppSSOTokenException");
                    }
                    String[] args = { exceptionMessage };
                    throw new InvalidAppSSOTokenException(ResBundleUtils.rbName, "server_reported_invalid_app_sso_token", args, null);
                } else {
                    debug.warning("ResourceResultCache." + "getResultsFromServer():" + "response exception message=" + exceptionMessage);
                    String[] args = { exceptionMessage };
                    throw new PolicyEvaluationException(ResBundleUtils.rbName, "server_reported_exception", args, null);
                }
            } else {
                resourceResults = pr.getResourceResults();
            }
        }
    } catch (SendRequestException sre) {
        String[] args = { sre.getMessage() };
        throw new PolicyEvaluationException(ResBundleUtils.rbName, "pll_send_request_exception", args, sre);
    }
    if (debug.messageEnabled()) {
        debug.message("ResourceResultCache.getResultsFromServer():" + "returning");
    }
    return resourceResults;
}
Also used : AdvicesHandleableByAMResponse(com.sun.identity.policy.remote.AdvicesHandleableByAMResponse) PolicyResponse(com.sun.identity.policy.remote.PolicyResponse) Response(com.iplanet.services.comm.share.Response) SendRequestException(com.iplanet.services.comm.client.SendRequestException) Set(java.util.Set) HashSet(java.util.HashSet) RequestSet(com.iplanet.services.comm.share.RequestSet) PolicyService(com.sun.identity.policy.remote.PolicyService) PolicyEvaluationException(com.sun.identity.policy.remote.PolicyEvaluationException) ResourceResultRequest(com.sun.identity.policy.remote.ResourceResultRequest) PolicyRequest(com.sun.identity.policy.remote.PolicyRequest) PolicyResponse(com.sun.identity.policy.remote.PolicyResponse) URL(java.net.URL)

Example 5 with Response

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

the class LogRecWrite method execute.

/**
     * Return result of the request processing in <code>Response</code>
     * @return result of the request processing in <code>Response</code>
     */
public Response execute(AuditEventPublisher auditEventPublisher, AuditEventFactory auditEventFactory) {
    Response res = new Response("OK");
    SsoServerLoggingSvcImpl slsi = null;
    SsoServerLoggingHdlrEntryImpl slei = null;
    if (MonitoringUtil.isRunning()) {
        slsi = Agent.getLoggingSvcMBean();
        slei = slsi.getHandler(SsoServerLoggingSvcImpl.REMOTE_HANDLER_NAME);
    }
    Logger logger = (Logger) Logger.getLogger(_logname);
    if (Debug.messageEnabled()) {
        Debug.message("LogRecWrite: exec: logname = " + _logname);
    }
    Level level = Level.parse(((com.sun.identity.log.service.LogRecord) _records.elementAt(0)).level);
    String msg = ((com.sun.identity.log.service.LogRecord) _records.elementAt(0)).msg;
    Map logInfoMap = ((com.sun.identity.log.service.LogRecord) _records.elementAt(0)).logInfoMap;
    Object[] parameters = ((com.sun.identity.log.service.LogRecord) _records.elementAt(0)).parameters;
    try {
        msg = new String(com.sun.identity.shared.encode.Base64.decode(msg));
    } catch (RuntimeException ex) {
        // write msg as it is.
        if (Debug.messageEnabled()) {
            Debug.message("LogRecWrite: message is not base64 encoded");
        }
    }
    LogRecord rec = new LogRecord(level, msg);
    if (logInfoMap != null) {
        String loginIDSid = (String) logInfoMap.get(LogConstants.LOGIN_ID_SID);
        if (loginIDSid != null && loginIDSid.length() > 0) {
            SSOToken loginIDToken = null;
            try {
                SSOTokenManager ssom = SSOTokenManager.getInstance();
                loginIDToken = ssom.createSSOToken(loginIDSid);
            } catch (SSOException e) {
                if (Debug.warningEnabled()) {
                    Debug.warning("LogService::process(): SSOException", e);
                }
                rec.setLogInfoMap(logInfoMap);
            }
            if (loginIDToken != null) {
                // here fill up logInfo into the newlr
                rec = LogSSOTokenDetails.logSSOTokenInfo(rec, loginIDToken);
                // now take one be one values from logInfoMap and overwrite
                // any populated value from sso token.
                Set keySet = logInfoMap.keySet();
                Iterator i = keySet.iterator();
                String key = null;
                String value = null;
                while (i.hasNext()) {
                    key = (String) i.next();
                    value = (String) logInfoMap.get(key);
                    if (value != null && value.length() > 0) {
                        if (key.equalsIgnoreCase(LogConstants.DATA)) {
                            try {
                                value = new String(com.sun.identity.shared.encode.Base64.decode(value));
                            } catch (RuntimeException ex) {
                                // ignore & write msg as it is.
                                if (Debug.messageEnabled()) {
                                    Debug.message("LogRecWrite: data is not " + "base64 encoded");
                                }
                            }
                        }
                        rec.addLogInfo(key, value);
                    }
                }
            }
        } else {
            rec.setLogInfoMap(logInfoMap);
        }
    }
    rec.addLogInfo(LogConstants.LOG_LEVEL, rec.getLevel().toString());
    rec.setParameters(parameters);
    SSOToken loggedByToken = null;
    String realm = NO_REALM;
    try {
        SSOTokenManager ssom = SSOTokenManager.getInstance();
        loggedByToken = ssom.createSSOToken(_loggedBySid);
        Map<String, Set<String>> appAttributes = IdUtils.getIdentity(loggedByToken).getAttributes();
        realm = getFirstItem(appAttributes.get(EVALUATION_REALM), NO_REALM);
    } catch (IdRepoException | SSOException ssoe) {
        Debug.error("LogRecWrite: exec:SSOException: ", ssoe);
    }
    if (MonitoringUtil.isRunning()) {
        slei.incHandlerRequestCount(1);
    }
    auditAccessMessage(auditEventPublisher, auditEventFactory, rec, realm);
    logger.log(rec, loggedByToken);
    // Log file record write okay and return OK
    if (MonitoringUtil.isRunning()) {
        slei.incHandlerSuccessCount(1);
    }
    return res;
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) Logger(com.sun.identity.log.Logger) Response(com.iplanet.services.comm.share.Response) LogRecord(com.sun.identity.log.LogRecord) Iterator(java.util.Iterator) Level(java.util.logging.Level) Map(java.util.Map) SsoServerLoggingSvcImpl(com.sun.identity.monitoring.SsoServerLoggingSvcImpl) SsoServerLoggingHdlrEntryImpl(com.sun.identity.monitoring.SsoServerLoggingHdlrEntryImpl)

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