Search in sources :

Example 1 with PolicyPublisher

use of org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher in project carbon-identity-framework by wso2.

the class EntitlementPolicyAdminService method publishToPDP.

/**
 * @param policyIds
 * @throws EntitlementException
 */
private void publishToPDP(String[] policyIds, String version, String action) throws EntitlementException {
    PolicyPublisher publisher = EntitlementAdminEngine.getInstance().getPolicyPublisher();
    String[] subscribers = new String[] { EntitlementConstants.PDP_SUBSCRIBER_ID };
    publisher.publishPolicy(policyIds, version, action, false, 0, subscribers, null);
}
Also used : PolicyPublisher(org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher)

Example 2 with PolicyPublisher

use of org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher in project carbon-identity-framework by wso2.

the class EntitlementPolicyAdminService method publishPolicies.

/**
 * Publishes given set of policies to all subscribers
 *
 * @param policyIds     policy ids to publish,  if null or empty, all policies are published
 * @param subscriberIds subscriber ids to publish,  if null or empty, all policies are published
 * @param action        publishing action
 * @param version       version
 * @param enabled       whether policy must be enabled or not
 * @param order         order of the policy
 * @throws EntitlementException throws, if fails
 */
public void publishPolicies(String[] policyIds, String[] subscriberIds, String action, String version, boolean enabled, int order) throws EntitlementException {
    PolicyPublisher publisher = EntitlementAdminEngine.getInstance().getPolicyPublisher();
    if (policyIds == null || policyIds.length < 1) {
        policyIds = EntitlementAdminEngine.getInstance().getPapPolicyStoreManager().getPolicyIds();
    }
    if (subscriberIds == null || subscriberIds.length < 1) {
        subscriberIds = publisher.retrieveSubscriberIds("*");
    }
    if (policyIds == null || policyIds.length < 1) {
        throw new EntitlementException("There are no policies to publish");
    }
    if (subscriberIds == null || subscriberIds.length < 1) {
        throw new EntitlementException("There are no subscribers to publish");
    }
    publisher.publishPolicy(policyIds, version, action, enabled, order, subscriberIds, null);
}
Also used : PolicyPublisher(org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher)

Example 3 with PolicyPublisher

use of org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher in project carbon-identity-framework by wso2.

the class EntitlementUtil method addPolicyToPDP.

/**
 * @param policyStoreDTO
 * @return
 */
public static void addPolicyToPDP(PolicyStoreDTO policyStoreDTO) throws EntitlementException {
    Registry registry;
    String policyPath;
    Collection policyCollection;
    Resource resource;
    Map.Entry<PolicyStoreManageModule, Properties> entry = EntitlementServiceComponent.getEntitlementConfig().getPolicyStore().entrySet().iterator().next();
    String policyStorePath = entry.getValue().getProperty("policyStorePath");
    if (policyStorePath == null) {
        policyStorePath = "/repository/identity/entitlement/policy/pdp/";
    }
    if (policyStoreDTO == null || policyStoreDTO.getPolicy() == null || policyStoreDTO.getPolicy().trim().length() == 0 || policyStoreDTO.getPolicyId() == null || policyStoreDTO.getPolicyId().trim().length() == 0) {
        return;
    }
    try {
        registry = EntitlementServiceComponent.getRegistryService().getGovernanceSystemRegistry();
        if (registry.resourceExists(policyStorePath)) {
            policyCollection = (Collection) registry.get(policyStorePath);
        } else {
            policyCollection = registry.newCollection();
        }
        registry.put(policyStorePath, policyCollection);
        policyPath = policyStorePath + policyStoreDTO.getPolicyId();
        if (registry.resourceExists(policyPath)) {
            resource = registry.get(policyPath);
        } else {
            resource = registry.newResource();
        }
        resource.setProperty("policyOrder", Integer.toString(policyStoreDTO.getPolicyOrder()));
        resource.setContent(policyStoreDTO.getPolicy());
        resource.setMediaType("application/xacml-policy+xml");
        resource.setProperty("active", String.valueOf(policyStoreDTO.isActive()));
        AttributeDTO[] attributeDTOs = policyStoreDTO.getAttributeDTOs();
        if (attributeDTOs != null) {
            setAttributesAsProperties(attributeDTOs, resource);
        }
        registry.put(policyPath, resource);
        // Enable published policies in PDP
        PAPPolicyStoreManager storeManager = EntitlementAdminEngine.getInstance().getPapPolicyStoreManager();
        if (storeManager.isExistPolicy(policyStoreDTO.getPolicyId())) {
            PolicyPublisher publisher = EntitlementAdminEngine.getInstance().getPolicyPublisher();
            String[] subscribers = new String[] { EntitlementConstants.PDP_SUBSCRIBER_ID };
            if (policyStoreDTO.isActive()) {
                publisher.publishPolicy(new String[] { policyStoreDTO.getPolicyId() }, null, EntitlementConstants.PolicyPublish.ACTION_ENABLE, false, 0, subscribers, null);
            } else {
                publisher.publishPolicy(new String[] { policyStoreDTO.getPolicyId() }, null, EntitlementConstants.PolicyPublish.ACTION_DISABLE, false, 0, subscribers, null);
            }
        }
    } catch (RegistryException e) {
        log.error(e);
        throw new EntitlementException("Error while adding policy to PDP", e);
    }
}
Also used : PAPPolicyStoreManager(org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreManager) Resource(org.wso2.carbon.registry.core.Resource) Registry(org.wso2.carbon.registry.core.Registry) Properties(java.util.Properties) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) AttributeDTO(org.wso2.carbon.identity.entitlement.dto.AttributeDTO) PolicyStoreManageModule(org.wso2.carbon.identity.entitlement.policy.store.PolicyStoreManageModule) PolicyPublisher(org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher) Collection(org.wso2.carbon.registry.core.Collection) Map(java.util.Map)

Example 4 with PolicyPublisher

use of org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher in project carbon-identity-framework by wso2.

the class EntitlementPolicyAdminService method deleteSubscriber.

/**
 * delete subscriber details from registry
 *
 * @param subscriberId subscriber id
 * @throws EntitlementException throws, if fails
 */
public void deleteSubscriber(String subscriberId) throws EntitlementException {
    PolicyPublisher publisher = EntitlementAdminEngine.getInstance().getPolicyPublisher();
    publisher.deleteSubscriber(subscriberId);
}
Also used : PolicyPublisher(org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher)

Example 5 with PolicyPublisher

use of org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher in project carbon-identity-framework by wso2.

the class EntitlementPolicyAdminService method publishToPDP.

/**
 * @param policyIds
 * @throws EntitlementException
 */
public void publishToPDP(String[] policyIds, String action, String version, boolean enabled, int order) throws EntitlementException {
    PolicyPublisher publisher = EntitlementAdminEngine.getInstance().getPolicyPublisher();
    String[] subscribers = new String[] { EntitlementConstants.PDP_SUBSCRIBER_ID };
    publisher.publishPolicy(policyIds, version, action, enabled, order, subscribers, null);
}
Also used : PolicyPublisher(org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher)

Aggregations

PolicyPublisher (org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher)9 Map (java.util.Map)1 Properties (java.util.Properties)1 AttributeDTO (org.wso2.carbon.identity.entitlement.dto.AttributeDTO)1 PAPPolicyStoreManager (org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreManager)1 PolicyStoreManageModule (org.wso2.carbon.identity.entitlement.policy.store.PolicyStoreManageModule)1 Collection (org.wso2.carbon.registry.core.Collection)1 Registry (org.wso2.carbon.registry.core.Registry)1 Resource (org.wso2.carbon.registry.core.Resource)1 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)1