Search in sources :

Example 1 with PAPPolicyStoreReader

use of org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreReader in project carbon-identity-framework by wso2.

the class EntitlementUtil method isPolicyExists.

/**
 * This method checks whether there is a policy having the same policyId as the given policyId is in the registry
 *
 * @param policyId
 * @param registry
 * @return
 * @throws EntitlementException
 */
public static boolean isPolicyExists(String policyId, Registry registry) throws EntitlementException {
    PAPPolicyStoreReader policyReader = null;
    policyReader = new PAPPolicyStoreReader(new PAPPolicyStore(registry));
    return policyReader.isExistPolicy(policyId);
}
Also used : PAPPolicyStoreReader(org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreReader) PAPPolicyStore(org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStore)

Example 2 with PAPPolicyStoreReader

use of org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreReader in project carbon-identity-framework by wso2.

the class EntitlementUtil method addFilesystemPolicy.

/**
 * This method persists a new XACML policy, which was read from filesystem,
 * in the registry
 *
 * @param policyDTO PolicyDTO object
 * @param registry  Registry
 * @param promote   where policy must be promote PDP or not
 * @return returns whether True/False
 * @throws org.wso2.carbon.identity.entitlement.EntitlementException throws if policy with same id is exist
 */
public static boolean addFilesystemPolicy(PolicyDTO policyDTO, Registry registry, boolean promote) throws EntitlementException {
    PAPPolicyStoreManager policyAdmin;
    AbstractPolicy policyObj;
    if (policyDTO.getPolicy() != null) {
        policyDTO.setPolicy(policyDTO.getPolicy().replaceAll(">\\s+<", "><"));
    }
    policyObj = getPolicy(policyDTO.getPolicy());
    if (policyObj != null) {
        PAPPolicyStore policyStore = new PAPPolicyStore(registry);
        policyAdmin = new PAPPolicyStoreManager();
        policyDTO.setPolicyId(policyObj.getId().toASCIIString());
        policyDTO.setActive(true);
        if (isPolicyExists(policyDTO.getPolicyId(), registry)) {
            return false;
        }
        policyDTO.setPromote(promote);
        PolicyVersionManager versionManager = EntitlementAdminEngine.getInstance().getVersionManager();
        try {
            String version = versionManager.createVersion(policyDTO);
            policyDTO.setVersion(version);
        } catch (EntitlementException e) {
            log.error("Policy versioning is not supported", e);
        }
        policyAdmin.addOrUpdatePolicy(policyDTO);
        PAPPolicyStoreReader reader = new PAPPolicyStoreReader(policyStore);
        policyDTO = reader.readPolicyDTO(policyDTO.getPolicyId());
        if (Boolean.parseBoolean(System.getProperty(ENHANCED_XACML_LOADING_SYSTEM_PROPERTY)) && promote) {
            EntitlementAdminEngine adminEngine = EntitlementAdminEngine.getInstance();
            adminEngine.getPolicyStoreManager().addPolicy(policyDTO);
        } else {
            PolicyStoreDTO policyStoreDTO = new PolicyStoreDTO();
            policyStoreDTO.setPolicyId(policyDTO.getPolicyId());
            policyStoreDTO.setPolicy(policyDTO.getPolicy());
            policyStoreDTO.setPolicyOrder(policyDTO.getPolicyOrder());
            policyStoreDTO.setAttributeDTOs(policyDTO.getAttributeDTOs());
            policyStoreDTO.setActive(policyDTO.isActive());
            policyStoreDTO.setSetActive(policyDTO.isActive());
            if (promote) {
                addPolicyToPDP(policyStoreDTO);
            }
            policyAdmin.addOrUpdatePolicy(policyDTO);
        }
        return true;
    } else {
        throw new EntitlementException("Invalid Entitlement Policy");
    }
}
Also used : PolicyStoreDTO(org.wso2.carbon.identity.entitlement.dto.PolicyStoreDTO) PAPPolicyStoreManager(org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreManager) PolicyVersionManager(org.wso2.carbon.identity.entitlement.policy.version.PolicyVersionManager) AbstractPolicy(org.wso2.balana.AbstractPolicy) PAPPolicyStoreReader(org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreReader) EntitlementAdminEngine(org.wso2.carbon.identity.entitlement.pap.EntitlementAdminEngine) PAPPolicyStore(org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStore)

Example 3 with PAPPolicyStoreReader

use of org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreReader in project carbon-identity-framework by wso2.

the class EntitlementUtil method getPolicy.

/**
 * Gets policy dto for a given policy id
 *
 * @param policyId policy id
 * @param registry Registry
 * @return returns policy
 * @throws org.wso2.carbon.identity.entitlement.EntitlementException
 */
public static PolicyDTO getPolicy(String policyId, Registry registry) throws EntitlementException {
    PAPPolicyStoreReader policyReader = null;
    policyReader = new PAPPolicyStoreReader(new PAPPolicyStore(registry));
    return policyReader.readPolicyDTO(policyId);
}
Also used : PAPPolicyStoreReader(org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreReader) PAPPolicyStore(org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStore)

Example 4 with PAPPolicyStoreReader

use of org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreReader in project carbon-identity-framework by wso2.

the class DefaultPolicyVersionManager method getPolicy.

@Override
public PolicyDTO getPolicy(String policyId, String version) throws EntitlementException {
    // Zero means current version
    if (version == null || version.trim().length() == 0) {
        Registry registry = EntitlementServiceComponent.getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId());
        try {
            Collection collection = (Collection) registry.get(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId);
            if (collection != null) {
                version = collection.getProperty("version");
            }
        } catch (RegistryException e) {
            log.error(e);
            throw new EntitlementException("Invalid policy version");
        }
    }
    PAPPolicyStore policyStore = new PAPPolicyStore();
    PAPPolicyStoreReader reader = new PAPPolicyStoreReader(policyStore);
    Resource resource = policyStore.getPolicy(version, PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId + RegistryConstants.PATH_SEPARATOR);
    if (resource == null) {
        throw new EntitlementException("Invalid policy version");
    }
    return reader.readPolicyDTO(resource);
}
Also used : EntitlementException(org.wso2.carbon.identity.entitlement.EntitlementException) PAPPolicyStoreReader(org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreReader) Resource(org.wso2.carbon.registry.core.Resource) Collection(org.wso2.carbon.registry.api.Collection) Registry(org.wso2.carbon.registry.api.Registry) PAPPolicyStore(org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStore) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Aggregations

PAPPolicyStore (org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStore)4 PAPPolicyStoreReader (org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreReader)4 AbstractPolicy (org.wso2.balana.AbstractPolicy)1 EntitlementException (org.wso2.carbon.identity.entitlement.EntitlementException)1 PolicyStoreDTO (org.wso2.carbon.identity.entitlement.dto.PolicyStoreDTO)1 EntitlementAdminEngine (org.wso2.carbon.identity.entitlement.pap.EntitlementAdminEngine)1 PAPPolicyStoreManager (org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreManager)1 PolicyVersionManager (org.wso2.carbon.identity.entitlement.policy.version.PolicyVersionManager)1 Collection (org.wso2.carbon.registry.api.Collection)1 Registry (org.wso2.carbon.registry.api.Registry)1 RegistryException (org.wso2.carbon.registry.api.RegistryException)1 Resource (org.wso2.carbon.registry.core.Resource)1