Search in sources :

Example 1 with ResourceResultRequest

use of com.sun.identity.policy.remote.ResourceResultRequest 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 2 with ResourceResultRequest

use of com.sun.identity.policy.remote.ResourceResultRequest in project OpenAM by OpenRock.

the class ResourceResultCache method getLBCookie.

/**
     * Returns lbcookie value for the Session
     * @param  preq policy request
     * @return lbcookie name and value pair
     * @throws Exception if session in request is invalid
     */
public static String getLBCookie(PolicyRequest preq) throws Exception {
    String lbcookie;
    ResourceResultRequest rrReq = preq.getResourceResultRequest();
    if (rrReq != null) {
        lbcookie = sessionCookies.getLBCookie(rrReq.getUserSSOToken());
    } else {
        lbcookie = sessionCookies.getLBCookie(preq.getAppSSOToken());
    }
    return lbcookie;
}
Also used : ResourceResultRequest(com.sun.identity.policy.remote.ResourceResultRequest)

Aggregations

ResourceResultRequest (com.sun.identity.policy.remote.ResourceResultRequest)2 SendRequestException (com.iplanet.services.comm.client.SendRequestException)1 RequestSet (com.iplanet.services.comm.share.RequestSet)1 Response (com.iplanet.services.comm.share.Response)1 AdvicesHandleableByAMResponse (com.sun.identity.policy.remote.AdvicesHandleableByAMResponse)1 PolicyEvaluationException (com.sun.identity.policy.remote.PolicyEvaluationException)1 PolicyRequest (com.sun.identity.policy.remote.PolicyRequest)1 PolicyResponse (com.sun.identity.policy.remote.PolicyResponse)1 PolicyService (com.sun.identity.policy.remote.PolicyService)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1