Search in sources :

Example 1 with AdvicesHandleableByAMResponse

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

the class ResourceResultCache method getAdvicesHandleableByAM.

/** 
     * Returns names of policy advices that could be handled by OpenAM
     * Enterprise if PEP redirects user agent to OpenAM.
     *
     * @param appToken application sso token that would be used while
     *        communicating to OpenAM
     * @param refetchFromServer indicates whether to get the values fresh 
     *      from OpenAM or return the values from local cache.
     *      If the server reports app sso token is invalid, a new app sso
     *      token is created and one more call is made to the server.
     * @return names of policy advices that could be handled by OpenAM
     * @throws InvalidAppSSOTokenException if the server reported that the
     *         app sso token provided was invalid
     * @throws PolicyEvaluationException if the server reported any other error
     * @throws PolicyException if there are problems in getting the advice 
     *          names
     * @throws SSOException if the appToken is detected to be invalid
     *         at the client
     */
Set getAdvicesHandleableByAM(SSOToken appToken, boolean refetchFromServer) throws InvalidAppSSOTokenException, PolicyException, SSOException {
    if (debug.messageEnabled()) {
        debug.message("ResourceResultCache.getAdvicesHandleableByAM():" + ":entering");
    }
    if ((advicesHandleableByAM != null) && !refetchFromServer) {
        if (debug.messageEnabled()) {
            debug.message("ResourceResultCache.getAdvicesHandleableByAM():" + ":returning cached advices" + advicesHandleableByAM);
        }
        return advicesHandleableByAM;
    }
    URL policyServiceURL = null;
    if (appToken != null) {
        try {
            policyServiceURL = getPolicyServiceURL(appToken);
        } catch (PolicyException pe) {
            debug.error("ResourceResultCache.getAdvicesHandleableByAM():", pe);
            throw pe;
        }
    }
    if ((appToken != null) && (policyServiceURL != null)) {
        PolicyRequest policyReq = new PolicyRequest();
        policyReq.setAppSSOToken(appToken.getTokenID().toString());
        policyReq.setAdvicesHandleableByAMRequest(new AdvicesHandleableByAMRequest());
        policyReq.setMethodID(PolicyRequest.POLICY_REQUEST_ADVICES_HANDLEABLE_BY_AM_REQUEST);
        try {
            PolicyService ps = sendPLLRequest(policyServiceURL, policyReq);
            if (ps != null) {
                if (debug.messageEnabled()) {
                    debug.message("ResourceResultCache." + "getAdvicesHandleableByAM():" + "result=" + ps.toXMLString());
                }
                PolicyResponse psres = ps.getPolicyResponse();
                String exceptionMessage = psres.getExceptionMsg();
                if (exceptionMessage != null) {
                    if (exceptionMessage.indexOf(ResBundleUtils.getString("app_sso_token_invalid")) >= 0) {
                        if (debug.warningEnabled()) {
                            debug.warning("ResourceResultCache." + "getAdvicesHandleableByAM():" + " response exception " + exceptionMessage);
                            debug.warning("ResourceResultCache." + "AdvicesHandleableByAM():" + " 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 {
                        if (debug.warningEnabled()) {
                            debug.warning("ResourceResultCache." + "AdvicesHandleableByAM():" + "response exception message=" + exceptionMessage);
                        }
                        String[] args = { exceptionMessage };
                        throw new PolicyEvaluationException(ResBundleUtils.rbName, "server_reported_exception", args, null);
                    }
                }
                if (psres.getMethodID() == PolicyResponse.POLICY_ADVICES_HANDLEABLE_BY_AM_RESPONSE) {
                    AdvicesHandleableByAMResponse advicesHandleableByAMResponse = psres.getAdvicesHandleableByAMResponse();
                    if (debug.messageEnabled()) {
                        debug.message("ResourceResultCache." + "getAdvicesHandleableByAM():" + advicesHandleableByAMResponse);
                    }
                    if (advicesHandleableByAMResponse != null) {
                        advicesHandleableByAM = advicesHandleableByAMResponse.getAdvicesHandleableByAM();
                    }
                }
            } else {
                debug.error("ResourceResultCache.getAdvicesHandleableByAM()" + ":no result");
            }
        } catch (SendRequestException e) {
            debug.error("ResourceResultCache.getAdvicesHandleableByAM():", e);
            throw new PolicyException(e);
        }
    }
    if (advicesHandleableByAM == null) {
        advicesHandleableByAM = Collections.EMPTY_SET;
    }
    if (debug.messageEnabled()) {
        debug.message("ResourceResultCache.getAdvicesHandleableByAM():" + ":returning advicesHandleableByAM" + advicesHandleableByAM);
    }
    return advicesHandleableByAM;
}
Also used : SendRequestException(com.iplanet.services.comm.client.SendRequestException) AdvicesHandleableByAMRequest(com.sun.identity.policy.remote.AdvicesHandleableByAMRequest) AdvicesHandleableByAMResponse(com.sun.identity.policy.remote.AdvicesHandleableByAMResponse) PolicyException(com.sun.identity.policy.PolicyException) PolicyService(com.sun.identity.policy.remote.PolicyService) PolicyEvaluationException(com.sun.identity.policy.remote.PolicyEvaluationException) PolicyRequest(com.sun.identity.policy.remote.PolicyRequest) PolicyResponse(com.sun.identity.policy.remote.PolicyResponse) URL(java.net.URL)

Aggregations

SendRequestException (com.iplanet.services.comm.client.SendRequestException)1 PolicyException (com.sun.identity.policy.PolicyException)1 AdvicesHandleableByAMRequest (com.sun.identity.policy.remote.AdvicesHandleableByAMRequest)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