use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.
the class PAPPolicyFinder method initPolicyIds.
public void initPolicyIds() throws EntitlementException {
this.policyIds = new ArrayList<String>();
PolicyDTO[] policyDTOs = policyReader.readAllLightPolicyDTOs();
for (PolicyDTO dto : policyDTOs) {
if (dto.isActive()) {
policyIds.add(dto.getPolicyId());
}
}
}
use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.
the class PAPPolicyFinder method findPolicy.
/*
* (non-Javadoc)
*
* @see org.wso2.balana.finder.PolicyFinderModule#findPolicy(java.net.URI, int,
* org.wso2.balana.VersionConstraints, org.wso2.balana.PolicyMetaData)
*/
public PolicyFinderResult findPolicy(URI idReference, int type, VersionConstraints constraints, PolicyMetaData parentMetaData) {
// clear all current policies
policies.getPolicies().clear();
AbstractPolicy policy = null;
try {
AbstractPolicy policyFromStore = policyReader.readPolicy(idReference.toString(), this.policyFinder);
if (policyFromStore != null) {
if (type == PolicyReference.POLICY_REFERENCE) {
if (policyFromStore instanceof Policy) {
policy = policyFromStore;
policies.addPolicy(policy);
}
} else {
if (policyFromStore instanceof PolicySet) {
policy = policyFromStore;
policies.addPolicy(policy);
}
}
}
} catch (EntitlementException e) {
// ignore and just log the error.
log.error(e);
}
if (policy == null) {
return new PolicyFinderResult();
} else {
return new PolicyFinderResult(policy);
}
}
use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.
the class RegistryPolicyReader method readPolicy.
/**
* Reads given policy resource as PolicyDTO
*
* @param policyId policy id
* @return PolicyDTO
* @throws EntitlementException throws, if fails
*/
public PolicyDTO readPolicy(String policyId) throws EntitlementException {
Resource resource = null;
resource = getPolicyResource(policyId);
if (resource == null) {
return new PolicyDTO();
}
return readPolicy(resource);
}
use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.
the class RegistryPolicyReader method readPolicy.
/**
* Reads PolicyDTO for given registry resource
*
* @param resource Registry resource
* @return PolicyDTO
* @throws EntitlementException throws, if fails
*/
private PolicyDTO readPolicy(Resource resource) throws EntitlementException {
String policy = null;
AbstractPolicy absPolicy = null;
PolicyDTO dto = null;
try {
if (resource.getContent() == null) {
throw new EntitlementException("Error while loading entitlement policy. Policy content is null");
}
policy = new String((byte[]) resource.getContent(), Charset.forName("UTF-8"));
absPolicy = PAPPolicyReader.getInstance(null).getPolicy(policy);
dto = new PolicyDTO();
dto.setPolicyId(absPolicy.getId().toASCIIString());
dto.setPolicy(policy);
String policyOrder = resource.getProperty("order");
if (policyOrder != null) {
dto.setPolicyOrder(Integer.parseInt(policyOrder));
} else {
dto.setPolicyOrder(0);
}
String policyActive = resource.getProperty("active");
if (policyActive != null) {
dto.setActive(Boolean.parseBoolean(policyActive));
}
PolicyAttributeBuilder policyAttributeBuilder = new PolicyAttributeBuilder();
dto.setAttributeDTOs(policyAttributeBuilder.getPolicyMetaDataFromRegistryProperties(resource.getProperties()));
return dto;
} catch (RegistryException e) {
log.error("Error while loading entitlement policy", e);
throw new EntitlementException("Error while loading entitlement policy", e);
}
}
use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.
the class AbstractPolicyPublisherModule method publish.
@Override
public void publish(PolicyDTO policyDTO, String action, boolean enabled, int order) throws EntitlementException {
if (EntitlementConstants.PolicyPublish.ACTION_CREATE.equals(action)) {
policyDTO.setPolicyOrder(order);
policyDTO.setActive(enabled);
publishNew(policyDTO);
} else if (EntitlementConstants.PolicyPublish.ACTION_DELETE.equals(action)) {
delete(policyDTO);
} else if (EntitlementConstants.PolicyPublish.ACTION_UPDATE.equals(action)) {
update(policyDTO);
} else if (EntitlementConstants.PolicyPublish.ACTION_ENABLE.equals(action)) {
policyDTO.setActive(true);
enable(policyDTO);
} else if (EntitlementConstants.PolicyPublish.ACTION_DISABLE.equals(action)) {
policyDTO.setActive(false);
disable(policyDTO);
} else if (EntitlementConstants.PolicyPublish.ACTION_ORDER.equals(action)) {
policyDTO.setPolicyOrder(order);
order(policyDTO);
} else {
throw new EntitlementException("Unsupported publishing action. Action is : " + action);
}
}
Aggregations