Java Code Examples for org.apache.axiom.om.OMElement#getLocalName()

The following examples show how to use org.apache.axiom.om.OMElement#getLocalName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallTemplateWithValuesAndExpressionTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Template with values and expressions")
public void testTemplateWithValuesAndExpressions() throws IOException, XMLStreamException {
    String soapResponse = getResponse();
    assertNotNull(soapResponse, "Response message is null");
    OMElement response = AXIOMUtil.stringToOM(soapResponse);
    OMElement soapBody = response.getFirstElement();
    Iterator quoteBody = soapBody.getChildElements();
    int count = 0;
    while (quoteBody.hasNext()) {
        OMElement getQuote = (OMElement) quoteBody.next();
        String test = getQuote.getLocalName();
        assertEquals(test, "getQuoteResponse", "getQuoteResponse not match");
        OMElement omElement = getQuote.getFirstElement();
        String symbolResponse = omElement.getFirstChildWithName(new QName("http://services.samples/xsd", "symbol"))
                .getText();
        assertEquals(symbolResponse, "WSO2", "Request symbol not changed");

        count++;
    }
    assertEquals(count, iterations, "number of responses different from requests");
}
 
Example 2
Source File: Metadata.java    From openxds with Apache License 2.0 6 votes vote down vote up
OMElement find_metadata_wrapper2(OMElement ele) throws MetadataException {
	for (Iterator<OMElement> it = ele.getChildElements(); it.hasNext();) {
		OMElement e = it.next();
		String name = e.getLocalName();
		if (name == null)
			continue;
		if (name.equals("ObjectRef") || name.equals("ExtrinsicObject")
				|| name.equals("RegistryPackage")
				|| name.equals("Association")
				|| name.equals("Classification"))
			return ele;
		OMElement e2 = find_metadata_wrapper2(e);
		if (e2 != null)
			return e2;
	}
	return null;
}
 
Example 3
Source File: ApplicationPermission.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public static ApplicationPermission build(OMElement applicationPermissionOM) {
    ApplicationPermission applicationPermission = new ApplicationPermission();

    Iterator<?> iter = applicationPermissionOM.getChildElements();

    while (iter.hasNext()) {
        OMElement element = (OMElement) (iter.next());
        String elementName = element.getLocalName();

        if ("value".equals(elementName)) {
            applicationPermission.setValue(element.getText());
        }
    }

    return applicationPermission;
}
 
Example 4
Source File: InboundProvisioningConfig.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public static InboundProvisioningConfig build(OMElement inboundProvisioningConfigOM) {
    InboundProvisioningConfig inboundProvisioningConfig = new InboundProvisioningConfig();

    if (inboundProvisioningConfigOM == null) {
        return inboundProvisioningConfig;
    }

    Iterator<?> iter = inboundProvisioningConfigOM.getChildElements();

    while (iter.hasNext()) {
        OMElement element = (OMElement) (iter.next());
        String elementName = element.getLocalName();

        if ("ProvisioningUserStore".equals(elementName)) {
            inboundProvisioningConfig.setProvisioningUserStore(element.getText());
        } else if ("IsProvisioningEnabled".equals(elementName) && element.getText() != null) {
            inboundProvisioningConfig.setProvisioningEnabled(Boolean.parseBoolean(element.getText()));
        } else if ("IsDumbModeEnabled".equals(elementName) && element.getText() != null) {
            inboundProvisioningConfig.setDumbMode(Boolean.parseBoolean(element.getText()));
        }
    }

    return inboundProvisioningConfig;
}
 
Example 5
Source File: ApplicationPermission.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public static ApplicationPermission build(OMElement applicationPermissionOM) {
    ApplicationPermission applicationPermission = new ApplicationPermission();

    Iterator<?> iter = applicationPermissionOM.getChildElements();

    while (iter.hasNext()) {
        OMElement element = (OMElement) (iter.next());
        String elementName = element.getLocalName();

        if ("value".equals(elementName)) {
            applicationPermission.setValue(element.getText());
        }
    }

    return applicationPermission;
}
 
Example 6
Source File: LocalRole.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public static LocalRole build(OMElement localRoleOM) {

        LocalRole localRole = new LocalRole();

        Iterator<?> iter = localRoleOM.getChildElements();

        while (iter.hasNext()) {
            OMElement element = (OMElement) (iter.next());
            String elementName = element.getLocalName();

            if ("LocalRoleName".equals(elementName)) {
                localRole.setLocalRoleName(element.getText());
            } else if ("UserStoreId".equals(elementName)) {
                localRole.setUserStoreId(element.getText());
            }

        }

        return localRole;
    }
 
Example 7
Source File: IdIndex.java    From openxds with Apache License 2.0 5 votes vote down vote up
public String getObjectTypeById(String id) {
	OMElement submission_set = m.getSubmissionSet();
	OMElement obj = getObjectById(id);
	if (obj == null)
		return null;
	String name = obj.getLocalName();
	if (name.equals("RegistryPackage")) {
		if (obj == submission_set)
			return "SubmissionSet";
		return "Folder";
	}
	return name;
}
 
Example 8
Source File: RepositoryB.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected void validatePnRTransaction(OMElement sor) throws XdsValidationException {
	forceForcedError();
	OMNamespace ns = sor.getNamespace();
	String ns_uri =  ns.getNamespaceURI();
	if (ns_uri == null || ! ns_uri.equals(MetadataSupport.xdsB.getNamespaceURI())) 
		throw new XdsValidationException("Invalid namespace on " + sor.getLocalName() + " (" + ns_uri + ")");
}
 
Example 9
Source File: TranslateToV2.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected void copy_attributes(OMElement from, OMElement to) {
		String element_name = from.getLocalName();
		for (Iterator it=from.getAllAttributes(); it.hasNext();  ) {
			OMAttribute from_a = (OMAttribute) it.next();
			String name = from_a.getLocalName();
			String value = from_a.getAttributeValue();
			OMNamespace xml_namespace = MetadataSupport.xml_namespace;
			OMNamespace namespace = null;
			if (name.endsWith("status"))
				value = translate_att(value);
			else if (name.endsWith("associationType"))
				value = translate_att(value);
			else if (name.equals("minorVersion"))
				continue;
			else if (name.equals("majorVersion"))
				continue;
			else if (name.equals("lang"))
				namespace = xml_namespace;
			else if (name.equals("objectType") && value.startsWith("urn:oasis:names:tc:ebxml-regrep:ObjectType:RegistryObject:")) {
				String[] parts = value.split(":");
				value = parts[parts.length-1];
			}
//			else if (name.equals("objectType") && ! value.startsWith("urn:oasis:names:tc:ebxml-regrep:ObjectType:RegistryObject:"))
//			value = "urn:oasis:names:tc:ebxml-regrep:ObjectType:RegistryObject:" + value;
			OMAttribute to_a = MetadataSupport.om_factory.createOMAttribute(name, namespace, value);
			to.addAttribute(to_a);
		}
		
	}
 
Example 10
Source File: RegistryB.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected void validateSubmitTransaction(OMElement sor)
throws XdsValidationException {
	forceForcedError();
	OMNamespace ns = sor.getNamespace();
	String ns_uri =  ns.getNamespaceURI();
	if (ns_uri == null || ! ns_uri.equals(MetadataSupport.ebLcm3.getNamespaceURI())) 
		throw new XdsValidationException("Invalid namespace on " + sor.getLocalName() + " (" + ns_uri + ")");

	String type = getRTransactionName(sor);

	if (!type.startsWith("SubmitObjectsRequest"))
		throw new XdsValidationException("Only SubmitObjectsRequest is acceptable on this endpoint, found " + sor.getLocalName());
}
 
Example 11
Source File: HomeAttribute.java    From openxds with Apache License 2.0 5 votes vote down vote up
public void set(OMElement root) {
	String localname = root.getLocalName();

	if (isIdentifiable(localname)) 
		root.addAttribute("home", home, null);

	for (OMNode child=root.getFirstElement(); child != null; child=child.getNextOMSibling()) {
		if (child instanceof OMText) {
			continue;				
		}
		OMElement child_e = (OMElement) child;
		set(child_e);
	}
}
 
Example 12
Source File: APIDescriptionGenUtil.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * The method to extract the tier attributes from each tier level policy definitions
 * @param policy  Tier level policy
 * @return Attributes map
 * @throws APIManagementException
 */
public static Map<String, Object> getTierAttributes(OMElement policy) throws APIManagementException {
    Map<String, Object> attributesMap = new HashMap<String, Object>();
    OMElement attributes = null;

    try {
        OMElement tier = policy.getFirstChildWithName(APIConstants.POLICY_ELEMENT).getFirstChildWithName
                (APIConstants.THROTTLE_CONTROL_ELEMENT).getFirstChildWithName(APIConstants.POLICY_ELEMENT)
                .getFirstChildWithName(APIConstants.POLICY_ELEMENT);
        if (tier != null) {
            attributes = tier.getFirstChildWithName(APIConstants.THROTTLE_ATTRIBUTES_ELEMENT);
        }
        if (attributes == null) {
            return attributesMap;
        } else {
            for (Iterator childElements = attributes.getChildElements(); childElements.hasNext(); ) {
                OMElement element = (OMElement) childElements.next();
                String displayName = element.getAttributeValue(
                        new QName(APIConstants.THROTTLE_ATTRIBUTE_DISPLAY_NAME));
                String localName = element.getLocalName();
                String attrName = (displayName != null ? displayName : localName); //If displayName not defined,
                // use the attribute name
                String attrValue = element.getText();
                attributesMap.put(attrName, attrValue);
            }
        }
    } catch (NullPointerException e) {
        String errorMessage = "Policy could not be parsed correctly based on " +
                "http://schemas.xmlsoap.org/ws/2004/09/policy specification";
        log.error(errorMessage, e);
        throw new APIManagementException(errorMessage + e.getMessage());
    }
    return attributesMap;
}
 
Example 13
Source File: QueryControl.java    From openxds with Apache License 2.0 5 votes vote down vote up
OMElement find_transaction_output(OMElement stepele) {
	for (Iterator<OMElement> it=stepele.getChildElements(); it.hasNext(); ) {
		OMElement child = it.next();
		String name = child.getLocalName();
		if (name.endsWith("Transaction"))
			return child;
	}
	return null;
}
 
Example 14
Source File: ClaimConfig.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public static ClaimConfig build(OMElement claimConfigOM) {
    ClaimConfig claimConfig = new ClaimConfig();

    Iterator<?> iter = claimConfigOM.getChildElements();

    while (iter.hasNext()) {

        OMElement element = (OMElement) (iter.next());
        String elementName = element.getLocalName();

        if ("RoleClaimURI".equals(elementName)) {
            claimConfig.setRoleClaimURI(element.getText());
        } else if ("LocalClaimDialect".equals(elementName)) {
            if (element.getText() != null) {
                claimConfig.setLocalClaimDialect(Boolean.parseBoolean(element.getText()));
            }
        } else if ("UserClaimURI".equals(elementName)) {
            claimConfig.setUserClaimURI(element.getText());
        } else if ("AlwaysSendMappedLocalSubjectId".equals(elementName)) {
            if ("true".equals(element.getText())) {
                claimConfig.setAlwaysSendMappedLocalSubjectId(true);
            }
        } else if ("IdpClaims".equals(elementName)) {
            Iterator<?> idpClaimsIter = element.getChildElements();
            List<Claim> idpClaimsArrList = new ArrayList<Claim>();

            if (idpClaimsIter != null) {
                while (idpClaimsIter.hasNext()) {
                    OMElement idpClaimsElement = (OMElement) (idpClaimsIter.next());
                    Claim claim = Claim.build(idpClaimsElement);
                    if (claim != null) {
                        idpClaimsArrList.add(claim);
                    }
                }
            }

            if (CollectionUtils.isNotEmpty(idpClaimsArrList)) {
                Claim[] idpClaimsArr = idpClaimsArrList.toArray(new Claim[0]);
                claimConfig.setIdpClaims(idpClaimsArr);
            }
        } else if ("ClaimMappings".equals(elementName)) {

            Iterator<?> claimMappingsIter = element.getChildElements();
            List<ClaimMapping> claimMappingsArrList = new ArrayList<ClaimMapping>();

            if (claimMappingsIter != null) {
                while (claimMappingsIter.hasNext()) {
                    OMElement claimMappingsElement = (OMElement) (claimMappingsIter.next());
                    ClaimMapping claimMapping = ClaimMapping.build(claimMappingsElement);
                    if (claimMapping != null) {
                        claimMappingsArrList.add(claimMapping);
                    }
                }
            }

            if (CollectionUtils.isNotEmpty(claimMappingsArrList)) {
                ClaimMapping[] claimMappingsArr = claimMappingsArrList
                        .toArray(new ClaimMapping[0]);
                claimConfig.setClaimMappings(claimMappingsArr);
            }
        } else if (IdentityApplicationConstants.ConfigElements.PROPERTY_SP_DIALECT.equals(elementName)) {
            Iterator<?> spDialects = element.getChildElements();
            List<String> spDialectsArrList = new ArrayList<String>();

            while (spDialects.hasNext()) {
                OMElement spDialectElement = (OMElement) (spDialects.next());
                if (spDialectElement.getText() != null) {
                    spDialectsArrList.add(spDialectElement.getText());
                }
            }

            if (CollectionUtils.isNotEmpty(spDialectsArrList)) {
                String[] spDialectArr = spDialectsArrList.toArray(new String[0]);
                claimConfig.setSpClaimDialects(spDialectArr);
            }
        }
    }

    return claimConfig;
}
 
Example 15
Source File: Property.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public static Property build(OMElement propertyOM) {

        if (propertyOM == null) {
            return null;
        }

        Property property = new Property();

        Iterator<?> iter = propertyOM.getChildElements();

        while (iter.hasNext()) {
            OMElement element = (OMElement) (iter.next());
            String elementName = element.getLocalName();

            if ("Name".equals(elementName)) {
                property.setName(element.getText());
            } else if ("Value".equals(elementName)) {
                property.setValue(element.getText());
            } else if ("IsConfidential".equals(elementName)) {
                if (element.getText() != null && element.getText().trim().length() > 0) {
                    property.setConfidential(Boolean.parseBoolean(element.getText()));
                }
            } else if ("defaultValue".equals(elementName)) {
                property.setDefaultValue(element.getText());
            } else if ("DisplayName".equals(elementName)) {
                property.setDisplayName(element.getText());
            } else if ("Required".equals(elementName)) {
                if (element.getText() != null && element.getText().trim().length() > 0) {
                    property.setRequired(Boolean.parseBoolean(element.getText()));
                }
            } else if ("Description".equals(elementName)) {
                property.setDescription(element.getText());
            } else if ("DisplayOrder".equals(elementName)) {
                property.setDisplayOrder(Integer.parseInt(element.getText()));
            } else if ("Type".equals(elementName)) {
                property.setType(element.getText());
            } else if ("IsAdvanced".equals(elementName)) {
                if (element.getText() != null && element.getText().trim().length() > 0) {
                    property.setAdvanced(Boolean.parseBoolean(element.getText()));
                }
            } else if ("Regex".equals(elementName)) {
                if (element.getText() != null && element.getText().trim().length() > 0) {
                    property.setRegex(element.getText());
                }
            } else if ("Options".equals(elementName)) {
                Iterator<?> optionsIter = element.getChildElements();
                List<String> optionsArrList = new ArrayList<String>();

                while (optionsIter.hasNext()) {
                    OMElement optionsElement = (OMElement) (optionsIter.next());
                    if (optionsElement.getText() != null) {
                        optionsArrList.add(optionsElement.getText());
                    }
                }

                if (CollectionUtils.isNotEmpty(optionsArrList)) {
                    String[] optionsArr = optionsArrList.toArray(new String[0]);
                    property.setOptions(optionsArr);
                }
            } else if ("SubProperties".equals(elementName)) {
                Iterator<?> subPropsIter = element.getChildElements();
                List<SubProperty> subPropsArrList = new ArrayList<>();

                while (subPropsIter.hasNext()) {
                    OMElement subPropElement = (OMElement) (subPropsIter.next());
                    if (subPropElement != null) {
                        subPropsArrList.add(SubProperty.build(subPropElement));
                    }
                }

                if (CollectionUtils.isNotEmpty(subPropsArrList)) {
                    SubProperty[] subPropsArr = subPropsArrList.toArray(new SubProperty[0]);
                    property.setSubProperties(subPropsArr);
                }
            }
        }

        return property;
    }
 
Example 16
Source File: EbXML21QuerySupport.java    From openxds with Apache License 2.0 4 votes vote down vote up
/**
 * Validate uids found in metadata are proper. Uids of Folder and Submission Set may not
 * be already present in registry.  Uid of DocumentEntry objects may be present if hash and
 * size match. 
 * @param metadata
 * @throws MetadataValidationException - on all metadata errors
 * @throws XdsNonIdenticalHashException - if uid found in registry with different hash 
 * @throws LoggerException - on error writing to Test Log
 * @throws XdsException - on low level interface errors
 * @throws XMLParserException 
 */
public void validateProperUids(Metadata metadata)  throws LoggerException, XMLParserException, XdsException {

	// uid_hash is uid => hash (null for non documents)
	HashMap<String, List<String>> uid_hash = metadata.getUidHashMap();

	List<String> uids = new ArrayList<String>(); // all uids in metadata
	uids.addAll(uid_hash.keySet());

	List<String> uuids = getUuidForUid(uids);

	if (uuids.size() == 0)
		return;

	// at least one uniqueId is already present in the registry. If it is from a document
	// and the hash and size are the same then it is ok.  Otherwise it is an error.

	sqs.forceLeafClassQueryType();
	OMElement offendingObjects = getObjectsByUuid(uuids);   // LeafClass for offending objects
	sqs.restoreOriginalQueryType();

	if (offendingObjects == null) 
		throw new XdsInternalException("RegistryObjectValidator.validateProperUids(): could not retrieve LeafClass for ObjectRef obtained from registry: UUIDs were " + uuids);

	Metadata m = MetadataParser.parseNonSubmission(offendingObjects);
	List<String> dup_uids = new ArrayList<String>();
	HashMap<String, OMElement> dup_objects = m.getUidMap();
	dup_uids.addAll(dup_objects.keySet());


	sqs.log_message.addOtherParam("dup uuids", uuids.toString());
	sqs.log_message.addOtherParam("dup uids", dup_uids.toString());

	// Generate error messages that are object type specific
	dupUidErrorException(metadata, 
			dup_uids, 
			"SubmissionSet", 
			metadata.getSubmissionSetIds(), 
			MetadataSupport.XDSSubmissionSet_uniqueid_uuid);

	dupUidErrorException(metadata, 
			dup_uids, 
			"Folder", 
			metadata.getFolderIds(), 
			MetadataSupport.XDSFolder_uniqueid_uuid);

	HashMap<String, OMElement> docs_submit_uid_map = metadata.getUidMap(metadata.getExtrinsicObjects());
	for (String doc_uid : docs_submit_uid_map.keySet()) {
		if (dup_uids.contains(doc_uid)) {
			OMElement reg_obj = dup_objects.get(doc_uid);
			String type = reg_obj.getLocalName();
			if ( !type.equals("ExtrinsicObject")) 
				throw new MetadataValidationException("Document uniqueId " + 
						doc_uid + 
				" already present in the registry on a non-document object");
			OMElement sub_obj = docs_submit_uid_map.get(doc_uid);
			String sub_hash = m.getSlotValue(sub_obj, "hash", 0);
			String reg_hash = m.getSlotValue(reg_obj, "hash", 0);

			if (logger.isDebugEnabled()) {
				logger.debug("doc_uid " + doc_uid);
				logger.debug("sub_hash " + sub_hash);
				logger.debug("reg_hash " + reg_hash);
			}
			
			if (sub_hash != null && reg_hash != null && !sub_hash.equals(reg_hash))
				throw new XdsNonIdenticalHashException(
						"UniqueId " + doc_uid + " exists in both the submission and Registry and the hash value is not the same: " +
						"Submission Hash Value = " + sub_hash + " and " +
						"Registry Hash Value = " + reg_hash
				);

		}
	}

}
 
Example 17
Source File: Claim.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public static Claim build(OMElement claimOM) {

        if (claimOM == null) {
            return null;
        }

        Claim claim = new Claim();

        Iterator<?> iter = claimOM.getChildElements();

        while (iter.hasNext()) {
            OMElement element = (OMElement) (iter.next());
            String elementName = element.getLocalName();

            if ("ClaimUri".equals(elementName)) {
                claim.setClaimUri(element.getText());
            }

        }
        return claim;

    }
 
Example 18
Source File: CrossGatewayRetrieveTest.java    From openxds with Apache License 2.0 4 votes vote down vote up
/**
    * XGR Retrieve multiple document, Generate request for the retrieval of multiple documents.
    * Some from the local community, and some from a remote community. 
    * Based on the XDSDocument.uniqueId, repositoryUniqueId, and homeCommunityId returned in metadata, 
    * issue a RetrieveDocumentSet transaction to retrieve two documents.
    * <p>
    * Note:
    * This test submits the RetrieveDocumentSet request to the initiating gateway instead of the responding gateway.
    * 
    * @throws Exception
    */	
	@Test
	public void testIGMultipleDocuments() throws Exception {
		//1. Load one or more documents for the default patient: patientId
		
		//2. Generate StoredQuery request message
		String message = new CrossGatewayQueryTest().findDocumentsQuery(patientId, "Approved", "LeafClass");
		OMElement request = OMUtil.xmlStringToOM(message);			
		System.out.println("Request:\n" +request);

		//3. Send a StoredQuery
		ServiceClient sender = getRegistryGateWayClient();															 
		OMElement response = sender.sendReceive( request );
		assertNotNull(response); 
		
		//4. Get DocumentUniqueId from the response.
		List extrinsicObjects = getExtrinsicObjects(response);
		List<String> docIds = getDocumentId(extrinsicObjects);
		
		//5. Get RepositoryUniqueId from the response.
		XdsRepositoryService xdsService = (XdsRepositoryService) XdsFactory.getInstance().getBean("repositoryService");
		String reposiotryUniqueId = xdsService.getRepositoryUniqueId();

		//6. Generate Retrieve document request message
		List<String> ids = new ArrayList<String>();
		//Add the documents from the local community repository
		for (String docId : docIds) {
			ids.add(homeProperty);
			ids.add(reposiotryUniqueId);
			ids.add(docId);
		}		
//String 	reposiotryUniqueId = "1.3.6.1.4.1.21367.2010.1.2.1125";
//ids.add("urn:oid:1.3.6.1.4.1.21367.2010.1.2.2045"); 
////use the same repository as in the local community. In the real world, it should not be the same.
//ids.add(reposiotryUniqueId);
//// docId - hard coded for now
//ids.add("2.16.840.1.113883.3.65.2.1262392348530");
		
		//Add the documents from a remote community (in the 198.160.211.53 server)
		//remote home id
		String remoteHomeId = "urn:oid:1.3.6.1.4.1.21367.2010.1.2.2800";
		ids.add(remoteHomeId); 
		//use the same repository as in the local community. In the real world, it should not be the same.
		ids.add(reposiotryUniqueId);
		// docId - hard coded for now
		ids.add("2.16.840.1.113883.3.65.2.1262451539643");
		
		String retrieveDoc = retrieveDocuments(ids);
		OMElement retrieveDocRequest = OMUtil.xmlStringToOM(retrieveDoc);
		System.out.println("Request:\n" +retrieveDoc);
		
		//7. Send a Retrieve document set request
		ServiceClient retrieveDocSender = getIGRetrieveServiceClient();
		OMElement retrieveDocResponse = retrieveDocSender.sendReceive(retrieveDocRequest);

		assertNotNull(retrieveDocResponse);

		String responseStatus;
		//8. Verify the response is correct
		List registryResponse = new ArrayList();
		for (Iterator it = retrieveDocResponse.getChildElements(); it.hasNext();) {
			OMElement obj = (OMElement) it.next();
			String type = obj.getLocalName();
			if (type.equals("RegistryResponse")) {
				registryResponse.add(obj);
			}
		}
		responseStatus = getRetrieveDocumentStatus(registryResponse);
		assertEquals("urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Success", responseStatus);
		
		//9. Verify the response returning more than 1 Document and each has a valid HomeCommunityId
		List<OMElement> docRequests = MetadataSupport.childrenWithLocalName(retrieveDocResponse, "DocumentResponse");
		assertNotNull (docRequests);

		for (OMElement documentRequest : docRequests) {
			OMElement homeElem = MetadataSupport.firstChildWithLocalName(documentRequest, "HomeCommunityId");
			assertNotNull (homeElem);
			String home = homeElem.getText();
			assertNotNull (home);
			assertTrue(home.equals(homeProperty) || home.equals(remoteHomeId));
		}
		assertTrue(docRequests.size() >= 1); 
		
		String result = retrieveDocResponse.toString();
		System.out.println("Result:\n" +result);
	}
 
Example 19
Source File: ServiceProvider.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public static ServiceProvider build(OMElement serviceProviderOM) {

        ServiceProvider serviceProvider = new ServiceProvider();

        // by default set to true.
        serviceProvider.setSaasApp(true);

        Iterator<?> iter = serviceProviderOM.getChildElements();

        while (iter.hasNext()) {

            OMElement element = (OMElement) (iter.next());
            String elementName = element.getLocalName();

            if ("ApplicationID".equals(elementName)) {
                if (element.getText() != null) {
                    serviceProvider.setApplicationID(Integer.parseInt(element.getText()));
                }
            } else if ("ApplicationName".equals(elementName)) {
                if (element.getText() != null) {
                    serviceProvider.setApplicationName(element.getText());
                } else {
                    log.error("Service provider not loaded from the file. Application Name is null.");
                    return null;
                }
            } else if ("Description".equals(elementName)) {
                serviceProvider.setDescription(element.getText());
            } else if ("IsSaaSApp".equals(elementName)) {
                if (element.getText() != null && "true".equals(element.getText())) {
                    serviceProvider.setSaasApp(true);
                } else {
                    serviceProvider.setSaasApp(false);
                }
            } else if ("Owner".equals(elementName)) {
                // build service provider owner.
                serviceProvider.setOwner(User.build(element));
            } else if ("InboundAuthenticationConfig".equals(elementName)) {
                // build in-bound authentication configuration.
                serviceProvider.setInboundAuthenticationConfig(InboundAuthenticationConfig
                        .build(element));
            } else if ("LocalAndOutBoundAuthenticationConfig".equals(elementName)) {
                // build local and out-bound authentication configuration.
                serviceProvider
                        .setLocalAndOutBoundAuthenticationConfig(LocalAndOutboundAuthenticationConfig
                                .build(element));
            } else if ("RequestPathAuthenticatorConfigs".equals(elementName)) {
                // build request-path authentication configurations.
                Iterator<?> requestPathAuthenticatorConfigsIter = element.getChildElements();

                if (requestPathAuthenticatorConfigsIter == null) {
                    continue;
                }

                List<RequestPathAuthenticatorConfig> requestPathAuthenticatorConfigsArrList;
                requestPathAuthenticatorConfigsArrList = new ArrayList<RequestPathAuthenticatorConfig>();

                while (requestPathAuthenticatorConfigsIter.hasNext()) {
                    OMElement requestPathAuthenticatorConfigsElement = (OMElement) (requestPathAuthenticatorConfigsIter
                            .next());
                    RequestPathAuthenticatorConfig reqConfig = RequestPathAuthenticatorConfig
                            .build(requestPathAuthenticatorConfigsElement);

                    if (reqConfig != null) {
                        // we only need not-null values.
                        requestPathAuthenticatorConfigsArrList.add(reqConfig);
                    }
                }

                if (CollectionUtils.isNotEmpty(requestPathAuthenticatorConfigsArrList)) {
                    // add to the service provider, only if we have any.
                    RequestPathAuthenticatorConfig[] requestPathAuthenticatorConfigsArr;
                    requestPathAuthenticatorConfigsArr = requestPathAuthenticatorConfigsArrList
                            .toArray(new RequestPathAuthenticatorConfig[0]);
                    serviceProvider
                            .setRequestPathAuthenticatorConfigs(requestPathAuthenticatorConfigsArr);
                }

            } else if ("InboundProvisioningConfig".equals(elementName)) {
                // build in-bound provisioning configuration.
                serviceProvider.setInboundProvisioningConfig(InboundProvisioningConfig
                        .build(element));
            } else if ("OutboundProvisioningConfig".equals(elementName)) {
                // build out-bound provisioning configuration.
                serviceProvider.setOutboundProvisioningConfig(OutboundProvisioningConfig
                        .build(element));
            } else if ("ClaimConfig".equals(elementName)) {
                // build claim configuration.
                serviceProvider.setClaimConfig(ClaimConfig.build(element));
            } else if ("PermissionAndRoleConfig".equals(elementName)) {
                // build permission and role configuration.
                serviceProvider.setPermissionAndRoleConfig(PermissionsAndRoleConfig.build(element));
            }

        }

        return serviceProvider;
    }
 
Example 20
Source File: Property.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public static Property build(OMElement propertyOM) {

        if (propertyOM == null) {
            return null;
        }

        Property property = new Property();

        Iterator<?> iter = propertyOM.getChildElements();

        while (iter.hasNext()) {
            OMElement element = (OMElement) (iter.next());
            String elementName = element.getLocalName();

            if ("Name".equals(elementName)) {
                property.setName(element.getText());
            } else if ("Value".equals(elementName)) {
                property.setValue(element.getText());
            } else if ("IsConfidential".equals(elementName)) {
                if (element.getText() != null && element.getText().trim().length() > 0) {
                    property.setConfidential(Boolean.parseBoolean(element.getText()));
                }
            } else if ("defaultValue".equals(elementName)) {
                property.setDefaultValue(element.getText());
            } else if ("DisplayName".equals(elementName)) {
                property.setDisplayName(element.getText());
            } else if ("Required".equals(elementName)) {
                if (element.getText() != null && element.getText().trim().length() > 0) {
                    property.setRequired(Boolean.parseBoolean(element.getText()));
                }
            } else if ("Description".equals(elementName)) {
                property.setDescription(element.getText());
            } else if ("DisplayOrder".equals(elementName)) {
                property.setDisplayOrder(Integer.parseInt(element.getText()));
            } else if ("Type".equals(elementName)) {
                property.setType(element.getText());
            }
        }

        return property;
    }