/** * * This method provides a secured document builder which will secure XXE attacks. * * @return DocumentBuilder * @throws ParserConfigurationException */ private DocumentBuilder getSecuredDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder; }
/** * * This method provides a secured document builder which will secure XXE attacks. * * @return DocumentBuilder * @throws ParserConfigurationException */ private DocumentBuilder getSecuredDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder; } }
/** * * This method provides a secured document builder which will secure XXE attacks. * * @return DocumentBuilder * @throws ParserConfigurationException */ private DocumentBuilder getSecuredDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder; }
/** * * This method provides a secured document builder which will secure XXE attacks. * * @return DocumentBuilder * @throws ParserConfigurationException */ private DocumentBuilder getSecuredDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder; }
/** * * This method provides a secured document builder which will secure XXE attacks. * * @return DocumentBuilder * @throws ParserConfigurationException */ private DocumentBuilder getSecuredDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder; } }
/** * * This method provides a secured document builder which will secure XXE attacks. * * @param setIgnoreComments whether to set setIgnoringComments in DocumentBuilderFactory. * @return DocumentBuilder * @throws ParserConfigurationException */ private static DocumentBuilder getSecuredDocumentBuilder(boolean setIgnoreComments) throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory(); documentBuilderFactory.setIgnoringComments(setIgnoreComments); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder; } }
private PolicyReader(PolicyFinder policyFinder) { this.policyFinder = policyFinder; // create the factory DocumentBuilderFactory factory = IdentityUtil.getSecuredDocumentBuilderFactory(); factory.setIgnoringComments(true); // now use the factory to create the document builder try { builder = factory.newDocumentBuilder(); builder.setErrorHandler(this); } catch (ParserConfigurationException pce) { throw new IllegalArgumentException("Filed to setup repository: "); } }
private PolicyReader(PolicyFinder policyFinder) { this.policyFinder = policyFinder; // create the factory DocumentBuilderFactory factory = IdentityUtil.getSecuredDocumentBuilderFactory(); factory.setIgnoringComments(true); // now use the factory to create the document builder try { builder = factory.newDocumentBuilder(); builder.setErrorHandler(this); } catch (ParserConfigurationException pce) { throw new IllegalArgumentException("Filed to setup repository: "); } }
private PAPPolicyReader(PolicyFinder policyFinder) { this.policyFinder = policyFinder; // create the factory DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory(); documentBuilderFactory.setIgnoringComments(true); // now use the factory to create the document builder try { builder = documentBuilderFactory.newDocumentBuilder(); builder.setErrorHandler(this); } catch (ParserConfigurationException pce) { throw new IllegalArgumentException("Failed to create the DocumentBuilder. : ", pce); } }
/** * * This method provides a secured document builder which will secure XXE attacks. * * @param setIgnoreComments whether to set setIgnoringComments in DocumentBuilderFactory. * @return DocumentBuilder * @throws ParserConfigurationException */ private static DocumentBuilder getSecuredDocumentBuilder(boolean setIgnoreComments) throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory(); documentBuilderFactory.setIgnoringComments(setIgnoreComments); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder; } }
/** * * This method provides a secured document builder which will secure XXE attacks. * * @param setIgnoreComments whether to set setIgnoringComments in DocumentBuilderFactory. * @return DocumentBuilder * @throws ParserConfigurationException */ private static DocumentBuilder getSecuredDocumentBuilder(boolean setIgnoreComments) throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory(); documentBuilderFactory.setIgnoringComments(setIgnoreComments); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder; } }
private PolicyReader(PolicyFinder policyFinder) { this.policyFinder = policyFinder; // create the factory DocumentBuilderFactory factory = IdentityUtil.getSecuredDocumentBuilderFactory(); factory.setIgnoringComments(true); // now use the factory to create the document builder try { builder = factory.newDocumentBuilder(); builder.setErrorHandler(this); } catch (ParserConfigurationException pce) { throw new IllegalArgumentException("Filed to setup repository: "); } }
private PAPPolicyReader(PolicyFinder policyFinder) { this.policyFinder = policyFinder; // create the factory DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory(); documentBuilderFactory.setIgnoringComments(true); // now use the factory to create the document builder try { builder = documentBuilderFactory.newDocumentBuilder(); builder.setErrorHandler(this); } catch (ParserConfigurationException pce) { throw new IllegalArgumentException("Failed to create the DocumentBuilder. : ", pce); } }
private PAPPolicyReader(PolicyFinder policyFinder) { this.policyFinder = policyFinder; // create the factory DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory(); documentBuilderFactory.setIgnoringComments(true); // now use the factory to create the document builder try { builder = documentBuilderFactory.newDocumentBuilder(); builder.setErrorHandler(this); } catch (ParserConfigurationException pce) { throw new IllegalArgumentException("Failed to create the DocumentBuilder. : ", pce); } }
public static Element decryptToken(String token) throws Exception { ByteArrayInputStream bais = new ByteArrayInputStream(token.getBytes()); DocumentBuilderFactory dbf = IdentityUtil.getSecuredDocumentBuilderFactory(); Document doc = dbf.newDocumentBuilder().parse(bais); Element encryptedTokenElem = doc.getDocumentElement(); // Decrypt element return TokenDecrypter.decryptElement(encryptedTokenElem); }
public static Element decryptToken(String token) throws Exception { ByteArrayInputStream bais = new ByteArrayInputStream(token.getBytes()); DocumentBuilderFactory dbf = IdentityUtil.getSecuredDocumentBuilderFactory(); Document doc = dbf.newDocumentBuilder().parse(bais); Element encryptedTokenElem = doc.getDocumentElement(); // Decrypt element return TokenDecrypter.decryptElement(encryptedTokenElem); }
private boolean evaluateXACMLResponse(String xacmlResponse) throws IdentityProvisioningException { try { DocumentBuilderFactory documentBuilderFactory = IdentityUtil.getSecuredDocumentBuilderFactory(); DocumentBuilder db = documentBuilderFactory.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xacmlResponse)); Document doc = db.parse(is); String decision = ""; NodeList decisionNode = doc.getDocumentElement().getElementsByTagName( ProvisioningRuleConstanats.XACML_RESPONSE_DECISION_NODE); if (decisionNode != null && decisionNode.item(0) != null) { decision = decisionNode.item(0).getTextContent(); } if (decision.equalsIgnoreCase(EntitlementPolicyConstants.RULE_EFFECT_PERMIT) || decision.equalsIgnoreCase(EntitlementPolicyConstants.RULE_EFFECT_NOT_APPLICABLE)) { return true; } } catch (ParserConfigurationException | SAXException | IOException e) { throw new IdentityProvisioningException("Exception occurred while xacmlResponse processing", e); } return false; }
/** * 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.base.IdentityException */ public static XMLObject unmarshall(String xmlString) throws IdentityException { try { DocumentBuilderFactory documentBuilderFactory = getSecuredDocumentBuilderFactory(); DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = docBuilder.parse(new ByteArrayInputStream(xmlString.trim().getBytes(Charsets.UTF_8))); Element element = document.getDocumentElement(); UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element); return unmarshaller.unmarshall(element); } catch (ParserConfigurationException | UnmarshallingException | SAXException | IOException e) { String message = "Error in constructing XML Object from the encoded String"; throw IdentityException.error(message, e); } }
/** * 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 = Configuration.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); } }
/** * Convert metadata String to entityDescriptor * * @param metadataString * @return EntityDescriptor */ private static EntityDescriptor generateMetadataObjectFromString(String metadataString) throws IdentityApplicationManagementException { EntityDescriptor entityDescriptor = null; try { DocumentBuilderFactory factory = IdentityUtil.getSecuredDocumentBuilderFactory(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new ByteArrayInputStream(metadataString.getBytes())); Element node = document.getDocumentElement(); DOMMetadataProvider idpMetaDataProvider = new DOMMetadataProvider(node); idpMetaDataProvider.setRequireValidMetadata(true); idpMetaDataProvider.setParserPool(new BasicParserPool()); idpMetaDataProvider.initialize(); XMLObject xmlObject = idpMetaDataProvider.getMetadata(); entityDescriptor = (EntityDescriptor) xmlObject; } catch (MetadataProviderException | SAXException | ParserConfigurationException | IOException e) { throw new IdentityApplicationManagementException("Error while converting file content to entity descriptor"); } return entityDescriptor; }