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);
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations