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()]);
}
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;
}
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);
}
}
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);
}
}
Aggregations