Search in sources :

Example 1 with PolicyListenerRequest

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

the class ResourceResultCache method addRemotePolicyListener.

/**
     * Registers a listener with policy service to recieve
     * notifications on policy changes
     * @param appToken session token identifying the client
     * @param serviceName service name
     * @param notificationURL end point on the client that listens for
     * notifications
     *
     * @param reRegister flag indicating whether to register listener
     *  even if it was already registered. <code>true</code> indicates
     * to register listener again even if it was previously registered
     */
boolean addRemotePolicyListener(SSOToken appToken, String serviceName, String notificationURL, boolean reRegister) {
    boolean status = false;
    if (debug.messageEnabled()) {
        debug.message("ResourceResultCache.addRemotePolicyListener():" + "serviceName=" + serviceName + ":notificationURL=" + notificationURL);
    }
    if (remotePolicyListeners.contains(serviceName) && !reRegister) {
        if (debug.messageEnabled()) {
            debug.message("ResourceResultCache.addRemotePolicyListener():" + "serviceName=" + serviceName + ":notificationURL=" + notificationURL + ":is already registered");
        }
        return status;
    }
    //else do the following
    URL policyServiceURL = null;
    if (appToken != null) {
        try {
            policyServiceURL = getPolicyServiceURL(appToken);
        } catch (PolicyException pe) {
            debug.error("ResourceResultCache.addRemotePolicyListener():" + "Can not add policy listner", pe);
        }
    }
    if ((appToken != null) && (policyServiceURL != null)) {
        PolicyListenerRequest listenerReq = new PolicyListenerRequest();
        listenerReq.setServiceName(serviceName);
        listenerReq.setNotificationURL(notificationURL);
        PolicyRequest policyReq = new PolicyRequest();
        policyReq.setAppSSOToken(appToken.getTokenID().toString());
        policyReq.setMethodID(PolicyRequest.POLICY_REQUEST_ADD_POLICY_LISTENER);
        policyReq.setPolicyListenerRequest(listenerReq);
        try {
            PolicyService ps = sendPLLRequest(policyServiceURL, policyReq);
            if (ps != null) {
                if (debug.messageEnabled()) {
                    debug.message("ResourceResultCache." + "addRemotePolicyListener():" + "result=" + ps.toXMLString());
                }
                PolicyResponse psres = ps.getPolicyResponse();
                if (psres.getMethodID() == PolicyResponse.POLICY_ADD_LISTENER_RESPONSE) {
                    status = true;
                    remotePolicyListeners.add(serviceName);
                    if (debug.messageEnabled()) {
                        debug.message("ResourceResultCache." + "addRemotePolicyListener():" + "serviceName=" + serviceName + ":notificationURL=" + notificationURL + ":policyServiceURL=" + policyServiceURL + ":add succeeded");
                    }
                }
            } else {
                debug.error("ResourceResultCache.addRemotePolicyListener():" + " no result");
            }
        } catch (Exception e) {
            debug.error("ResourceResultCache.addRemotePolicyListener():", e);
        }
    }
    return status;
}
Also used : PolicyException(com.sun.identity.policy.PolicyException) PolicyService(com.sun.identity.policy.remote.PolicyService) PolicyListenerRequest(com.sun.identity.policy.remote.PolicyListenerRequest) PolicyRequest(com.sun.identity.policy.remote.PolicyRequest) PolicyResponse(com.sun.identity.policy.remote.PolicyResponse) URL(java.net.URL) 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)

Aggregations

SessionException (com.iplanet.dpro.session.SessionException)1 AlreadyRegisteredException (com.iplanet.services.comm.client.AlreadyRegisteredException)1 SendRequestException (com.iplanet.services.comm.client.SendRequestException)1 URLNotFoundException (com.iplanet.services.naming.URLNotFoundException)1 SSOException (com.iplanet.sso.SSOException)1 PolicyException (com.sun.identity.policy.PolicyException)1 PolicyEvaluationException (com.sun.identity.policy.remote.PolicyEvaluationException)1 PolicyListenerRequest (com.sun.identity.policy.remote.PolicyListenerRequest)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 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1 JSONException (org.json.JSONException)1