Search in sources :

Example 86 with EntitlementException

use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.

the class DefaultPolicyVersionManager method getVersions.

@Override
public String[] getVersions(String policyId) throws EntitlementException {
    List<String> versions = new ArrayList<String>();
    Registry registry = EntitlementServiceComponent.getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId());
    Collection collection = null;
    try {
        try {
            collection = (Collection) registry.get(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId);
        } catch (ResourceNotFoundException e) {
        // ignore
        }
        if (collection != null && collection.getChildren() != null) {
            String[] children = collection.getChildren();
            for (String child : children) {
                versions.add(RegistryUtils.getResourceName(child));
            }
        }
    } catch (RegistryException e) {
        log.error("Error while creating new version of policy", e);
    }
    return versions.toArray(new String[versions.size()]);
}
Also used : ArrayList(java.util.ArrayList) Collection(org.wso2.carbon.registry.api.Collection) Registry(org.wso2.carbon.registry.api.Registry) ResourceNotFoundException(org.wso2.carbon.registry.core.exceptions.ResourceNotFoundException) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 87 with EntitlementException

use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.

the class PolicyAttributeBuilder method createPolicyMetaData.

/**
 * This creates the OMElement from the policy xml and create the the meta data for hole policy
 *
 * @param policy        policy as a String
 * @param attributeDTOs object which holds the policy meta data in String format
 * @return list of AttributeDTO object which holds the policy meta data in String format
 * @throws EntitlementException throws if OMElement can not be created
 */
public List<AttributeDTO> createPolicyMetaData(String policy, List<AttributeDTO> attributeDTOs) throws EntitlementException {
    OMElement omElement;
    try {
        omElement = AXIOMUtil.stringToOM(policy);
    } catch (XMLStreamException e) {
        throw new EntitlementException("Policy xml can not be converted to OMElement");
    }
    if (omElement != null) {
        Iterator iterator1 = omElement.getChildrenWithLocalName(PDPConstants.TARGET_ELEMENT);
        while (iterator1.hasNext()) {
            OMElement targetElement = (OMElement) iterator1.next();
            if (version == XACMLConstants.XACML_VERSION_3_0) {
                createMetaDataFromXACML3TargetElement(targetElement, attributeDTOs);
            } else {
                createMetaDataFromTargetElement(targetElement, attributeDTOs);
            }
        }
        Iterator iterator2 = omElement.getChildrenWithLocalName(PDPConstants.RULE_ELEMENT);
        while (iterator2.hasNext()) {
            OMElement targetElement = (OMElement) iterator2.next();
            createMetaDataFromRuleElement(targetElement, attributeDTOs);
        }
        Iterator iterator3 = omElement.getChildrenWithLocalName(PDPConstants.POLICY_ELEMENT);
        while (iterator3.hasNext()) {
            OMElement targetElement = (OMElement) iterator3.next();
            createPolicyMetaData(targetElement.toString(), attributeDTOs);
        }
    }
    return attributeDTOs;
}
Also used : EntitlementException(org.wso2.carbon.identity.entitlement.EntitlementException) XMLStreamException(javax.xml.stream.XMLStreamException) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement)

Example 88 with EntitlementException

use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.

the class WSXACMLMessageReceiver method marshall.

/**
 * `
 * Serialize XML objects
 *
 * @param xmlObject : XACML or SAML objects to be serialized
 * @return serialized XACML or SAML objects
 * @throws EntitlementException
 */
private String marshall(XMLObject xmlObject) throws EntitlementException {
    try {
        doBootstrap();
        System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
        MarshallerFactory marshallerFactory = XMLObjectProviderRegistrySupport.getMarshallerFactory();
        Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
        Element element = marshaller.marshall(xmlObject);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = impl.createLSSerializer();
        LSOutput output = impl.createLSOutput();
        output.setByteStream(byteArrayOutputStream);
        writer.write(element, output);
        return byteArrayOutputStream.toString();
    } catch (Exception e) {
        log.error("Error Serializing the SAML Response");
        throw new EntitlementException("Error Serializing the SAML Response", e);
    }
}
Also used : MarshallerFactory(org.opensaml.core.xml.io.MarshallerFactory) EntitlementException(org.wso2.carbon.identity.entitlement.EntitlementException) Marshaller(org.opensaml.core.xml.io.Marshaller) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) DOMImplementationLS(org.w3c.dom.ls.DOMImplementationLS) DOMImplementationRegistry(org.w3c.dom.bootstrap.DOMImplementationRegistry) LSSerializer(org.w3c.dom.ls.LSSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LSOutput(org.w3c.dom.ls.LSOutput) SignatureException(org.opensaml.xmlsec.signature.support.SignatureException) CertificateEncodingException(java.security.cert.CertificateEncodingException) EntitlementException(org.wso2.carbon.identity.entitlement.EntitlementException)

Example 89 with EntitlementException

use of org.wso2.carbon.identity.entitlement.EntitlementException in project carbon-identity-framework by wso2.

the class WSXACMLMessageReceiver method unmarshall.

/**
 * Constructing the SAML or XACML Objects from a String
 *
 * @param xmlString Decoded SAML or XACML String
 * @return SAML or XACML Object
 * @throws org.wso2.carbon.identity.entitlement.EntitlementException
 */
public XMLObject unmarshall(String xmlString) throws EntitlementException {
    try {
        doBootstrap();
        DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory();
        DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = docBuilder.parse(new ByteArrayInputStream(xmlString.trim().getBytes()));
        Element element = document.getDocumentElement();
        UnmarshallerFactory unmarshallerFactory = XMLObjectProviderRegistrySupport.getUnmarshallerFactory();
        Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
        return unmarshaller.unmarshall(element);
    } catch (Exception e) {
        log.error("Error in constructing XML(SAML or XACML) Object from the encoded String", e);
        throw new EntitlementException("Error in constructing XML(SAML or XACML) from the encoded String ", e);
    }
}
Also used : EntitlementException(org.wso2.carbon.identity.entitlement.EntitlementException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) UnmarshallerFactory(org.opensaml.core.xml.io.UnmarshallerFactory) Document(org.w3c.dom.Document) Unmarshaller(org.opensaml.core.xml.io.Unmarshaller) SignatureException(org.opensaml.xmlsec.signature.support.SignatureException) CertificateEncodingException(java.security.cert.CertificateEncodingException) 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