List of usage examples for org.w3c.dom Node setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:org.wso2.developerstudio.eclipse.qos.project.ui.dashboard.QoSDashboardPage.java
private Map<String, String> setRampartConfig() { if (!kerberossignandencrypt) { Node user = rampart.getElementsByTagName(RAMPART_USER).item(0); if (user != null) { user.setTextContent(configMap.get(RAMPART_USER)); }/*from ww w.ja va2 s .c om*/ Node encryptionUser = rampart.getElementsByTagName(RAMPART_ENCRYPTION_USER).item(0); if (encryptionUser != null && StringUtils.isNotBlank(configMap.get(RAMPART_ENCRYPTION_USER))) { encryptionUser.setTextContent(configMap.get(RAMPART_ENCRYPTION_USER)); } } Node timestampPrecisionInMilliseconds = rampart .getElementsByTagName(RAMPART_TIMESTAMP_PRECISION_IN_MILLISECONDS).item(0); if (timestampPrecisionInMilliseconds != null && StringUtils.isNotBlank(configMap.get(RAMPART_TIMESTAMP_PRECISION_IN_MILLISECONDS))) { timestampPrecisionInMilliseconds .setTextContent(configMap.get(RAMPART_TIMESTAMP_PRECISION_IN_MILLISECONDS)); } Node timestampTTL = rampart.getElementsByTagName(RAMPART_TIMESTAMP_TTL).item(0); if (timestampTTL != null && StringUtils.isNotBlank(configMap.get(RAMPART_TIMESTAMP_TTL))) { timestampTTL.setTextContent(configMap.get(RAMPART_TIMESTAMP_TTL)); } Node timestampMaxSkew = rampart.getElementsByTagName(RAMPART_TIMESTAMP_MAX_SKEW).item(0); if (timestampMaxSkew != null && StringUtils.isNotBlank(configMap.get(RAMPART_TIMESTAMP_MAX_SKEW))) { timestampMaxSkew.setTextContent(configMap.get(RAMPART_TIMESTAMP_MAX_SKEW)); } Node timestampStrict = rampart.getElementsByTagName(RAMPART_TIMESTAMP_STRICT).item(0); if (timestampStrict != null && StringUtils.isNotBlank(configMap.get(RAMPART_TIMESTAMP_STRICT))) { timestampStrict.setTextContent(configMap.get(RAMPART_TIMESTAMP_STRICT)); } if (!kerberossignandencrypt) { Node tokenStoreClass = rampart.getElementsByTagName(RAMPART_TOKEN_STORE_CLASS).item(0); tokenStoreClass.setTextContent(configMap.get(RAMPART_TOKEN_STORE_CLASS)); } Node nonceLifeTime = rampart.getElementsByTagName(RAMPART_NONCE_LIFE_TIME).item(0); if (nonceLifeTime != null && StringUtils.isNotBlank(configMap.get(RAMPART_NONCE_LIFE_TIME))) { nonceLifeTime.setTextContent(configMap.get(RAMPART_NONCE_LIFE_TIME)); } if (!kerberossignandencrypt) { Node encryptionCrypto = rampart.getElementsByTagName("rampart:encryptionCrypto").item(0); if (encryptionCrypto != null) { setenCryto(encryptionCrypto); } Node signatureCrypto = rampart.getElementsByTagName("rampart:signatureCrypto").item(0); if (signatureCrypto != null) { setenCryto(signatureCrypto); } } else { Node kerberosConfig = rampart.getElementsByTagName("rampart:kerberosConfig").item(0); if (kerberosConfig != null) { setKerberosConfig(kerberosConfig); } } return configMap; }
From source file:org.wso2.developerstudio.eclipse.qos.project.ui.dashboard.QoSDashboardPage.java
private void setenCryto(Node encryptionCrypto) { Node encrypto = ((Element) encryptionCrypto).getElementsByTagName("rampart:crypto").item(0); NodeList list = ((Element) encrypto).getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node != null && "rampart:property".equals(node.getNodeName())) { Element eElement = (Element) node; String attribute = eElement.getAttribute("name"); if (StringUtils.isNotBlank(attribute)) { node.setTextContent(configMap.get(attribute)); }// w w w. j ava2 s .c o m } } }
From source file:org.wso2.developerstudio.eclipse.qos.project.ui.dashboard.QoSDashboardPage.java
private void setKerberosConfig(Node kerberosConfig) { NodeList list = ((Element) kerberosConfig).getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node != null && "rampart:property".equals(node.getNodeName())) { Element eElement = (Element) node; String attribute = eElement.getAttribute("name"); if (StringUtils.isNotBlank(attribute)) { node.setTextContent(configMap.get(attribute)); }/*from w w w .jav a 2 s . c om*/ } } }
From source file:org.wso2.developerstudio.eclipse.security.project.ui.form.SecurityFormPage.java
/** * Updates the source with changes// w w w .j a va2 s . c o m * * @throws ParserConfigurationException * @throws IOException * @throws SAXException */ private void updateSourceConfiguration() throws ParserConfigurationException, SAXException, IOException { boolean isKerberosAuthenticationScenario = SecurityPolicies.POLICY_TYPE_16.equals(selectedPolicy); Node rampartConfigNode = policyFileDOMDocument.getElementsByTagName(SecurityFormConstants.RAMPART_CONFIG) .item(0); Element rampartConfigElement = (Element) rampartConfigNode; Node securityConfigNode = policyFileDOMDocument.getElementsByTagName(SecurityFormConstants.CARBONSEC_CONFIG) .item(0); Element securityConfigElement = (Element) securityConfigNode; if (!isKerberosAuthenticationScenario) { Node userNode = rampartConfigElement.getElementsByTagName(SecurityFormConstants.RAMPART_USER).item(0); String userValue = rampartConfigDataMap.get(SecurityFormConstants.RAMPART_USER); updateXMLNodeValue(userNode, userValue, policyFileDOMDocument, rampartConfigElement, SecurityFormConstants.RAMPART_USER); Node encryptionUserNode = rampartConfigElement .getElementsByTagName(SecurityFormConstants.RAMPART_ENCRYPTION_USER).item(0); String encryptionUserValue = rampartConfigDataMap.get(SecurityFormConstants.RAMPART_ENCRYPTION_USER); updateXMLNodeValue(encryptionUserNode, encryptionUserValue, policyFileDOMDocument, rampartConfigElement, SecurityFormConstants.RAMPART_ENCRYPTION_USER); } Node timestampPrecisionInMSNode = rampartConfigElement .getElementsByTagName(SecurityFormConstants.RAMPART_TIMESTAMP_PRECISION_IN_MILLISECONDS).item(0); String timestampPrecisionInMSValue = rampartConfigDataMap .get(SecurityFormConstants.RAMPART_TIMESTAMP_PRECISION_IN_MILLISECONDS); updateXMLNodeValue(timestampPrecisionInMSNode, timestampPrecisionInMSValue, policyFileDOMDocument, rampartConfigElement, SecurityFormConstants.RAMPART_TIMESTAMP_PRECISION_IN_MILLISECONDS); Node timestampTTLNode = rampartConfigElement .getElementsByTagName(SecurityFormConstants.RAMPART_TIMESTAMP_TTL).item(0); String timestampTTLValue = rampartConfigDataMap.get(SecurityFormConstants.RAMPART_TIMESTAMP_TTL); updateXMLNodeValue(timestampTTLNode, timestampTTLValue, policyFileDOMDocument, rampartConfigElement, SecurityFormConstants.RAMPART_TIMESTAMP_TTL); Node timestampMaxSkewNode = rampartConfigElement .getElementsByTagName(SecurityFormConstants.RAMPART_TIMESTAMP_MAX_SKEW).item(0); String timestampMaxSkewValue = rampartConfigDataMap.get(SecurityFormConstants.RAMPART_TIMESTAMP_MAX_SKEW); updateXMLNodeValue(timestampMaxSkewNode, timestampMaxSkewValue, policyFileDOMDocument, rampartConfigElement, SecurityFormConstants.RAMPART_TIMESTAMP_MAX_SKEW); Node timestampStrictNode = rampartConfigElement .getElementsByTagName(SecurityFormConstants.RAMPART_TIMESTAMP_STRICT).item(0); String timestampStrictValue = rampartConfigDataMap.get(SecurityFormConstants.RAMPART_TIMESTAMP_STRICT); updateXMLNodeValue(timestampStrictNode, timestampStrictValue, policyFileDOMDocument, rampartConfigElement, SecurityFormConstants.RAMPART_TIMESTAMP_STRICT); if (!isKerberosAuthenticationScenario) { Node tokenStoreClassNode = rampartConfigElement .getElementsByTagName(SecurityFormConstants.RAMPART_TOKEN_STORE_CLASS).item(0); String tokenStoreClassValue = rampartConfigDataMap.get(SecurityFormConstants.RAMPART_TOKEN_STORE_CLASS); updateXMLNodeValue(tokenStoreClassNode, tokenStoreClassValue, policyFileDOMDocument, rampartConfigElement, SecurityFormConstants.RAMPART_TOKEN_STORE_CLASS); } Node nonceLifeTimeNode = rampartConfigElement .getElementsByTagName(SecurityFormConstants.RAMPART_NONCE_LIFE_TIME).item(0); String nonceLifeTimeNodeValue = rampartConfigDataMap.get(SecurityFormConstants.RAMPART_NONCE_LIFE_TIME); updateXMLNodeValue(nonceLifeTimeNode, nonceLifeTimeNodeValue, policyFileDOMDocument, rampartConfigElement, SecurityFormConstants.RAMPART_NONCE_LIFE_TIME); if (!isKerberosAuthenticationScenario) { Node encryptionCryptoNode = rampartConfigElement .getElementsByTagName(SecurityFormConstants.RAMPART_ENCRYPTION_CRYPTO).item(0); if (encryptionCryptoNode != null) { setEncryptionCrypto(encryptionCryptoNode, encryptionPropertiesDataMap); } Node signatureCryptoNode = rampartConfigElement .getElementsByTagName(SecurityFormConstants.RAMPART_SIGNATURE_CRYPTO).item(0); if (signatureCryptoNode != null) { setSignatureCrypto(signatureCryptoNode, signaturePropertiesDataMap); } } else { Node kerberosConfigNode = rampartConfigElement .getElementsByTagName(SecurityFormConstants.RAMPART_KERBEROS_CONFIG).item(0); if (kerberosConfigNode != null) { setKerberosRampartConfig(kerberosConfigNode, kerberosPropertiesDataMap); } if (securityConfigElement != null) { Node kerberosSec = securityConfigElement.getElementsByTagName(SecurityFormConstants.CARBON_KEBEROS) .item(0); if (kerberosSec != null) { setKerberosSecConfig(kerberosSec, kerberosPropertiesDataMap); } } } if (SecurityPolicyUtils.getInstance().getUserRoleRequiredSecurityScenarios().contains(selectedPolicy)) { if (securityConfigElement != null) { Node securityAuth = securityConfigElement .getElementsByTagName(SecurityFormConstants.CARBONSEC_AUTHORIZATION).item(0); if (securityAuth != null) { setSecAuthorization(securityAuth, carbonSecAuthDataMap); } } else { if (StringUtils.isNotEmpty( carbonSecAuthControlMap.get(SecurityFormConstants.ORG_WSO2_CARBON_SECURITY_ALLOWEDROLES))) { Node wsPolicyNode = policyFileDOMDocument.getElementsByTagName(SecurityFormConstants.WS_POLICY) .item(0); securityConfigElement = policyFileDOMDocument .createElement(SecurityFormConstants.CARBONSEC_CONFIG); securityConfigElement.setAttribute(SecurityFormConstants.XML_NS_SEC, SecurityFormConstants.XML_NS_SEC_ATTRIBUTE); wsPolicyNode.appendChild(securityConfigElement); Node carbonAuthNode = policyFileDOMDocument .createElement(SecurityFormConstants.CARBONSEC_AUTHORIZATION); securityConfigElement.appendChild(carbonAuthNode); Node secPropertyNode = policyFileDOMDocument .createElement(SecurityFormConstants.CARBONSEC_PROPERTY); ((Element) secPropertyNode).setAttribute(SecurityFormConstants.PROPERTY_NAME, SecurityFormConstants.ORG_WSO2_CARBON_SECURITY_ALLOWEDROLES); carbonAuthNode.appendChild(secPropertyNode); secPropertyNode.setTextContent(carbonSecAuthControlMap .get(SecurityFormConstants.ORG_WSO2_CARBON_SECURITY_ALLOWEDROLES)); } } } if (SecurityPolicyUtils.getInstance().getSecurityTrustRequiredSecurityScenarios() .contains(selectedPolicy)) { if (securityConfigElement != null) { Node securityTrustNode = securityConfigElement .getElementsByTagName(SecurityFormConstants.CARBONSEC_TRUST).item(0); if (securityTrustNode != null) { setSecTrust(securityTrustNode, carbonSecTrustDataMap); } } } }
From source file:org.wso2.developerstudio.eclipse.security.project.ui.form.SecurityFormPage.java
/** * This method is to update a XML node value *///from ww w.j av a 2 s .co m private void updateXMLNodeValue(Node node, String value, Document document, Element parentNode, String nodeName) { if (node != null && StringUtils.isNotEmpty(value)) { node.setTextContent(value); } else if (node == null && StringUtils.isNotEmpty(value)) { createXMLNode(document, parentNode, nodeName, value); } else if (node != null && StringUtils.isEmpty(value)) { node.getParentNode().removeChild(node); } }
From source file:org.wso2.developerstudio.eclipse.security.project.ui.form.SecurityFormPage.java
/** * Sets the encryption/*from w w w .j av a 2 s .co m*/ * * @param encryptionCrypto node encrypto * @param cryptoMap map */ private void setEncryptionCrypto(Node encryptionCrypto, Map<String, String> cryptoMap) { Node rampartCryptoProperties = ((Element) encryptionCrypto) .getElementsByTagName(SecurityFormConstants.RAMPART_CRYPTO).item(0); NodeList list = rampartCryptoProperties.getChildNodes(); boolean isPrivateStoreEmpty = false; boolean isTrustStoreEmpty = false; for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (SecurityFormConstants.RAMPART_PROPERTY.equals(node.getNodeName())) { Element eElement = (Element) node; String attribute = eElement.getAttribute(SecurityFormConstants.PROPERTY_NAME); if (StringUtils.isNotBlank(attribute)) { node.setTextContent(cryptoMap.get(attribute)); } if (attribute.equals(SecurityFormConstants.ORG_WSO2_CARBON_SECURITY_CRYPTO_PRIVATESTORE) && StringUtils.isEmpty(cryptoMap .get(SecurityFormConstants.ORG_WSO2_CARBON_SECURITY_CRYPTO_PRIVATESTORE))) { isPrivateStoreEmpty = true; } else if (attribute.equals(SecurityFormConstants.ORG_WSO2_CARBON_SECURITY_CRYPTO_TRUSTSTORES) && StringUtils.isEmpty( cryptoMap.get(SecurityFormConstants.ORG_WSO2_CARBON_SECURITY_CRYPTO_TRUSTSTORES))) { isTrustStoreEmpty = true; } } } //Showing warnings if private store or trust store is empty if (isPrivateStoreEmpty && isTrustStoreEmpty) { MessageBox msgBox = new MessageBox(getSite().getShell(), SWT.ICON_WARNING); msgBox.setMessage(SecurityFormMessageConstants.MESSAGE_EN_PROPERTIES); msgBox.open(); } else if (isPrivateStoreEmpty) { MessageBox msgBox = new MessageBox(getSite().getShell(), SWT.ICON_WARNING); msgBox.setMessage(SecurityFormMessageConstants.MESSAGE_PRIVATESTORE_EN); msgBox.open(); } else if (isTrustStoreEmpty) { MessageBox msgBox = new MessageBox(getSite().getShell(), SWT.ICON_WARNING); msgBox.setMessage(SecurityFormMessageConstants.MESSAGE_TRUSTSTORE_EN); msgBox.open(); } }
From source file:org.wso2.developerstudio.eclipse.security.project.ui.form.SecurityFormPage.java
/** * Sets the encryption sign value/*w w w . j a v a2 s . c o m*/ * * @param encryptionCrypto node encrypto * @param cryptoMap map */ private void setSignatureCrypto(Node encryptionCrypto, Map<String, String> cryptoMap) { Node rampartCryptoProperties = ((Element) encryptionCrypto) .getElementsByTagName(SecurityFormConstants.RAMPART_CRYPTO).item(0); NodeList list = rampartCryptoProperties.getChildNodes(); boolean isPrivateStoreEmpty = false; boolean isTrustStoreEmpty = false; for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node != null && SecurityFormConstants.RAMPART_PROPERTY.equals(node.getNodeName())) { Element eElement = (Element) node; String attribute = eElement.getAttribute(SecurityFormConstants.PROPERTY_NAME); if (StringUtils.isNotBlank(attribute)) { node.setTextContent(cryptoMap.get(attribute)); } if (attribute.equals(SecurityFormConstants.ORG_WSO2_CARBON_SECURITY_CRYPTO_PRIVATESTORE) && StringUtils.isEmpty(cryptoMap .get(SecurityFormConstants.ORG_WSO2_CARBON_SECURITY_CRYPTO_PRIVATESTORE))) { isPrivateStoreEmpty = true; } if (attribute.equals(SecurityFormConstants.ORG_WSO2_CARBON_SECURITY_CRYPTO_TRUSTSTORES) && StringUtils.isEmpty( cryptoMap.get(SecurityFormConstants.ORG_WSO2_CARBON_SECURITY_CRYPTO_TRUSTSTORES))) { isTrustStoreEmpty = true; } } } //Showing warnings if private store or trust store is empty if (isPrivateStoreEmpty && isTrustStoreEmpty) { MessageBox msgBox = new MessageBox(getSite().getShell(), SWT.ICON_WARNING); msgBox.setMessage(SecurityFormMessageConstants.MESSAGE_SIGN_PROPERTIES); msgBox.open(); } else if (isPrivateStoreEmpty) { MessageBox msgBox = new MessageBox(getSite().getShell(), SWT.ICON_WARNING); msgBox.setMessage(SecurityFormMessageConstants.MESSAGE_PRIVATESTORE_SIGN); msgBox.open(); } else if (isTrustStoreEmpty) { MessageBox msgBox = new MessageBox(getSite().getShell(), SWT.ICON_WARNING); msgBox.setMessage(SecurityFormMessageConstants.MESSAGE_TRUSTSTORE_SIGN); msgBox.open(); } }
From source file:org.wso2.developerstudio.eclipse.security.project.ui.form.SecurityFormPage.java
/** * Sets the security authorization/* w ww . j a v a 2 s . c om*/ * * @param carbonSecurity node carbonSecurity * @param carbonAuthMap map */ private void setSecAuthorization(Node carbonSecurity, Map<String, String> carbonAuthMap) { NodeList list = carbonSecurity.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node != null && SecurityFormConstants.CARBONSEC_PROPERTY.equals(node.getNodeName())) { Element eElement = (Element) node; String attribute = eElement.getAttribute(SecurityFormConstants.PROPERTY_NAME); if (StringUtils.isNotBlank(attribute)) { if (StringUtils.isNotEmpty(carbonAuthMap.get(attribute))) { node.setTextContent(carbonAuthMap.get(attribute)); } else { // Remove the sec: tag when User Role value is empty if (SecurityPolicies.POLICY_TYPE_14.equals(selectedPolicy) || SecurityPolicies.POLICY_TYPE_15.equals(selectedPolicy)) { node.getParentNode().getParentNode().removeChild(carbonSecurity); } else { node.getParentNode().getParentNode().getParentNode() .removeChild(carbonSecurity.getParentNode()); } } } } } }
From source file:org.wso2.developerstudio.eclipse.security.project.ui.form.SecurityFormPage.java
/** * Sets the security trust/*from w w w . j a v a2 s . c om*/ * * @param carbonTrust node carbonTrust * @param carbonTrustMap map */ private void setSecTrust(Node carbonTrust, Map<String, String> carbonTrustMap) { NodeList list = carbonTrust.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node != null && SecurityFormConstants.CARBONSEC_PROPERTY.equals(node.getNodeName())) { Element eElement = (Element) node; String attribute = eElement.getAttribute(SecurityFormConstants.PROPERTY_NAME); if (StringUtils.isNotBlank(attribute)) { node.setTextContent(carbonTrustMap.get(attribute)); } } } }
From source file:org.wso2.developerstudio.eclipse.security.project.ui.form.SecurityFormPage.java
/** * Sets the security trust//w w w.j a va 2 s . com */ private void setKerberosSecConfig(Node carbonKerberos, Map<String, String> carbonKerberosMap) { NodeList list = carbonKerberos.getChildNodes(); boolean isPasswordEmpty = false; boolean isPrincipalNameEmpty = false; for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node != null && SecurityFormConstants.CARBONSEC_PROPERTY.equals(node.getNodeName())) { Element eElement = (Element) node; String attribute = eElement.getAttribute(SecurityFormConstants.PROPERTY_NAME); if (StringUtils.isNotBlank(attribute)) { if (StringUtils.isNotEmpty(carbonKerberosMap.get(attribute))) { node.setTextContent(carbonKerberosMap.get(attribute)); } else { if (attribute.equals(SecurityFormConstants.SERVICE_PRINCIPAL_NAME)) { isPrincipalNameEmpty = true; } if (attribute.equals(SecurityFormConstants.SERVICE_PRINCIPAL_PASSWORD)) { isPasswordEmpty = true; } } } } } //Showing warnings if principal name or password is empty if (isPasswordEmpty && isPrincipalNameEmpty) { MessageBox msgBox = new MessageBox(getSite().getShell(), SWT.ICON_WARNING); msgBox.setMessage(SecurityFormMessageConstants.MESSAGE_KERBEROS_PROPERTIES); msgBox.open(); } else if (isPrincipalNameEmpty) { MessageBox msgBox = new MessageBox(getSite().getShell(), SWT.ICON_WARNING); msgBox.setMessage(SecurityFormMessageConstants.MESSAGE_KERBEROS_NAME); msgBox.open(); } else if (isPasswordEmpty) { MessageBox msgBox = new MessageBox(getSite().getShell(), SWT.ICON_WARNING); msgBox.setMessage(SecurityFormMessageConstants.MESSAGE_KERBEROS_PASSWORD); msgBox.open(); } }