Search in sources :

Example 1 with ResponseProvider

use of com.sun.identity.policy.interfaces.ResponseProvider in project OpenAM by OpenRock.

the class PrivilegeUtils method resourceAttributesToResponseProviders.

private static Map<String, ResponseProvider> resourceAttributesToResponseProviders(Set<ResourceAttribute> resourceAttributes) throws PolicyException, EntitlementException {
    Map<String, ResponseProvider> results = new HashMap<String, ResponseProvider>();
    if (resourceAttributes != null) {
        Map<String, Map<String, Set<String>>> map = new HashMap<String, Map<String, Set<String>>>();
        for (ResourceAttribute ra : resourceAttributes) {
            if (ra instanceof StaticAttributes) {
                resourceAttributesToResponseProviders((StaticAttributes) ra, map);
            } else if (ra instanceof UserAttributes) {
                resourceAttributesToResponseProviders((UserAttributes) ra, map);
            }
        }
        for (String n : map.keySet()) {
            ResponseProvider rp = new IDRepoResponseProvider();
            Map<String, Set<String>> values = map.get(n);
            Set<String> dynValues = values.get(IDRepoResponseProvider.DYNAMIC_ATTRIBUTE);
            if ((dynValues != null) && !dynValues.isEmpty()) {
                Map<String, Set<String>> configParams = new HashMap<String, Set<String>>();
                configParams.put(PolicyConfig.SELECTED_DYNAMIC_ATTRIBUTES, dynValues);
                rp.initialize(configParams);
            }
            rp.setProperties(values);
            results.put(n, rp);
        }
        // Copy any legacy response providers over directly
        for (ResourceAttribute ra : resourceAttributes) {
            if (ra instanceof PolicyResponseProvider) {
                PolicyResponseProvider prp = (PolicyResponseProvider) ra;
                results.put(prp.getPResponseProviderName(), prp.getResponseProvider());
            }
        }
    }
    return results;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) StaticAttributes(com.sun.identity.entitlement.StaticAttributes) IDRepoResponseProvider(com.sun.identity.policy.plugins.IDRepoResponseProvider) UserAttributes(com.sun.identity.entitlement.UserAttributes) IDRepoResponseProvider(com.sun.identity.policy.plugins.IDRepoResponseProvider) ResponseProvider(com.sun.identity.policy.interfaces.ResponseProvider) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ResponseProvider

use of com.sun.identity.policy.interfaces.ResponseProvider in project OpenAM by OpenRock.

the class PolicyResponseProvider method getResponseProvider.

/**
     * Constructs a legacy response provider based on the information in this adapter.
     *
     * @return the legacy response provider
     * @throws EntitlementException if an error occurs constructing the response provider.
     */
@JsonIgnore
public ResponseProvider getResponseProvider() throws EntitlementException {
    try {
        ResponseProvider rp = Class.forName(className).asSubclass(ResponseProvider.class).newInstance();
        Map<String, Set<String>> properties = new HashMap<String, Set<String>>();
        properties.put(propertyName, propertyValues);
        rp.setProperties(properties);
        return rp;
    } catch (Exception ex) {
        throw new EntitlementException(510, ex);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ResponseProvider(com.sun.identity.policy.interfaces.ResponseProvider) JSONException(org.json.JSONException) EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOException(com.iplanet.sso.SSOException) PolicyException(com.sun.identity.policy.PolicyException) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 3 with ResponseProvider

use of com.sun.identity.policy.interfaces.ResponseProvider in project OpenAM by OpenRock.

the class PolicyResponseProvider method evaluate.

/**
     * Called by the entitlements framework to fetch its resource attributes;
     * cascades the call through to the configured response provider implementation
     * 
     * @param adminSubject The admin user executing the policy eval
     * @param realm The realm of the policy eval
     * @param subject The user who is subject to the policy eval
     * @param resourceName The resource name of the policy eval
     * @param environment environment map from the policy eval client
     * @return The attributes (only one since resource attributes are singled)
     * @throws EntitlementException 
     */
public Map<String, Set<String>> evaluate(Subject adminSubject, String realm, Subject subject, String resourceName, Map<String, Set<String>> environment) throws EntitlementException {
    try {
        ResponseProvider rp = getResponseProvider();
        SSOToken token = (subject != null) ? getSSOToken(subject) : null;
        Map<String, Set<String>> result = rp.getResponseDecision(token, environment);
        return result;
    } catch (SSOException ex) {
        throw new EntitlementException(510, ex);
    } catch (PolicyException ex) {
        throw new EntitlementException(510, ex);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) HashSet(java.util.HashSet) PolicyException(com.sun.identity.policy.PolicyException) ResponseProvider(com.sun.identity.policy.interfaces.ResponseProvider) SSOException(com.iplanet.sso.SSOException)

Example 4 with ResponseProvider

use of com.sun.identity.policy.interfaces.ResponseProvider in project OpenAM by OpenRock.

the class PolicyModelImpl method getResponseProviderViewBeanURL.

/**
     * Returns properties view bean URL of a response provider.
     *
     * @param realmName Name of realm.
     * @param typeName Name of response provider Type.
     * @return properties view bean URL of a response provider.
     */
public String getResponseProviderViewBeanURL(String realmName, String typeName) {
    String url = null;
    try {
        PolicyManager policyMgr = getPolicyManager(realmName);
        if (policyMgr != null) {
            ResponseProviderTypeManager mgr = policyMgr.getResponseProviderTypeManager();
            ResponseProvider provider = mgr.getResponseProvider(typeName);
            url = mgr.getViewBeanURL(provider);
        }
    } catch (AMConsoleException e) {
        debug.warning("PolicyModelImpl.getResponseProviderViewBeanURL", e);
    } catch (NameNotFoundException e) {
        debug.warning("PolicyModelImpl.getResponseProviderViewBeanURL", e);
    } catch (PolicyException e) {
        debug.warning("PolicyModelImpl.getResponseProviderViewBeanURL", e);
    }
    return url;
}
Also used : PolicyManager(com.sun.identity.policy.PolicyManager) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) PolicyException(com.sun.identity.policy.PolicyException) ResponseProvider(com.sun.identity.policy.interfaces.ResponseProvider) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) ResponseProviderTypeManager(com.sun.identity.policy.ResponseProviderTypeManager)

Example 5 with ResponseProvider

use of com.sun.identity.policy.interfaces.ResponseProvider in project OpenAM by OpenRock.

the class PolicyModelImpl method createResponseProvider.

/**
     * Returns a response provider object.
     *
     * @param realmName Name of Realm.
     * @param providerType Name of response provider type.
     * @param values Values of the response provider.
     * @return response provider object.
     * @throws AMConsoleException if response provider cannot be created.
     */
public ResponseProvider createResponseProvider(String realmName, String providerType, Map values) throws AMConsoleException {
    ResponseProvider provider = null;
    try {
        PolicyManager policyMgr = getPolicyManager(realmName);
        if (policyMgr != null) {
            ResponseProviderTypeManager mgr = policyMgr.getResponseProviderTypeManager();
            provider = mgr.getResponseProvider(providerType);
            provider.setProperties(values);
        }
    } catch (NameNotFoundException e) {
        throw new AMConsoleException(getErrorString(e));
    } catch (PolicyException e) {
        throw new AMConsoleException(getErrorString(e));
    }
    return provider;
}
Also used : PolicyManager(com.sun.identity.policy.PolicyManager) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) PolicyException(com.sun.identity.policy.PolicyException) ResponseProvider(com.sun.identity.policy.interfaces.ResponseProvider) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) ResponseProviderTypeManager(com.sun.identity.policy.ResponseProviderTypeManager)

Aggregations

ResponseProvider (com.sun.identity.policy.interfaces.ResponseProvider)19 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)7 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)7 Policy (com.sun.identity.policy.Policy)6 CachedPolicy (com.sun.identity.console.policy.model.CachedPolicy)5 PolicyException (com.sun.identity.policy.PolicyException)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 IDRepoResponseProvider (com.sun.identity.policy.plugins.IDRepoResponseProvider)4 Map (java.util.Map)4 SSOException (com.iplanet.sso.SSOException)3 PolicyManager (com.sun.identity.policy.PolicyManager)3 ResponseProviderTypeManager (com.sun.identity.policy.ResponseProviderTypeManager)3 HashMap (java.util.HashMap)3 PolicyModel (com.sun.identity.console.policy.model.PolicyModel)2 EntitlementException (com.sun.identity.entitlement.EntitlementException)2 ResourceAttribute (com.sun.identity.entitlement.ResourceAttribute)2 NameAlreadyExistsException (com.sun.identity.policy.NameAlreadyExistsException)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 SSOToken (com.iplanet.sso.SSOToken)1