use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project carbon-identity-framework by wso2.
the class PAPPolicyStoreReader method readMetaDataPolicyDTO.
/**
* Reads Light Weight PolicyDTO with Attribute meta data for given policy id
*
* @param policyId policy id
* @return PolicyDTO but don not contains XACML policy
* @throws EntitlementException throws, if fails
*/
public PolicyDTO readMetaDataPolicyDTO(String policyId) throws EntitlementException {
Resource resource = null;
PolicyDTO dto = null;
resource = store.getPolicy(policyId, PDPConstants.ENTITLEMENT_POLICY_PAP);
if (resource == null) {
return null;
}
dto = new PolicyDTO();
dto.setPolicyId(policyId);
dto.setActive(Boolean.parseBoolean(resource.getProperty(PDPConstants.ACTIVE_POLICY)));
String policyOrder = resource.getProperty(PDPConstants.POLICY_ORDER);
if (policyOrder != null) {
dto.setPolicyOrder(Integer.parseInt(policyOrder));
} else {
dto.setPolicyOrder(0);
}
String version = resource.getProperty(PDPConstants.POLICY_VERSION);
if (version != null) {
dto.setVersion(version);
}
String lastModifiedTime = resource.getProperty(PDPConstants.LAST_MODIFIED_TIME);
if (lastModifiedTime != null) {
dto.setLastModifiedTime(lastModifiedTime);
}
String lastModifiedUser = resource.getProperty(PDPConstants.LAST_MODIFIED_USER);
if (lastModifiedUser != null) {
dto.setLastModifiedUser(lastModifiedUser);
}
dto.setPolicyType(resource.getProperty(PDPConstants.POLICY_TYPE));
String policyReferences = resource.getProperty(PDPConstants.POLICY_REFERENCE);
if (policyReferences != null && policyReferences.trim().length() > 0) {
dto.setPolicyIdReferences(policyReferences.split(PDPConstants.ATTRIBUTE_SEPARATOR));
}
String policySetReferences = resource.getProperty(PDPConstants.POLICY_SET_REFERENCE);
if (policySetReferences != null && policySetReferences.trim().length() > 0) {
dto.setPolicySetIdReferences(policySetReferences.split(PDPConstants.ATTRIBUTE_SEPARATOR));
}
dto.setPolicyEditor(resource.getProperty(PDPConstants.POLICY_EDITOR_TYPE));
String basicPolicyEditorMetaDataAmount = resource.getProperty(PDPConstants.BASIC_POLICY_EDITOR_META_DATA_AMOUNT);
if (basicPolicyEditorMetaDataAmount != null) {
int amount = Integer.parseInt(basicPolicyEditorMetaDataAmount);
String[] basicPolicyEditorMetaData = new String[amount];
for (int i = 0; i < amount; i++) {
basicPolicyEditorMetaData[i] = resource.getProperty(PDPConstants.BASIC_POLICY_EDITOR_META_DATA + i);
}
dto.setPolicyEditorData(basicPolicyEditorMetaData);
}
PolicyAttributeBuilder policyAttributeBuilder = new PolicyAttributeBuilder();
dto.setAttributeDTOs(policyAttributeBuilder.getPolicyMetaDataFromRegistryProperties(resource.getProperties()));
return dto;
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project carbon-identity-framework by wso2.
the class EntitlementExtensionBuilder method populateResourceFinders.
/**
* @param properties
* @param holder
* @throws Exception
*/
private void populateResourceFinders(Properties properties, EntitlementConfigHolder holder) throws Exception {
int i = 1;
PIPResourceFinder resource = null;
while (properties.getProperty("PIP.ResourceFinders.Finder." + i) != null) {
String className = properties.getProperty("PIP.ResourceFinders.Finder." + i++);
Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
resource = (PIPResourceFinder) clazz.newInstance();
int j = 1;
Properties resourceProps = new Properties();
while (properties.getProperty(className + "." + j) != null) {
String[] props = properties.getProperty(className + "." + j++).split(",");
resourceProps.put(props[0], props[1]);
}
resource.init(resourceProps);
holder.addResourceFinders(resource, resourceProps);
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource in project carbon-identity-framework by wso2.
the class CarbonEntitlementDataFinder method getChildResources.
/**
* This helps to find resources un a recursive manner
*
* @param node attribute value node
* @param parentResource parent resource Name
* @return child resource set
* @throws RegistryException throws
*/
private EntitlementTreeNodeDTO getChildResources(EntitlementTreeNodeDTO node, String parentResource) throws RegistryException {
if (registry.resourceExists(parentResource)) {
String[] resourcePath = parentResource.split("/");
EntitlementTreeNodeDTO childNode = new EntitlementTreeNodeDTO(resourcePath[resourcePath.length - 1]);
node.addChildNode(childNode);
Resource root = registry.get(parentResource);
if (root instanceof Collection) {
Collection collection = (Collection) root;
String[] resources = collection.getChildren();
for (String resource : resources) {
getChildResources(childNode, resource);
}
}
}
return node;
}
use of org.wso2.carbon.identity.configuration.mgt.core.model.Resource 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.configuration.mgt.core.model.Resource 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);
}
}
Aggregations