use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-identity-framework by wso2.
the class XACMLBasedRuleHandler method evaluateXACMLResponse.
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;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-identity-framework by wso2.
the class UserRegistrationService method getTenantSignUpConfig.
private TenantRegistrationConfig getTenantSignUpConfig(int tenantId) throws IdentityException {
TenantRegistrationConfig config;
NodeList nodes;
try {
// start tenant flow to load tenant registry
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
Registry registry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE);
if (registry.resourceExists(SelfRegistrationConstants.SIGN_UP_CONFIG_REG_PATH)) {
Resource resource = registry.get(SelfRegistrationConstants.SIGN_UP_CONFIG_REG_PATH);
// build config from tenant registry resource
DocumentBuilder builder = getSecuredDocumentBuilder();
String configXml = new String((byte[]) resource.getContent());
InputSource configInputSource = new InputSource();
configInputSource.setCharacterStream(new StringReader(configXml.trim()));
Document doc = builder.parse(configInputSource);
nodes = doc.getElementsByTagName(SelfRegistrationConstants.SELF_SIGN_UP_ELEMENT);
if (nodes.getLength() > 0) {
config = new TenantRegistrationConfig();
config.setSignUpDomain(((Element) nodes.item(0)).getElementsByTagName(SelfRegistrationConstants.SIGN_UP_DOMAIN_ELEMENT).item(0).getTextContent());
// there can be more than one <SignUpRole> elements, iterate through all elements
NodeList rolesEl = ((Element) nodes.item(0)).getElementsByTagName(SelfRegistrationConstants.SIGN_UP_ROLE_ELEMENT);
for (int i = 0; i < rolesEl.getLength(); i++) {
Element tmpEl = (Element) rolesEl.item(i);
String tmpRole = tmpEl.getElementsByTagName(SelfRegistrationConstants.ROLE_NAME_ELEMENT).item(0).getTextContent();
boolean tmpIsExternal = Boolean.parseBoolean(tmpEl.getElementsByTagName(SelfRegistrationConstants.IS_EXTERNAL_ELEMENT).item(0).getTextContent());
config.getRoles().put(tmpRole, tmpIsExternal);
}
return config;
} else {
return null;
}
}
} catch (RegistryException e) {
throw IdentityException.error("Error retrieving sign up config from registry " + e.getMessage(), e);
} catch (ParserConfigurationException e) {
throw IdentityException.error("Error parsing tenant sign up configuration " + e.getMessage(), e);
} catch (SAXException e) {
throw IdentityException.error("Error parsing tenant sign up configuration " + e.getMessage(), e);
} catch (IOException e) {
throw IdentityException.error("Error parsing tenant sign up configuration " + e.getMessage(), e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
return null;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-identity-framework by wso2.
the class InMemoryPersistenceManager method buildDataHolder.
private PolicyEditorDataHolder buildDataHolder(String type, String xmlConfig) throws PolicyEditorException {
if (xmlConfig == null) {
return null;
}
PolicyEditorDataHolder holder = new PolicyEditorDataHolder();
DocumentBuilder builder;
ByteArrayInputStream inputStream;
Element root = null;
inputStream = new ByteArrayInputStream(xmlConfig.getBytes());
try {
builder = getSecuredDocumentBuilder();
Document doc = builder.parse(inputStream);
root = doc.getDocumentElement();
} catch (Exception e) {
log.error("DOM of request element can not be created from String", e);
} finally {
try {
inputStream.close();
} catch (IOException e) {
log.error("Error in closing input stream of XACML request");
}
}
if (root == null) {
return holder;
}
NodeList nodeList = root.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeName().equals("categories")) {
parseCategories(type, node, holder);
} else if (node.getNodeName().equals("ruleCombiningAlgorithm")) {
parseAlgorithm(node, holder, false);
} else if (node.getNodeName().equals("policyCombiningAlgorithm")) {
parseAlgorithm(node, holder, true);
} else if (node.getNodeName().equals("attributeIds")) {
parseAttributeIds(node, holder);
} else if (node.getNodeName().equals("dataTypes")) {
parseDataTypes(node, holder);
} else if (node.getNodeName().equals("functions")) {
parseFunctions(node, holder);
} else if (node.getNodeName().equals("preFunctions")) {
parsePreFunctions(node, holder);
} else if (node.getNodeName().equals("rule")) {
parseRule(node, holder);
} else if (node.getNodeName().equals("policyDescription")) {
if ("true".equals(node.getTextContent())) {
holder.setShowPolicyDescription(true);
}
}
}
return holder;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project carbon-mediation by wso2.
the class RestApiAdminClient method ReadWSDLPrefix.
private String ReadWSDLPrefix() throws AxisFault {
try {
String confPath = System.getProperty(CONF_LOCATION);
if (confPath == null) {
confPath = Paths.get("repository", "conf").toString();
}
InputStream in = new FileInputStream(Paths.get(confPath, "axis2", "axis2.xml").toString());
OMElement results = OMXMLBuilderFactory.createOMBuilder(in).getDocumentElement();
AXIOMXPath xpathExpression = new AXIOMXPath("/axisconfig/transportReceiver/parameter[@name='WSDLEPRPrefix']");
List nodeList = (List) xpathExpression.selectNodes(results);
if (!nodeList.isEmpty()) {
OMNode value = (OMNode) nodeList.get(0);
String server = ((OMElementImpl) value).getText();
if (server.contains("http") || server.contains("https")) {
return server;
}
}
} catch (Exception e) {
handleException(bundle.getString("failed.to.read.wsdl.prefix"), e);
}
return null;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeList in project product-is by wso2.
the class SAML2SSOTestBase method extractAndProcessSAMLResponse.
/**
* Get SAML response object from the HTTP response.
*
* @param response HTTP response
* @return SAML response instance.
* @throws Exception
*/
public Response extractAndProcessSAMLResponse(HttpResponse response) throws Exception {
String encodedSAML2ResponseString = extractSAMLResponse(response);
EntityUtils.consume(response.getEntity());
String saml2ResponseString = new String(Base64.decode(encodedSAML2ResponseString), Charset.forName(StandardCharsets.UTF_8.name()));
XMLObject samlResponse = unmarshall(saml2ResponseString);
// Check for duplicate samlp:Response
NodeList list = samlResponse.getDOM().getElementsByTagNameNS(SAMLConstants.SAML20P_NS, RESPONSE_TAG_NAME);
if (list.getLength() > 0) {
log.error("Invalid schema for the SAML2 response. Multiple Response elements found.");
throw new Exception("Error occurred while processing SAML2 response.");
}
// Checking for multiple Assertions
NodeList assertionList = samlResponse.getDOM().getElementsByTagNameNS(SAMLConstants.SAML20_NS, ASSERTION_TAG_NAME);
if (assertionList.getLength() > 1) {
log.error("Invalid schema for the SAML2 response. Multiple Assertion elements found.");
throw new Exception("Error occurred while processing SAML2 response.");
}
return (Response) samlResponse;
}
Aggregations