Search in sources :

Example 11 with EntitlementException

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());
        }
    }
}
Also used : PolicyDTO(org.wso2.carbon.identity.entitlement.dto.PolicyDTO)

Example 12 with EntitlementException

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);
    }
}
Also used : AbstractPolicy(org.wso2.balana.AbstractPolicy) Policy(org.wso2.balana.Policy) EntitlementException(org.wso2.carbon.identity.entitlement.EntitlementException) PolicyFinderResult(org.wso2.balana.finder.PolicyFinderResult) AbstractPolicy(org.wso2.balana.AbstractPolicy) PolicySet(org.wso2.balana.PolicySet)

Example 13 with EntitlementException

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);
}
Also used : PolicyDTO(org.wso2.carbon.identity.entitlement.dto.PolicyDTO) Resource(org.wso2.carbon.registry.core.Resource)

Example 14 with EntitlementException

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);
    }
}
Also used : EntitlementException(org.wso2.carbon.identity.entitlement.EntitlementException) PolicyDTO(org.wso2.carbon.identity.entitlement.dto.PolicyDTO) AbstractPolicy(org.wso2.balana.AbstractPolicy) PolicyAttributeBuilder(org.wso2.carbon.identity.entitlement.policy.PolicyAttributeBuilder) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 15 with EntitlementException

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);
    }
}
Also used : EntitlementException(org.wso2.carbon.identity.entitlement.EntitlementException)

Aggregations

EntitlementException (org.wso2.carbon.identity.entitlement.EntitlementException)42 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)23 ArrayList (java.util.ArrayList)19 PolicyDTO (org.wso2.carbon.identity.entitlement.dto.PolicyDTO)18 Resource (org.wso2.carbon.registry.core.Resource)18 Registry (org.wso2.carbon.registry.core.Registry)13 Collection (org.wso2.carbon.registry.core.Collection)12 Properties (java.util.Properties)11 AbstractPolicy (org.wso2.balana.AbstractPolicy)9 PolicyPublisher (org.wso2.carbon.identity.entitlement.policy.publisher.PolicyPublisher)9 PolicyStoreDTO (org.wso2.carbon.identity.entitlement.dto.PolicyStoreDTO)7 Map (java.util.Map)6 StatusHolder (org.wso2.carbon.identity.entitlement.dto.StatusHolder)6 PAPPolicyStoreManager (org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStoreManager)6 AttributeDTO (org.wso2.carbon.identity.entitlement.dto.AttributeDTO)5 PAPPolicyStore (org.wso2.carbon.identity.entitlement.pap.store.PAPPolicyStore)5 PolicyAttributeBuilder (org.wso2.carbon.identity.entitlement.policy.PolicyAttributeBuilder)5 PolicyVersionManager (org.wso2.carbon.identity.entitlement.policy.version.PolicyVersionManager)5 CertificateEncodingException (java.security.cert.CertificateEncodingException)4 SignatureException (org.opensaml.xmlsec.signature.support.SignatureException)4