Java Code Examples for org.apache.axiom.om.OMAttribute#getAttributeValue()

The following examples show how to use org.apache.axiom.om.OMAttribute#getAttributeValue() . 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: DataServiceCallMediatorFactory.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private List extractOperations(OMElement operationsElemet, DataServiceCallMediator mediator) {
    List operationsList = new ArrayList();
    Iterator operationIterator = operationsElemet.getChildElements();
    while (operationIterator.hasNext()) {
        OMElement operationEle = (OMElement) operationIterator.next();
        if (DataServiceCallMediatorConstants.OPERATION.equals(operationEle.getLocalName())) {
            OMAttribute nameAtr = operationEle.getAttribute(new QName(DataServiceCallMediatorConstants.NAME));
            if (nameAtr != null) {
                String operationName = nameAtr.getAttributeValue();
                List<Param> paramList = new ArrayList<>();
                if (operationEle.getFirstElement() != null && DataServiceCallMediatorConstants.PARAM.
                        equals(operationEle.getFirstElement().getLocalName())) {
                    paramList = extractParams(operationEle, mediator);
                }
                operationsList.add(mediator.new Operation(operationName, paramList));
            }
        } else if (DataServiceCallMediatorConstants.OPERATIONS.equals(operationEle.getLocalName())) {
            String operationType = operationEle.getAttributeValue(new QName(DataServiceCallMediatorConstants.TYPE));
            OperationsType operationsType = OperationsType.valueOf(operationType.toUpperCase());
            operationsList.add(mediator.new Operations(operationsType, extractOperations(operationEle, mediator)));
        } else {
            handleException("The 'operation' element is missing in the configuration.");
        }
    }
    return operationsList;
}
 
Example 2
Source File: Validator.java    From openxds with Apache License 2.0 6 votes vote down vote up
void validate_internal_classifications(OMElement e) throws MetadataValidationException, MetadataException {
	String e_id = e.getAttributeValue(MetadataSupport.id_qname);
	if (e_id == null || e_id.equals(""))
		return;
	for (Iterator it=e.getChildElements(); it.hasNext(); ) {
		OMElement child = (OMElement) it.next();
		OMAttribute classified_object_att = child.getAttribute(MetadataSupport.classified_object_qname);
		if (classified_object_att != null) {
			String value = classified_object_att.getAttributeValue();
			if ( !e_id.equals(value)) {
				throw new MetadataValidationException("Classification " + m.getIdentifyingString(child) + 
						"\n   is nested inside " + m.getIdentifyingString(e) +
						"\n   but classifies object " + m.getIdentifyingString(value));
			}
		}
	}
}
 
Example 3
Source File: IdParser.java    From openxds with Apache License 2.0 5 votes vote down vote up
public List getDefinedIds() {
	List defined = new ArrayList();

	for (Iterator it=this.identifyingAttributes.iterator(); it.hasNext(); ) {
		OMAttribute attr = (OMAttribute) it.next();
		String id = attr.getAttributeValue();

		if ( !defined.contains(id))
			defined.add(id);
	}

	return defined;
}
 
Example 4
Source File: Util.java    From openxds with Apache License 2.0 5 votes vote down vote up
public static String getAttributeValue(OMElement doc, String xpath) throws Exception {
	XPathEvaluator eval = new XPathEvaluator();
	List<OMNode> node_list = eval.evaluateXpath(xpath, doc, null);

	for (Iterator<?> it=node_list.iterator(); it.hasNext(); ) {
		OMAttribute attr = (OMAttribute) it.next();
		return attr.getAttributeValue();
	}
	throw new Exception("Path " + xpath + " not found");
}
 
Example 5
Source File: IdParser.java    From openxds with Apache License 2.0 5 votes vote down vote up
public List getReferencedIds() {
	List refer = new ArrayList();
	for (Iterator it=this.referencingAttributes.iterator(); it.hasNext(); ) {
		OMAttribute attr = (OMAttribute) it.next();
		String id = attr.getAttributeValue();

		if ( !refer.contains(id))
			refer.add(id);
	}

	return refer;
}
 
Example 6
Source File: RegistryErrorList.java    From openxds with Apache License 2.0 5 votes vote down vote up
HashMap<String, String> getErrorDetails(OMElement registryError) {
	HashMap<String, String>  err = new HashMap<String, String>();

	for (Iterator<OMAttribute> it=registryError.getAllAttributes(); it.hasNext(); ) {
		OMAttribute att = it.next();
		String name = att.getLocalName();
		String value = att.getAttributeValue();
		err.put(name, value);
	}

	return err;
}
 
Example 7
Source File: FileBasedConfigurationBuilder.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private void readAuthenticationEndpointRedirectParams(OMElement documentElement) {

        OMElement authEndpointRedirectParamsElem = documentElement.getFirstChildWithName(
                IdentityApplicationManagementUtil.getQNameWithIdentityApplicationNS(
                        FrameworkConstants.Config.QNAME_AUTH_ENDPOINT_REDIRECT_PARAMS));

        if (authEndpointRedirectParamsElem != null) {

            authEndpointRedirectParamsConfigAvailable = true;
            OMAttribute actionAttr = authEndpointRedirectParamsElem.getAttribute(new QName(
                    FrameworkConstants.Config.ATTR_AUTH_ENDPOINT_QUERY_PARAM_ACTION));
            OMAttribute removeOnConsumeAttr = authEndpointRedirectParamsElem.getAttribute(new QName(
                    FrameworkConstants.Config.REMOVE_PARAM_ON_CONSUME));
            authEndpointRedirectParamsAction = FrameworkConstants.AUTH_ENDPOINT_QUERY_PARAMS_ACTION_EXCLUDE;

            if (actionAttr != null) {
                String actionValue = actionAttr.getAttributeValue();

                if (actionValue != null && !actionValue.isEmpty()) {
                    authEndpointRedirectParamsAction = actionValue;
                }
            }

            if (removeOnConsumeAttr != null) {
                removeAPIParametersOnConsume = Boolean.parseBoolean(removeOnConsumeAttr.getAttributeValue());
            }

            for (Iterator authEndpointRedirectParamElems = authEndpointRedirectParamsElem
                    .getChildrenWithLocalName(FrameworkConstants.Config.ELEM_AUTH_ENDPOINT_REDIRECT_PARAM);
                 authEndpointRedirectParamElems.hasNext(); ) {
                String redirectParamName = processAuthEndpointQueryParamElem((OMElement) authEndpointRedirectParamElems
                        .next());

                if (redirectParamName != null) {
                    this.authEndpointRedirectParams.add(redirectParamName);
                }
            }
        }
    }
 
Example 8
Source File: FileBasedConfigurationBuilder.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private void readAuthenticationEndpointQueryParams(OMElement documentElement) {
    OMElement authEndpointQueryParamsElem = documentElement
            .getFirstChildWithName(IdentityApplicationManagementUtil
                    .getQNameWithIdentityApplicationNS(FrameworkConstants.Config.QNAME_AUTH_ENDPOINT_QUERY_PARAMS));

    if (authEndpointQueryParamsElem != null) {

        authEndpointQueryParamsConfigAvailable = true;
        OMAttribute actionAttr = authEndpointQueryParamsElem.getAttribute(new QName(
                FrameworkConstants.Config.ATTR_AUTH_ENDPOINT_QUERY_PARAM_ACTION));
        authEndpointQueryParamsAction = FrameworkConstants.AUTH_ENDPOINT_QUERY_PARAMS_ACTION_EXCLUDE;

        if (actionAttr != null) {
            String actionValue = actionAttr.getAttributeValue();

            if (actionValue != null && !actionValue.isEmpty()) {
                authEndpointQueryParamsAction = actionValue;
            }
        }

        for (Iterator authEndpointQueryParamElems = authEndpointQueryParamsElem
                .getChildrenWithLocalName(FrameworkConstants.Config.ELEM_AUTH_ENDPOINT_QUERY_PARAM); authEndpointQueryParamElems
                     .hasNext(); ) {
            String queryParamName = processAuthEndpointQueryParamElem((OMElement) authEndpointQueryParamElems
                    .next());

            if (queryParamName != null) {
                this.authEndpointQueryParams.add(queryParamName);
            }
        }
    }
}
 
Example 9
Source File: RegistryResponseParser.java    From openxds with Apache License 2.0 5 votes vote down vote up
String get_att(OMElement ele, String name) {
	OMAttribute att = ele.getAttribute(new QName(name));
	if (att == null)
		return null;
	return att.getAttributeValue();

}
 
Example 10
Source File: FileBasedConfigurationBuilder.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private void readAuthenticationEndpointQueryParams(OMElement documentElement) {
    OMElement authEndpointQueryParamsElem = documentElement
            .getFirstChildWithName(IdentityApplicationManagementUtil
                                           .getQNameWithIdentityApplicationNS(FrameworkConstants.Config.QNAME_AUTH_ENDPOINT_QUERY_PARAMS));

    if (authEndpointQueryParamsElem != null) {

        authEndpointQueryParamsConfigAvailable = true;
        OMAttribute actionAttr = authEndpointQueryParamsElem.getAttribute(new QName(
                FrameworkConstants.Config.ATTR_AUTH_ENDPOINT_QUERY_PARAM_ACTION));
        authEndpointQueryParamsAction = FrameworkConstants.AUTH_ENDPOINT_QUERY_PARAMS_ACTION_EXCLUDE;

        if (actionAttr != null) {
            String actionValue = actionAttr.getAttributeValue();

            if (actionValue != null && !actionValue.isEmpty()) {
                authEndpointQueryParamsAction = actionValue;
            }
        }


        for (Iterator authEndpointQueryParamElems = authEndpointQueryParamsElem
                .getChildrenWithLocalName(FrameworkConstants.Config.ELEM_AUTH_ENDPOINT_QUERY_PARAM); authEndpointQueryParamElems
                     .hasNext(); ) {
            String queryParamName = processAuthEndpointQueryParamElem((OMElement) authEndpointQueryParamElems
                    .next());

            if (queryParamName != null) {
                this.authEndpointQueryParams.add(queryParamName);
            }
        }
    }
}
 
Example 11
Source File: TransportBuilderUtils.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
/**
 * Processes transport parameters from the given configuration.
 * 
 * @param parameters An Iterator of OMElement which contains transport parameters.
 * @param parameterInclude ParameterInclude
 * @throws DeploymentException on error
 */
private static void processParameters(Iterator parameters,
                                         ParameterInclude parameterInclude) throws DeploymentException {

       if (parameters == null) {
           return;
       }

	while (parameters.hasNext()) {
		// this is to check whether some one has locked the parameter at the
		// top level
		OMElement parameterElement = (OMElement) parameters.next();
		Parameter parameter = new Parameter();
		// setting parameterElement
		parameter.setParameterElement(parameterElement);
		// setting parameter Name
		OMAttribute paramName = parameterElement.getAttribute(new QName(ATTRIBUTE_NAME));
		if (paramName == null) {
			throw new DeploymentException(Messages.getMessage(
					DeploymentErrorMsgs.BAD_PARAMETER_ARGUMENT, parameterElement.toString()));
		}
		parameter.setName(paramName.getAttributeValue());
		// setting parameter Value (the child element of the parameter)
		OMElement paramValue = parameterElement.getFirstElement();
		if (paramValue != null) {
			parameter.setValue(parameterElement);
			parameter.setParameterType(Parameter.OM_PARAMETER);
		} else {
			String paratextValue = parameterElement.getText();
			parameter.setValue(paratextValue);
			parameter.setParameterType(Parameter.TEXT_PARAMETER);
		}
		// setting locking attribute
		OMAttribute paramLocked = parameterElement.getAttribute(new QName(ATTRIBUTE_LOCKED));

		if (paramLocked != null) {
			String lockedValue = paramLocked.getAttributeValue();
			if (BOOLEAN_TRUE.equals(lockedValue)) {
				parameter.setLocked(true);
			} else {
				parameter.setLocked(false);
			}
		}
		try {
			parameterInclude.addParameter(parameter);
		} catch (AxisFault axisFault) {
			throw new DeploymentException(axisFault);
		}
	}
}
 
Example 12
Source File: ParameterUtil.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
/**
 * Create an Axis2 parameter using the given OMElement
 *
 * @param parameterElement The OMElement of the parameter
 * @return Axis2 parameter with an the given OMElement
 * @throws AxisFault If the <code>parameterElement</code> is malformed
 */
public static Parameter createParameter(OMElement parameterElement) throws AxisFault {
    if(parameterElement.getParent() instanceof OMDocument) {
        parameterElement.detach();  //To enable a unified way of accessing the parameter via xpath.
    }
    Parameter parameter = new Parameter();
    //setting parameterElement
    parameter.setParameterElement(parameterElement);

    //setting parameter Name
    OMAttribute paraName = parameterElement.getAttribute(new QName("name"));
    if (paraName == null) {
        throw new AxisFault(Messages.getMessage(DeploymentErrorMsgs.BAD_PARAMETER_ARGUMENT));
    }
    parameter.setName(paraName.getAttributeValue());

    //setting parameter Value (the chiled elemnt of the parameter)
    OMElement paraValue = parameterElement.getFirstElement();
    if (paraValue != null) {
        parameter.setValue(parameterElement);
        parameter.setParameterType(Parameter.OM_PARAMETER);
    } else {
        String paratextValue = parameterElement.getText();
        parameter.setValue(paratextValue);
        parameter.setParameterType(Parameter.TEXT_PARAMETER);
    }

    //setting locking attribute
    OMAttribute paraLocked = parameterElement.getAttribute(new QName("locked"));
    parameter.setParameterElement(parameterElement);

    if (paraLocked != null) {
        String lockedValue = paraLocked.getAttributeValue();
        if ("true".equals(lockedValue)) {

            parameter.setLocked(true);

        } else {
            parameter.setLocked(false);
        }
    }
    return parameter;
}
 
Example 13
Source File: FileBasedConfigurationBuilder.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Create SequenceDOs for each sequence entry
 *
 * @param sequenceElem
 * @return
 */
private SequenceConfig processSequenceElement(OMElement sequenceElem) {
    SequenceConfig sequenceConfig = new SequenceConfig();

    String applicationId = "default";
    OMAttribute appIdAttr = sequenceElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_APPLICATION_ID));

    if (appIdAttr != null) {
        applicationId = appIdAttr.getAttributeValue();
    }

    sequenceConfig.setApplicationId(applicationId);

    OMAttribute forceAuthnAttr = sequenceElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_FORCE_AUTHENTICATE));

    if (forceAuthnAttr != null) {
        sequenceConfig.setForceAuthn(Boolean.valueOf(forceAuthnAttr.getAttributeValue()));
    }

    OMAttribute checkAuthnAttr = sequenceElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_CHECK_AUTHENTICATE));

    if (checkAuthnAttr != null) {
        sequenceConfig.setCheckAuthn(Boolean.valueOf(checkAuthnAttr.getAttributeValue()));
    }

    //RequestPathAuthenticators
    OMElement reqPathAuthenticatorsElem = sequenceElem.getFirstChildWithName(IdentityApplicationManagementUtil.
            getQNameWithIdentityApplicationNS(FrameworkConstants.Config.ELEM_REQ_PATH_AUTHENTICATOR));

    if (reqPathAuthenticatorsElem != null) {

        for (Iterator reqPathAuthenticatorElems = reqPathAuthenticatorsElem.getChildElements(); reqPathAuthenticatorElems.hasNext(); ) {
            OMElement reqPathAuthenticatorElem = (OMElement) reqPathAuthenticatorElems.next();

            String authenticatorName = reqPathAuthenticatorElem.getAttributeValue(IdentityApplicationManagementUtil.
                    getQNameWithIdentityApplicationNS(FrameworkConstants.Config.ATTR_AUTHENTICATOR_NAME));
            AuthenticatorConfig authenticatorConfig = authenticatorConfigMap.get(authenticatorName);
            sequenceConfig.getReqPathAuthenticators().add(authenticatorConfig);
        }
    }

    // for each step defined, create a StepDO instance
    for (Iterator stepElements = sequenceElem.getChildrenWithLocalName(FrameworkConstants.Config.ELEM_STEP);
         stepElements.hasNext(); ) {
        StepConfig stepConfig = processStepElement((OMElement) stepElements.next());

        if (stepConfig != null) {
            sequenceConfig.getStepMap().put(stepConfig.getOrder(), stepConfig);
        }
    }

    return sequenceConfig;
}
 
Example 14
Source File: FileBasedConfigurationBuilder.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
/**
 * Create SequenceDOs for each sequence entry
 *
 * @param sequenceElem
 * @return
 */
private SequenceConfig processSequenceElement(OMElement sequenceElem) {
    SequenceConfig sequenceConfig = new SequenceConfig();

    String applicationId = "default";
    OMAttribute appIdAttr = sequenceElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_APPLICATION_ID));

    if (appIdAttr != null) {
        applicationId = appIdAttr.getAttributeValue();
    }

    sequenceConfig.setApplicationId(applicationId);

    OMAttribute forceAuthnAttr = sequenceElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_FORCE_AUTHENTICATE));

    if (forceAuthnAttr != null) {
        sequenceConfig.setForceAuthn(Boolean.valueOf(forceAuthnAttr.getAttributeValue()));
    }

    OMAttribute checkAuthnAttr = sequenceElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_CHECK_AUTHENTICATE));

    if (checkAuthnAttr != null) {
        sequenceConfig.setCheckAuthn(Boolean.valueOf(checkAuthnAttr.getAttributeValue()));
    }

    //RequestPathAuthenticators
    OMElement reqPathAuthenticatorsElem = sequenceElem.getFirstChildWithName(IdentityApplicationManagementUtil.
            getQNameWithIdentityApplicationNS(FrameworkConstants.Config.ELEM_REQ_PATH_AUTHENTICATOR));

    if (reqPathAuthenticatorsElem != null) {

        for (Iterator reqPathAuthenticatorElems = reqPathAuthenticatorsElem.getChildElements(); reqPathAuthenticatorElems.hasNext(); ) {
            OMElement reqPathAuthenticatorElem = (OMElement) reqPathAuthenticatorElems.next();

            String authenticatorName = reqPathAuthenticatorElem.getAttributeValue(IdentityApplicationManagementUtil.
                    getQNameWithIdentityApplicationNS(FrameworkConstants.Config.ATTR_AUTHENTICATOR_NAME));
            AuthenticatorConfig authenticatorConfig = authenticatorConfigMap.get(authenticatorName);
            sequenceConfig.getReqPathAuthenticators().add(authenticatorConfig);
        }
    }

    // for each step defined, create a StepDO instance
    for (Iterator stepElements = sequenceElem.getChildrenWithLocalName(FrameworkConstants.Config.ELEM_STEP);
         stepElements.hasNext(); ) {
        StepConfig stepConfig = processStepElement((OMElement) stepElements.next());

        if (stepConfig != null) {
            sequenceConfig.getStepMap().put(stepConfig.getOrder(), stepConfig);
        }
    }
    return sequenceConfig;
}
 
Example 15
Source File: MockIaasConfigParser.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
/**
 * Parse mock iaas configuration and return configuration object.
 *
 * @param filePath
 * @return
 */
public static MockIaasConfig parse(String filePath) {
    try {
        MockIaasConfig mockIaasConfig = new MockIaasConfig();
        MockHealthStatisticsConfig mockHealthStatisticsConfig = new MockHealthStatisticsConfig();
        mockIaasConfig.setMockHealthStatisticsConfig(mockHealthStatisticsConfig);

        OMElement document = AxiomXpathParserUtil.parse(new File(filePath));
        String enabledStr = document.getAttributeValue(ENABLED_ATTRIBUTE);
        if (StringUtils.isEmpty(enabledStr)) {
            throw new RuntimeException("Enabled attribute not found in mock-iaas element");
        }
        mockIaasConfig.setEnabled(Boolean.parseBoolean(enabledStr));

        Iterator statisticsIterator = document.getChildElements();

        while (statisticsIterator.hasNext()) {
            OMElement statisticsElement = (OMElement) statisticsIterator.next();

            if (HEALTH_STATISTICS_ELEMENT.equals(statisticsElement.getQName().getLocalPart())) {
                Iterator cartridgeIterator = statisticsElement.getChildElements();

                while (cartridgeIterator.hasNext()) {
                    OMElement cartridgeElement = (OMElement) cartridgeIterator.next();
                    OMAttribute typeAttribute = cartridgeElement.getAttribute(TYPE_ATTRIBUTE);
                    if (typeAttribute == null) {
                        throw new RuntimeException("Type attribute not found in cartridge element");
                    }
                    String cartridgeType = typeAttribute.getAttributeValue();
                    Iterator patternIterator = cartridgeElement.getChildElements();

                    while (patternIterator.hasNext()) {
                        OMElement patternElement = (OMElement) patternIterator.next();

                        OMAttribute factorAttribute = patternElement.getAttribute(FACTOR_ATTRIBUTE);
                        if (factorAttribute == null) {
                            throw new RuntimeException("Factor attribute not found in pattern element: " +
                                    "[cartridge-type] " + cartridgeType);
                        }
                        String factorStr = factorAttribute.getAttributeValue();
                        MockScalingFactor scalingFactor = convertScalingFactor(factorStr);

                        OMAttribute modeAttribute = patternElement.getAttribute(MODE_ATTRIBUTE);
                        if (modeAttribute == null) {
                            throw new RuntimeException("Mode attribute not found in pattern element: " +
                                    "[cartridge-type] " + cartridgeType);
                        }
                        String modeStr = modeAttribute.getAttributeValue();
                        StatisticsPatternMode mode = convertMode(modeStr);

                        String sampleValuesStr = null;
                        String sampleDurationStr = null;
                        Iterator patternChildIterator = patternElement.getChildElements();

                        while (patternChildIterator.hasNext()) {
                            OMElement patternChild = (OMElement) patternChildIterator.next();
                            if (SAMPLE_VALUES_ELEMENT.equals(patternChild.getQName().getLocalPart())) {
                                sampleValuesStr = patternChild.getText();
                            } else if (SAMPLE_DURATION_ELEMENT.equals(patternChild.getQName().getLocalPart())) {
                                sampleDurationStr = patternChild.getText();
                            }
                        }

                        if (sampleValuesStr == null) {
                            throw new RuntimeException("Sample values not found in pattern [factor] " + factorStr);
                        }
                        if (sampleDurationStr == null) {
                            throw new RuntimeException("Sample duration not found in pattern [factor] " + factorStr);
                        }

                        String[] sampleValuesArray = sampleValuesStr.split(",");
                        List<Integer> sampleValues = convertStringArrayToIntegerList(sampleValuesArray);
                        int sampleDuration = Integer.parseInt(sampleDurationStr);

                        MockHealthStatisticsPattern mockHealthStatisticsPattern = new MockHealthStatisticsPattern
                                (cartridgeType, scalingFactor, mode, sampleValues, sampleDuration);
                        mockHealthStatisticsConfig.addStatisticsPattern(mockHealthStatisticsPattern);
                    }
                }
            }
        }
        return mockIaasConfig;
    } catch (Exception e) {
        throw new RuntimeException("Could not parse mock health statistics configuration", e);
    }
}
 
Example 16
Source File: IdIndex.java    From openxds with Apache License 2.0 4 votes vote down vote up
public String getExternalIdentifierValue(String id, String identifier_scheme) {
	OMAttribute att = getExternalIdentifierAttribute(id, identifier_scheme);
	if (att == null)
		return null;
	return att.getAttributeValue();
}
 
Example 17
Source File: APIManagerConfiguration.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
private void setJWTTokenIssuers(OMElement omElement) {

        Iterator tokenIssuersElement =
                omElement.getChildrenWithLocalName(APIConstants.TokenIssuer.TOKEN_ISSUER);
        while (tokenIssuersElement.hasNext()) {
            OMElement issuerElement = (OMElement) tokenIssuersElement.next();
            String issuer = issuerElement.getAttributeValue(new QName("issuer"));
            TokenIssuerDto tokenIssuerDto = new TokenIssuerDto(issuer);
            OMElement jwksConfiguration =
                    issuerElement.getFirstChildWithName(new QName(APIConstants.TokenIssuer.JWKS_CONFIGURATION));
            if (jwksConfiguration != null) {
                JWKSConfigurationDTO jwksConfigurationDTO = tokenIssuerDto.getJwksConfigurationDTO();
                jwksConfigurationDTO.setEnabled(true);
                jwksConfigurationDTO.setUrl(jwksConfiguration
                        .getFirstChildWithName(new QName(APIConstants.TokenIssuer.JWKSConfiguration.URL)).getText());
            }
            OMElement claimMappingsElement =
                    issuerElement.getFirstChildWithName(new QName(APIConstants.TokenIssuer.CLAIM_MAPPINGS));
            if (claimMappingsElement != null) {
                OMAttribute disableDefaultClaimMappingAttribute =
                        claimMappingsElement.getAttribute(new QName("disable-default-claim-mapping"));
                if (disableDefaultClaimMappingAttribute != null) {
                    String disableDefaultClaimMapping = disableDefaultClaimMappingAttribute.getAttributeValue();
                    tokenIssuerDto.setDisableDefaultClaimMapping(Boolean.parseBoolean(disableDefaultClaimMapping));
                }
                Iterator claimMapping =
                        claimMappingsElement.getChildrenWithName(new QName(APIConstants.TokenIssuer.CLAIM_MAPPING));
                while (claimMapping.hasNext()) {
                    OMElement claim = (OMElement) claimMapping.next();
                    OMElement remoteClaimElement = claim.getFirstChildWithName(
                            new QName(APIConstants.TokenIssuer.ClaimMapping.REMOTE_CLAIM));
                    OMElement localClaimElement = claim.getFirstChildWithName(
                            new QName(APIConstants.TokenIssuer.ClaimMapping.LOCAL_CLAIM));
                    if (remoteClaimElement != null && localClaimElement != null) {
                        String remoteClaim = remoteClaimElement.getText();
                        String localClaim = localClaimElement.getText();
                        if (StringUtils.isNotEmpty(remoteClaim) &&
                                StringUtils.isNotEmpty(localClaim)) {
                            tokenIssuerDto.getClaimConfigurations().put(remoteClaim, new ClaimMappingDto(remoteClaim,
                                    localClaim));
                        }
                    }
                }
            }
            jwtConfigurationDto.getTokenIssuerDtoMap().put(tokenIssuerDto.getIssuer(), tokenIssuerDto);
        }
    }
 
Example 18
Source File: FileBasedConfigurationBuilder.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Create AuthenticatorBean elements for each authenticator entry
 *
 * @param authenticatorConfigElem OMElement for Authenticator
 * @return AuthenticatorBean object
 */
private AuthenticatorConfig processAuthenticatorConfigElement(OMElement authenticatorConfigElem) {

    // read the name of the authenticator. this is a mandatory attribute.
    OMAttribute nameAttr = authenticatorConfigElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_AUTHENTICATOR_CONFIG_NAME));
    // if the name is not given, do not register this authenticator
    if (nameAttr == null) {
        log.warn("Each Authenticator Configuration should have a unique name attribute. +" +
                 "This Authenticator will not be registered.");
        return null;
    }

    String authenticatorName = nameAttr.getAttributeValue();

    // check whether the disabled attribute is set
    boolean enabled = false;

    if (authenticatorConfigElem.getAttribute(IdentityApplicationManagementUtil.
            getQNameWithIdentityApplicationNS(FrameworkConstants.Config.ATTR_AUTHENTICATOR_ENABLED)) != null) {
        enabled = Boolean.parseBoolean(authenticatorConfigElem.getAttribute(IdentityApplicationManagementUtil.
                getQNameWithIdentityApplicationNS(FrameworkConstants.Config.ATTR_AUTHENTICATOR_ENABLED)).getAttributeValue());
    }

    // read the config parameters
    Map<String, String> parameterMap = new HashMap<>();

    for (Iterator paramIterator = authenticatorConfigElem.getChildrenWithLocalName(FrameworkConstants.Config.ELEM_PARAMETER);
         paramIterator.hasNext(); ) {
        OMElement paramElem = (OMElement) paramIterator.next();
        OMAttribute paramNameAttr = paramElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_PARAMETER_NAME));

        if (paramNameAttr == null) {
            log.warn("An Authenticator Parameter should have a name attribute. Skipping the parameter.");
            continue;
        }

        parameterMap.put(paramNameAttr.getAttributeValue(), paramElem.getText());
    }

    AuthenticatorConfig authenticatorConfig = new AuthenticatorConfig(authenticatorName, enabled, parameterMap);
    authenticatorConfig.setApplicationAuthenticator(FrameworkUtils.getAppAuthenticatorByName(authenticatorName));

    return authenticatorConfig;
}
 
Example 19
Source File: DataServiceCallMediatorFactory.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
private List<Param> extractParams(OMElement elem, DataServiceCallMediator mediator) {
    List<Param> paramList = new ArrayList<>();
    if (elem != null) {
        Iterator paramsIterator = elem.getChildrenWithName(new QName(DataServiceCallMediatorConstants.PARAM));
        while (paramsIterator.hasNext()) {
            OMElement paramElement = (OMElement) paramsIterator.next();
            OMAttribute nameAtr = paramElement.getAttribute(new QName(DataServiceCallMediatorConstants.NAME));

            if (nameAtr != null) {
                String paramName = nameAtr.getAttributeValue();
                String paramValue = paramElement.getAttributeValue(new QName(DataServiceCallMediatorConstants.VALUE));
                String paramType = paramElement.getAttributeValue(new QName(DataServiceCallMediatorConstants.TYPE));
                String evaluator = paramElement.getAttributeValue(new QName(DataServiceCallMediatorConstants.
                        EVALUATOR));
                String paramExpression = paramElement.getAttributeValue(new QName(DataServiceCallMediatorConstants.
                        EXPRESSION));
                Param param = mediator.new Param(paramName, paramType);
                param.setParamValue(paramValue);
                param.setEvaluator(evaluator);
                try {
                    if (paramExpression != null) {
                        if (evaluator != null && evaluator.equals(DataServiceCallMediatorConstants.JSON_TYPE)) {
                            if (paramExpression.startsWith("json-eval(")) {
                                paramExpression = paramExpression.substring(10, paramExpression.length() - 1);
                            }
                            param.setParamExpression(SynapseJsonPathFactory.getSynapseJsonPath(paramExpression));
                            // we have to explicitly define the path type since we are not going to mark
                            // JSON Path's with prefix "json-eval(".
                            param.getParamExpression().setPathType(SynapsePath.JSON_PATH);
                        } else {
                            SynapseXPath sxp = SynapseXPathFactory.getSynapseXPath(paramElement, ATT_EXPRN);
                            //we need to disable stream Xpath forcefully
                            sxp.setForceDisableStreamXpath(Boolean.TRUE);
                            param.setParamExpression(sxp);
                            param.getParamExpression().setPathType(SynapsePath.X_PATH);
                        }
                    }
                } catch (JaxenException e) {
                    handleException("Invalid XPath expression for attribute expression : " +
                            paramExpression, e);
                }
                paramList.add(param);
            }
        }
    }
    return paramList;
}
 
Example 20
Source File: DataServiceCallMediatorFactory.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
public Mediator createSpecificMediator(OMElement elem, Properties properties) {

        DataServiceCallMediator mediator = new DataServiceCallMediator();
        processAuditStatus(mediator, elem);
        String dsName = elem.getAttributeValue(new QName(DataServiceCallMediatorConstants.SERVICE_NAME));
        if (dsName == null) {
            handleException("The 'serviceName' attribute in 'dataServicesCall' element  is missing " +
                    "in the configuration.");
        }
        mediator.setDsName(dsName);
        OMElement operationsTypeElement = elem.getFirstElement();
        if (!operationsTypeElement.getLocalName().equals(DataServiceCallMediatorConstants.OPERATIONS)) {
            handleException("The 'operations' element in 'dataServicesCall' element  is missing in the configuration.");
        }
        String operationType = operationsTypeElement.getAttributeValue(new QName(DataServiceCallMediatorConstants.TYPE));
        if (operationType == null) {
            handleException("The 'type' attribute in 'operations' element  is missing in the configuration.");
        }
        OperationsType operationsType = OperationsType.valueOf(operationType.toUpperCase());
        List operationList = extractOperations(operationsTypeElement, mediator);
        if (OperationsType.SINGLE_REQ.equals(operationsType) && operationList.size() > 1) {
            handleException("The 'single operation' should contain one operation in the configuration.");
        }
        Operations operations = mediator.new Operations(operationsType, operationList);
        mediator.setOperations(operations);

        OMElement targetElement = elem.getFirstChildWithName(TARGET_Q);
        if (targetElement != null) {
            OMAttribute typeAtr = targetElement.getAttribute(TYPE_Q);
            if (typeAtr != null) {
                String type = typeAtr.getAttributeValue();
                mediator.setTargetType(type);
                if (type.equals(DataServiceCallMediatorConstants.PROPERTY)) {
                    OMAttribute propertyAtr = targetElement.getAttribute(NAME_Q);
                    if (propertyAtr != null) {
                        if (!propertyAtr.getAttributeValue().isEmpty()) {
                            String propertyName = propertyAtr.getAttributeValue();
                            mediator.setPropertyName(propertyName);
                        } else {
                            handleException("The 'name' attribute in 'target' element is empty. " +
                                    "Please enter a value.");
                        }
                    } else {
                        handleException("The 'name' attribute in 'target' element  is missing " +
                                "in the configuration.");
                    }
                }
            } else {
                handleException("The 'type' attribute in 'target' element is required for the configuration");
            }
        } else {
            handleException("The 'target' element is missing in the configuration.");
        }
        return mediator;
    }