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

The following examples show how to use org.apache.axiom.om.OMElement#getText() . 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: IdentityProviderData.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param rst
 * @throws IdentityProviderException
 */
@Override
protected void processInfoCardReference(OMElement rst) throws IdentityProviderException {
    OMElement infoCardRef = null;
    OMElement omCardID = null;

    if (log.isDebugEnabled()) {
        log.debug("Processing information card reference");
    }

    infoCardRef = rst.getFirstChildWithName(new QName(IdentityConstants.NS,
                                                      IdentityConstants.LocalNames.INFO_CARD_REFERENCE));

    omCardID = infoCardRef.getFirstChildWithName(new QName(IdentityConstants.NS,
                                                           IdentityConstants.LocalNames.CARD_ID));

    this.cardID = omCardID.getText();
}
 
Example 2
Source File: RetrieveAggregator.java    From openxds with Apache License 2.0 6 votes vote down vote up
protected void addResult(OMElement result, String homeId) throws XdsInternalException {
List<OMElement> docResponseList = MetadataSupport.childrenWithLocalName(result, "DocumentResponse"); 
for (OMElement docResponse : docResponseList) {			
	if (log.isDebugEnabled()) {
		log.debug("docResponse is \n" + docResponse.toString());
	}
	
	docResponse.setNamespace(MetadataSupport.xdsB);
	
	OMElement elemHome = MetadataSupport.firstChildWithLocalName(docResponse, "HomeCommunityId");
	if (elemHome == null || elemHome.getText() == null || elemHome.getText().equals("")) 
		MetadataSupport.addChild("HomeCommunityId", MetadataSupport.xdsB, docResponse); 
	else if (!homeId.equals(elemHome.getText())) {
		response.error("Invalid home returned " + elemHome +", expected home is " + homeId);
	}
	rdsResponse.addDocumentResponse(docResponse);
}    	
  }
 
Example 3
Source File: ConfigurationLoader.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Populates individual users.
 *
 * @param users the parent element of users
 * @return map of users against credentials
 */
private static Map<String, char[]> populateUsers(OMElement users) {
    HashMap<String, char[]> userMap = new HashMap<>();
    if (users != null) {
        @SuppressWarnings("unchecked")
        Iterator<OMElement> usersIterator = users.getChildrenWithName(USER_Q);
        if (usersIterator != null) {
            while (usersIterator.hasNext()) {
                OMElement userElement = usersIterator.next();
                OMElement userNameElement = userElement.getFirstChildWithName(USERNAME_Q);
                OMElement passwordElement = userElement.getFirstChildWithName(PASSWORD_Q);
                if (userNameElement != null && passwordElement != null) {
                    String userName = userNameElement.getText();
                    if (userMap.containsKey(userName)) {
                        handleException("Error parsing the file based user store. User: " + userName + " defined "
                                        + "more than once. ");
                    }
                    userMap.put(userName, passwordElement.getText().toCharArray());
                }
            }
        }
    }
    return userMap;
}
 
Example 4
Source File: LBService1.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public OMElement sleepOperation(OMElement param) throws AxisFault {

        param.build();
        param.detach();

        OMElement timeElement = param.getFirstChildWithName(new QName("load"));
        String time = timeElement.getText();
        try {
            Thread.sleep(Long.parseLong(time));
        } catch (InterruptedException e) {
            throw new AxisFault("Service is interrupted while sleeping.");
        }

        String sName = System.getProperty("server_name");
        if (sName != null) {
            timeElement.setText("Response from server: " + sName);
        } else {
            timeElement.setText("Response from anonymous server");
        }
        return param;
    }
 
Example 5
Source File: FileBasedConfigurationBuilder.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private void readMaximumLoginAttemptCount(OMElement documentElement) {
    OMElement maxLoginAttemptCountElem = documentElement.getFirstChildWithName(IdentityApplicationManagementUtil.
            getQNameWithIdentityApplicationNS(FrameworkConstants.Config.QNAME_MAX_LOGIN_ATTEMPT_COUNT));

    if (maxLoginAttemptCountElem != null) {
        String maxLoginAttemptCountStr = maxLoginAttemptCountElem.getText();

        if (maxLoginAttemptCountStr != null && !maxLoginAttemptCountStr.isEmpty()) {
            try {
                maxLoginAttemptCount = Integer.parseInt(maxLoginAttemptCountElem.getText());
            } catch (NumberFormatException e) {
                log.error("MaxLoginAttemptCount must be a number");
                maxLoginAttemptCount = 5;
            }
        }
    }
}
 
Example 6
Source File: SecurityUtils.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the resolved secret.
 *
 * @param secretResolver secret resolver initialized with relevant OM element
 * @param paramElement   OMElement password
 * @return resolved password
 */
public static String getSecureVaultValue(SecretResolver secretResolver, OMElement paramElement) {
    String value = null;
    if (paramElement != null) {
        OMAttribute attribute = paramElement.getAttribute(new QName(CryptoConstants.SECUREVAULT_NAMESPACE,
                CryptoConstants.SECUREVAULT_ALIAS_ATTRIBUTE));
        if (attribute != null && attribute.getAttributeValue() != null && !attribute.getAttributeValue().isEmpty
                ()) {
            if (secretResolver == null) {
                throw new SecureVaultException("Cannot resolve secret password because axis2 secret resolver "
                        + "is null");
            }
            if (secretResolver.isTokenProtected(attribute.getAttributeValue())) {
                value = secretResolver.resolve(attribute.getAttributeValue());
            }
        } else {
            value = paramElement.getText();
        }
    }
    return value;
}
 
Example 7
Source File: JustInTimeProvisioningConfig.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public static JustInTimeProvisioningConfig build(OMElement justInTimeProvisioningConfigOM) {
    JustInTimeProvisioningConfig justInTimeProvisioningConfig = new JustInTimeProvisioningConfig();

    if (justInTimeProvisioningConfigOM == null) {
        return justInTimeProvisioningConfig;
    }

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

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

        if ("UserStoreClaimUri".equals(elementName)) {
            justInTimeProvisioningConfig.setUserStoreClaimUri(element.getText());
        } else if ("ProvisioningUserStore".equals(elementName)) {
            justInTimeProvisioningConfig.setProvisioningUserStore(element.getText());
        } else if ("IsProvisioningEnabled".equals(elementName)) {
            if (element.getText() != null && element.getText().trim().length() > 0) {
                justInTimeProvisioningConfig.setProvisioningEnabled(Boolean
                        .parseBoolean(element.getText()));
            }
        } else if (IdentityApplicationConstants.IS_PASSWORD_PROVISIONING_ENABLED_ELEMENT.equals(elementName)) {
            if (StringUtils.isNotEmpty(element.getText())) {
                justInTimeProvisioningConfig
                        .setPasswordProvisioningEnabled(Boolean.parseBoolean(element.getText()));
            }
        } else if (IdentityApplicationConstants.ALLOW_MODIFY_USERNAME_ELEMENT.equals(elementName)) {
            if (StringUtils.isNotEmpty(element.getText())) {
                justInTimeProvisioningConfig.setModifyUserNameAllowed(Boolean.parseBoolean(element.getText()));
            }
        } else if (IdentityApplicationConstants.PROMPT_CONSENT_ELEMENT.equals(elementName)) {
            if (StringUtils.isNotEmpty(element.getText())) {
                justInTimeProvisioningConfig.setPromptConsent(Boolean.parseBoolean(element.getText()));
            }
        }
    }

    return justInTimeProvisioningConfig;
}
 
Example 8
Source File: LoadbalanceFailoverClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public String sessionlessClient() throws AxisFault {

        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMElement value = fac.createOMElement("Value", null);
        value.setText("Sample string");

        Options options = new Options();
        options.setTo(new EndpointReference("http://localhost:8480/services/LBService1"));

        options.setAction("urn:sampleOperation");

        long timeout = Integer.parseInt(getProperty("timeout", "10000000"));
        System.out.println("timeout=" + timeout);
        options.setTimeOutInMilliSeconds(timeout);

        // set addressing, transport and proxy url
        serviceClient.engageModule("addressing");
        options.setTo(new EndpointReference("http://localhost:8480"));

        serviceClient.setOptions(options);
        String testString = "";

        long i = 0;
        while (i < 100) {

            serviceClient.getOptions().setManageSession(true);
            OMElement responseElement = serviceClient.sendReceive(value);
            String response = responseElement.getText();

            i++;
            System.out.println("Request: " + i + " ==> " + response);
            testString = testString.concat(":" + i + ">" + response + ":");
        }

        return testString;
    }
 
Example 9
Source File: Attribute.java    From openxds with Apache License 2.0 5 votes vote down vote up
void validate_slot(String type, String id, List slots, String name, boolean multivalue, boolean required, boolean number) {
	boolean found = false;
	for (int i=0; i<slots.size(); i++) {
		OMElement slot = (OMElement) slots.get(i);
		String slot_name = slot.getAttributeValue(MetadataSupport.slot_name_qname);
		if ( slot_name == null || !slot_name.equals(name))
			continue;
		if (found)
			err(type + " " + id + " has multiple slots with name " + name);
		found = true;
		OMElement value_list = MetadataSupport.firstChildWithLocalName(slot, "ValueList");
		int value_count = 0;
		for (Iterator it=value_list.getChildElements(); it.hasNext(); ) {
			OMElement value = (OMElement) it.next();
			String value_string = value.getText();
			value_count++;
			if (number) {
				try {
					prove_int(value_string);
				} catch (Exception e) {
					err(type + " " + id + " the value of slot " + name + "(" + value_string + ") is required to be an integer");
				}
			} 
		}
		if (	(value_count > 1 && ! multivalue)   ||
				value_count == 0
		) 
			err(type + " " + id + " has slot " + name + " is required to have a single value");

	}
	if ( !found && required)
		err(type + " " + id + " does not have the required slot " + name);
}
 
Example 10
Source File: LDAPConfigurationBuilder.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Reads the properties mentioned under the XML Element in the config file, which is passed
 * as an OMElement to the method.
 *
 * @param omElement : main XML element whose properties should be read
 * @return : the map containing property names and the values.
 */
private Map<String, String> getChildPropertyElements(OMElement omElement) {
    Map<String, String> map = new HashMap<String, String>();
    Iterator<?> ite = omElement.getChildrenWithName(new QName(
            UserCoreConstants.RealmConfig.LOCAL_NAME_PROPERTY));
    while (ite.hasNext()) {
        OMElement propElem = (OMElement) ite.next();
        String propName = propElem.getAttributeValue(new QName(
                UserCoreConstants.RealmConfig.ATTR_NAME_PROP_NAME));
        String propValue = propElem.getText();
        map.put(propName, propValue);
    }
    return map;
}
 
Example 11
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 12
Source File: UserStoreConfigurationDeployer.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param propElem Property Element
 * @return If the element text can be encrypted
 */
private static boolean isEligibleTobeEncrypted(OMElement propElem) {
    String secAlias = propElem.getAttributeValue(new QName(UserStoreConfigurationConstants.SECURE_VAULT_NS,
            UserStoreConfigurationConstants.SECRET_ALIAS));
    if (secAlias == null) {
        String secretPropName = propElem.getAttributeValue(new QName(UserStoreConfigurationConstants.PROPERTY_ENCRYPT));
        if (secretPropName != null && secretPropName.equalsIgnoreCase("true")) {
            String plainText = propElem.getText();
            if (plainText != null) {
                return true;
            }
        }
    }
    return false;
}
 
Example 13
Source File: StockQuoteHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Digests the custom quote response and extracts the last trade price
 * @param result
 * @return
 * @throws javax.xml.stream.XMLStreamException
 *
 *      <CheckPriceResponse xmlns="http://ws.invesbot.com/" >
 *          <Code>IBM</Code>
 *          <Price>82.90</Price>
 *      </CheckPriceResponse>
 */
public static String parseCustomQuoteResponse(OMElement result) throws Exception {

    AXIOMXPath xPath = new AXIOMXPath("//ns:Price");
    xPath.addNamespace("ns","http://services.samples/xsd");
    OMElement price = (OMElement) xPath.selectSingleNode(result);        
    if (price != null) {
        return price.getText();
    } else {
        throw new Exception("Unexpected response : " + result);
    }
}
 
Example 14
Source File: PolicyEditorUtil.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public static PolicyElementDTO createPolicyElementDTO(String policy)
        throws EntitlementPolicyCreationException {

    PolicyElementDTO policyElementDTO = new PolicyElementDTO();
    OMElement omElement;
    try {
        omElement = AXIOMUtil.stringToOM(policy);
    } catch (XMLStreamException e) {
        throw new EntitlementPolicyCreationException("Policy can not be converted to OMElement");
    }

    if (omElement != null) {

        policyElementDTO.setPolicyName(omElement.
                getAttributeValue(new QName(EntitlementPolicyConstants.POLICY_ID)));

        String ruleCombiningAlgorithm = omElement.
                getAttributeValue(new QName(EntitlementPolicyConstants.RULE_ALGORITHM));

        try {
            policyElementDTO.setRuleCombiningAlgorithms(ruleCombiningAlgorithm.
                    split(PolicyEditorConstants.RULE_ALGORITHM_IDENTIFIER_3)[1]);
        } catch (Exception ignore) {
            policyElementDTO.setRuleCombiningAlgorithms(ruleCombiningAlgorithm.
                    split(PolicyEditorConstants.RULE_ALGORITHM_IDENTIFIER_1)[1]);
            // if this is also fails, can not edit the policy
        }

        Iterator iterator = omElement.getChildrenWithLocalName(EntitlementPolicyConstants.
                DESCRIPTION_ELEMENT);

        if (iterator.hasNext()) {
            OMElement descriptionElement = (OMElement) iterator.next();
            if (descriptionElement != null && descriptionElement.getText() != null) {
                policyElementDTO.setPolicyDescription(descriptionElement.getText().trim());
            }
        }

    }
    return policyElementDTO;
}
 
Example 15
Source File: OperationFactory.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static Operation createOperation(DataService dataService,
                                           OMElement opEl) throws DataServiceFault {
	String name = opEl.getAttributeValue(new QName(DBSFields.NAME));
	
	/* get the description */
	OMElement descEl = opEl.getFirstChildWithName(new QName(DBSFields.DESCRIPTION));
	String description = null;
	if (descEl != null) {
		description = descEl.getText();
	}
	
	CallQuery callQuery = null;

	List<CallQuery> callQueries = QueryFactory.createCallQueries(dataService,
                                                                    opEl.getChildrenWithName(new QName(DBSFields.CALL_QUERY)));
	if (callQueries.size() > 0) {
		callQuery = callQueries.get(0);
	}
   
	String disableStreamingRequestStr = opEl.getAttributeValue(
			new QName(DBSFields.DISABLE_STREAMING));
	boolean disableStreamingRequest = false;
	if (disableStreamingRequestStr != null) {
		disableStreamingRequest = Boolean.parseBoolean(disableStreamingRequestStr);
	}
	boolean disableStreamingEffective = disableStreamingRequest | dataService.isDisableStreaming();
	
    /* the last param is 'null' because, this is not a batch operation and 
     * there is no parent operation */
    Operation operation = new Operation(dataService, name, description,
                                           callQuery, false, null, disableStreamingRequest, disableStreamingEffective);
    
    String returnReqStatusStr = opEl.getAttributeValue(
			new QName(DBSFields.RETURN_REQUEST_STATUS));
	boolean returnReqStatus = false;
	if (returnReqStatusStr != null) {
		returnReqStatus = Boolean.parseBoolean(returnReqStatusStr);
	}
	operation.setReturnRequestStatus(returnReqStatus);
	
    return operation;
}
 
Example 16
Source File: SqlRepair.java    From openxds with Apache License 2.0 4 votes vote down vote up
public String get_query_text(OMElement query) throws XdsInternalException, SqlRepairException {
	OMElement element = find_sql_query_element(query);
	return element.getText();
}
 
Example 17
Source File: IdentityConfigParser.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
private boolean elementHasText(OMElement element) {
    String text = element.getText();
    return text != null && text.trim().length() != 0;
}
 
Example 18
Source File: LogFile.java    From openxds with Apache License 2.0 4 votes vote down vote up
public String getFatalError() {
	OMElement ele = MetadataSupport.firstChildWithLocalName(log, "FatalError");
	if (ele == null)
		return null;
	return ele.getText();
}
 
Example 19
Source File: ResourceFactory.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static Resource createResource(DataService dataService,
                                         OMElement resEl) throws DataServiceFault {
	String path = resEl.getAttributeValue(new QName(DBSFields.PATH));
	String method = resEl.getAttributeValue(new QName(DBSFields.METHOD));
	
	/* get the description */
	OMElement descEl = resEl.getFirstChildWithName(new QName(DBSFields.DESCRIPTION));
	String description = null;
	if (descEl != null) {
		description = descEl.getText();
	}
	
	CallQuery callQuery = null;
	List<CallQuery> callQueries = QueryFactory.createCallQueries(dataService,
                                                                    resEl.getChildrenWithName(new QName(DBSFields.CALL_QUERY)));
	if (callQueries.size() > 0) {
		callQuery = callQueries.get(0);
	}
	Resource.ResourceID resourceId = new Resource.ResourceID(path, method);
	
	String disableStreamingRequestStr = resEl.getAttributeValue(
			new QName(DBSFields.DISABLE_STREAMING));
	boolean disableStreamingRequest = false;
	if (disableStreamingRequestStr != null) {
		disableStreamingRequest = Boolean.parseBoolean(disableStreamingRequestStr);
	}
	boolean disableStreamingEffective = disableStreamingRequest | dataService.isDisableStreaming();
	
	Resource resource = new Resource(dataService, resourceId, description, callQuery, false, null,
                                        disableStreamingRequest, disableStreamingEffective);
	
    String returnReqStatusStr = resEl.getAttributeValue(
			new QName(DBSFields.RETURN_REQUEST_STATUS));
	boolean returnReqStatus = false;
	if (returnReqStatusStr != null) {
		returnReqStatus = Boolean.parseBoolean(returnReqStatusStr);
	}
	resource.setReturnRequestStatus(returnReqStatus);
	
	return resource;
}
 
Example 20
Source File: OutboundProvisioningConfig.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public static OutboundProvisioningConfig build(OMElement outboundProvisioningConfigOM) {
    OutboundProvisioningConfig outboundProvisioningConfig = new OutboundProvisioningConfig();

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

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

        if ("ProvisioningIdentityProviders".equals(elementName)) {

            Iterator<?> provisioningIdentityProvidersIter = element.getChildElements();
            List<IdentityProvider> provisioningIdentityProvidersArrList = new ArrayList<IdentityProvider>();

            if (provisioningIdentityProvidersIter != null) {
                while (provisioningIdentityProvidersIter.hasNext()) {
                    OMElement provisioningIdentityProvidersElement = (OMElement) (provisioningIdentityProvidersIter
                            .next());
                    IdentityProvider idp = IdentityProvider
                            .build(provisioningIdentityProvidersElement);
                    if (idp != null) {
                        provisioningIdentityProvidersArrList.add(idp);
                    }
                }
            }

            if (CollectionUtils.isNotEmpty(provisioningIdentityProvidersArrList)) {
                IdentityProvider[] provisioningIdentityProvidersArr = provisioningIdentityProvidersArrList
                        .toArray(new IdentityProvider[0]);
                outboundProvisioningConfig
                        .setProvisioningIdentityProviders(provisioningIdentityProvidersArr);
            }
        } else if ("ProvisionByRoleList".equals(elementName)) {

            Iterator<?> provisionByRoleListIter = element.getChildElements();
            List<String> provisionByRoleListArrList = new ArrayList<String>();

            if (provisionByRoleListIter != null) {
                while (provisionByRoleListIter.hasNext()) {
                    OMElement provisionByRoleListElement = (OMElement) (provisionByRoleListIter
                            .next());
                    if (provisionByRoleListElement.getText() != null) {
                        provisionByRoleListArrList.add(provisionByRoleListElement.getText());
                    }
                }
            }

            if (CollectionUtils.isNotEmpty(provisionByRoleListArrList)) {
                String[] provisionByRoleListArr = provisionByRoleListArrList
                        .toArray(new String[0]);
                outboundProvisioningConfig.setProvisionByRoleList(provisionByRoleListArr);
            }
        }
    }

    return outboundProvisioningConfig;
}