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

The following examples show how to use org.apache.axiom.om.OMElement#getChildrenWithLocalName() . 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: PolicyAttributeBuilder.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * This extract policy meta data from condition element in the policy
 *
 * @param omElement     condition element as an OMElement
 * @param attributeDTOs list of AttributeDTO object which holds the policy meta data
 *                      in String format
 * @return list of AttributeDTO object which holds the policy meta data in String format
 */
public List<AttributeDTO> createMetaDataFromConditionElement(OMElement omElement,
                                                             List<AttributeDTO> attributeDTOs) {

    Iterator iterator = omElement.getChildrenWithLocalName(PDPConstants.APPLY_ELEMENT);
    if (iterator.hasNext()) {
        if (version == XACMLConstants.XACML_VERSION_3_0) {
            createMetaDataFromXACML3ApplyElement(omElement, attributeDTOs);
        } else {
            createMetaDataFromApplyElement(omElement, attributeDTOs);
        }
    } else {
        AttributeDTO attributeDTO = new AttributeDTO();
        attributeDTO.setCategory(PDPConstants.UNKNOWN);
        attributeDTO.setAttributeValue(PDPConstants.SEARCH_WARNING_MESSAGE4);
    }

    // TODO currently only search meta data on Apply Element, support for other elements 
    return attributeDTOs;
}
 
Example 2
Source File: FileBasedConfigurationBuilder.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private void readTenantDataListenerURLs(OMElement documentElement) {
    OMElement tenantDataURLsElem =
            documentElement.getFirstChildWithName(IdentityApplicationManagementUtil.
                    getQNameWithIdentityApplicationNS(
                            FrameworkConstants.Config.QNAME_TENANT_DATA_LISTENER_URLS));

    if (tenantDataURLsElem != null) {
        for (Iterator tenantDataURLElems = tenantDataURLsElem.getChildrenWithLocalName(
                FrameworkConstants.Config.ELEM_TENANT_DATA_LISTENER_URL);
             tenantDataURLElems.hasNext(); ) {

            OMElement tenantDataListenerURLElem = (OMElement) tenantDataURLElems.next();
            if (tenantDataListenerURLElem != null &&
                StringUtils.isNotEmpty(tenantDataListenerURLElem.getText())) {
                tenantDataEndpointURLs.add(IdentityUtil.fillURLPlaceholders(tenantDataListenerURLElem.getText()));
            }
        }
    }
}
 
Example 3
Source File: EmailUserNameMigrationClient.java    From product-es with Apache License 2.0 6 votes vote down vote up
/**
 * This method checks whether there is a overview_provider in the overview table.
 * @param governanceArtifactConfiguration
 * @return
 * @throws RegistryException
 * @throws XMLStreamException
 */
private boolean hasOverviewProviderElement(GovernanceArtifactConfiguration governanceArtifactConfiguration)
        throws RegistryException, XMLStreamException {

    OMElement rxtContentOM = governanceArtifactConfiguration.getContentDefinition();
    Iterator tableNodes = rxtContentOM.getChildrenWithLocalName(Constants.TABLE);
    while (tableNodes.hasNext()) {
        OMElement tableOMElement = (OMElement) tableNodes.next();
        if (Constants.OVERVIEW.equalsIgnoreCase(tableOMElement.getAttributeValue(new QName(Constants.NAME)))) {
            Iterator fieldNodes = tableOMElement.getChildrenWithLocalName(Constants.FIELD);
            while (fieldNodes.hasNext()) {
                OMElement fieldElement = (OMElement) fieldNodes.next();
                OMElement nameElement = fieldElement.getFirstChildWithName(new QName(Constants.NAME));
                if (nameElement != null) {
                    if (Constants.PROVIDER.equalsIgnoreCase(nameElement.getText())) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 4
Source File: ESBSampleIntegrationTest.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Method to update current synapse config provided a new one.
 *
 * @param synapseConfig the new synapse configuration
 * @throws Exception if an error occurs during update
 */
protected void updateESBConfiguration(OMElement synapseConfig) throws Exception {

    if (synapseConfiguration == null) {
        synapseConfiguration = synapseConfig;
    } else {
        Iterator<OMElement> itr = synapseConfig.cloneOMElement().getChildElements();
        while (itr.hasNext()) {
            synapseConfiguration.addChild(itr.next());
        }
    }
    updateESBConfiguration(setEndpoints(synapseConfig), contextUrls.getBackEndUrl(), sessionCookie);

    if (context.getProductGroup().isClusterEnabled()) {
        long deploymentDelay = Long.parseLong(context.getConfigurationValue("//deploymentDelay"));
        Thread.sleep(deploymentDelay);
        Iterator<OMElement> proxies = synapseConfig.getChildrenWithLocalName("proxy");
        while (proxies.hasNext()) {
            String proxy = proxies.next().getAttributeValue(new QName("name"));

            Assert.assertTrue(isProxyWSDlExist(getProxyServiceURLHttp(proxy), deploymentDelay),
                    "Deployment Synchronizing failed in workers");
        }
    }
}
 
Example 5
Source File: FileBasedConfigurationBuilder.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private void readTenantDataListenerURLs(OMElement documentElement) {
    OMElement tenantDataURLsElem =
            documentElement.getFirstChildWithName(IdentityApplicationManagementUtil.
                    getQNameWithIdentityApplicationNS(
                            FrameworkConstants.Config.QNAME_TENANT_DATA_LISTENER_URLS));

    if (tenantDataURLsElem != null) {
        for (Iterator tenantDataURLElems = tenantDataURLsElem.getChildrenWithLocalName(
                FrameworkConstants.Config.ELEM_TENANT_DATA_LISTENER_URL);
             tenantDataURLElems.hasNext(); ) {

            OMElement tenantDataListenerURLElem = (OMElement) tenantDataURLElems.next();
            if (tenantDataListenerURLElem != null &&
                    StringUtils.isNotEmpty(tenantDataListenerURLElem.getText())) {
                tenantDataEndpointURLs.add(IdentityUtil.fillURLPlaceholders(tenantDataListenerURLElem.getText()));
            }
        }
    }
}
 
Example 6
Source File: LargeCSVTransformSmooksTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**                                            "
 * This test checks the completeness of the resulting XML, when we perform a smooks transformation in a csv file
 * which is large in size(>4K)
 */
@Test(groups = {"wso2.esb"}, description = "Tests the smooks transformation when large CSV files are sent")
public void testLargeCSVTransformSmooks() throws Exception {
    OMElement response;
    CSVInputRequestUtil testCSVInputRequest = new CSVInputRequestUtil();
    response = testCSVInputRequest.sendReceive(
            getProxyServiceURLHttp("smooksMediatorLargeCSVTestProxy"), generateCSVInput());
    Iterator csvRecs = response.getChildrenWithLocalName("csv-record");

    int recordCount = 0;
    while (csvRecs.hasNext()){
        Object o =csvRecs.next();
        recordCount++;
    }
    assertEquals(recordCount,RECORD_COUNT,"Smooks Mediator couldn't transform large CSV files(>4K) ");
}
 
Example 7
Source File: FileBasedConfigurationBuilder.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private void readIdpConfigs(OMElement documentElement) {
    OMElement idpConfigsElem = documentElement.getFirstChildWithName(IdentityApplicationManagementUtil.
            getQNameWithIdentityApplicationNS(FrameworkConstants.Config.QNAME_IDP_CONFIGS));

    if (idpConfigsElem != null) {
        // for each and every external idp defined, create an ExternalIdPConfig instance
        for (Iterator idpConfigElements = idpConfigsElem.getChildrenWithLocalName(FrameworkConstants.Config.ELEM_IDP_CONFIG);
             idpConfigElements.hasNext(); ) {

            ExternalIdPConfig idpConfig = processIdPConfigElement((OMElement) idpConfigElements.next());

            if (idpConfig != null) {
                idpList.add(idpConfig);
            }
        }
    }
}
 
Example 8
Source File: IdentityApplicationManagementUtil.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * @param configElem
 * @return
 */
public static Properties readProperties(OMElement configElem) {

    Properties properties = new Properties();
    OMElement propsElem = configElem
            .getFirstChildWithName(
                    getQNameWithIdentityApplicationNS(IdentityApplicationConstants.ConfigElements.PROPERTIES));
    if (propsElem != null) {
        Iterator propItr = propsElem
                .getChildrenWithLocalName(IdentityApplicationConstants.ConfigElements.PROPERTY);
        for (; propItr.hasNext(); ) {
            OMElement propElem = (OMElement) propItr.next();
            String propName = propElem.getAttributeValue(
                    new QName(IdentityApplicationConstants.ConfigElements.ATTR_NAME)).trim();
            String propValue = propElem.getText().trim();
            properties.put(propName, propValue);
            if (log.isDebugEnabled()) {
                log.debug("Property name : " + propName + ", Property Value : " + propValue);
            }
        }
    }
    return properties;
}
 
Example 9
Source File: PolicyAttributeBuilder.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * This extract policy meta data from target element in the policy
 *
 * @param omElement     target element as an OMElement
 * @param attributeDTOs list of AttributeDTO object which holds the policy meta data
 *                      in String format
 * @return list of AttributeDTO object which holds the policy meta data in String format
 */
public List<AttributeDTO> createMetaDataFromXACML3TargetElement(OMElement omElement,
                                                                List<AttributeDTO> attributeDTOs) {

    if (omElement != null) {

        Iterator iterator1 = omElement.
                getChildrenWithLocalName(PDPConstants.ANY_OF);
        while (iterator1.hasNext()) {

            OMElement anyOff = (OMElement) iterator1.next();

            Iterator iterator2 = anyOff.
                    getChildrenWithLocalName(PDPConstants.ALL_OF);

            while (iterator2.hasNext()) {
                OMElement allOf = (OMElement) iterator2.next();

                Iterator iterator3 = allOf.
                        getChildrenWithLocalName(PDPConstants.MATCH_ELEMENT);

                while (iterator3.hasNext()) {
                    OMElement resourceMatch = (OMElement) iterator3.next();
                    List<AttributeDTO> attributeDTOList =
                            createMetaDataFromXACML3MatchElement(resourceMatch);
                    for (AttributeDTO attributeDTO : attributeDTOList) {
                        attributeDTOs.add(attributeDTO);
                    }
                }
            }
        }
    }

    return attributeDTOs;
}
 
Example 10
Source File: ExtendedPasswordGrantHandler.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
private void parseRequiredHeaderClaimUris(OMElement requiredClaimUrisElem) {
    if (requiredClaimUrisElem == null) {
        return;
    }

    Iterator claimUris = requiredClaimUrisElem.getChildrenWithLocalName(CLAIM_URI);
    if (claimUris != null) {
        while (claimUris.hasNext()) {
            OMElement claimUri = (OMElement) claimUris.next();
            if (claimUri != null) {
                requiredHeaderClaimUris.add(claimUri.getText());
            }
        }
    }
}
 
Example 11
Source File: ESBIntegrationTest.java    From product-ei with Apache License 2.0 5 votes vote down vote up
protected void updateESBConfiguration(OMElement synapseConfig) throws Exception {

		if (synapseConfiguration == null) {
			synapseConfiguration = synapseConfig;
		} else {
			Iterator<OMElement> itr = synapseConfig.cloneOMElement().getChildElements();
			while (itr.hasNext()) {
				synapseConfiguration.addChild(itr.next());
			}
		}
		esbUtils.updateESBConfiguration(setEndpoints(synapseConfig), contextUrls.getBackEndUrl(), sessionCookie);

		if (context.getProductGroup().isClusterEnabled()) {
			long deploymentDelay = Long.parseLong(context.getConfigurationValue("//deploymentDelay"));
			Thread.sleep(deploymentDelay);
			Iterator<OMElement> proxies = synapseConfig.getChildrenWithLocalName("proxy");
			while (proxies.hasNext()) {
				String proxy = proxies.next().getAttributeValue(new QName("name"));

				Assert.assertTrue(isProxyWSDlExist(getProxyServiceURLHttp(proxy), deploymentDelay)
						, "Deployment Synchronizing failed in workers");
				Assert.assertTrue(isProxyWSDlExist(getProxyServiceURLHttp(proxy), deploymentDelay)
						, "Deployment Synchronizing failed in workers");
				Assert.assertTrue(isProxyWSDlExist(getProxyServiceURLHttp(proxy), deploymentDelay)
						, "Deployment Synchronizing failed in workers");
			}
		}
	}
 
Example 12
Source File: FileBasedConfigurationBuilder.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private ExternalIdPConfig processIdPConfigElement(OMElement idpConfigElem) {

        OMAttribute nameAttr = idpConfigElem.getAttribute(new QName("name"));

        // if the name is not given, do not register this config
        if (nameAttr == null) {
            log.warn("Each IDP configuration should have a unique name attribute");
            return null;
        }

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

        for (Iterator paramIterator = idpConfigElem.getChildrenWithLocalName("Parameter");
             paramIterator.hasNext(); ) {
            OMElement paramElem = (OMElement) paramIterator.next();
            OMAttribute paramNameAttr = paramElem.getAttribute(new QName("name"));

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

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

        IdentityProvider fedIdp = new IdentityProvider();
        fedIdp.setIdentityProviderName(nameAttr.getAttributeValue());
        ExternalIdPConfig externalIdPConfig = new ExternalIdPConfig(fedIdp);
        externalIdPConfig.setParameterMap(parameterMap);

        return externalIdPConfig;

    }
 
Example 13
Source File: AppDeployerUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Reads the root element of the required-features.xml file and returns a list of required
 * features for each and every artifact type.
 *
 * @param featureSets - root element of the required-features.xml
 * @return - map which includes the list of features for each artifact type
 */
public static Map<String, List<Feature>> readRequiredFeaturs(OMElement featureSets) {
    if (featureSets == null) {
        return null;
    }
    HashMap<String, List<Feature>> reqFeatureMap = new HashMap<String, List<Feature>>();

    // read featureSet elements
    Iterator itr = featureSets.getChildrenWithLocalName(AppDeployerConstants.FEATURE_SET);
    while (itr.hasNext()) {
        OMElement fsElement = (OMElement) itr.next();
        String artifactType = readAttribute(fsElement, AppDeployerConstants.ARTIFACT_TYPE);

        // read feature elements
        Iterator featureItr = fsElement.getChildrenWithLocalName(AppDeployerConstants.FEATURE);
        List<Feature> featureList = new ArrayList<Feature>();
        while (featureItr.hasNext()) {
            OMElement featureElement = (OMElement) featureItr.next();
            Feature requiredFeature = new Feature();
            requiredFeature.setId(readAttribute(featureElement, Feature.ID));
            requiredFeature.setVersionRange(readAttribute(featureElement, Feature.VERSION));
            featureList.add(requiredFeature);
        }
        reqFeatureMap.put(artifactType, featureList);
    }
    return reqFeatureMap;
}
 
Example 14
Source File: FileBasedConfigurationBuilder.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private ExternalIdPConfig processIdPConfigElement(OMElement idpConfigElem) {

        OMAttribute nameAttr = idpConfigElem.getAttribute(new QName("name"));

        // if the name is not given, do not register this config
        if (nameAttr == null) {
            log.warn("Each IDP configuration should have a unique name attribute");
            return null;
        }

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

        for (Iterator paramIterator = idpConfigElem.getChildrenWithLocalName("Parameter");
             paramIterator.hasNext(); ) {
            OMElement paramElem = (OMElement) paramIterator.next();
            OMAttribute paramNameAttr = paramElem.getAttribute(new QName("name"));

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

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

        IdentityProvider fedIdp = new IdentityProvider();
        fedIdp.setIdentityProviderName(nameAttr.getAttributeValue());
        ExternalIdPConfig externalIdPConfig = new ExternalIdPConfig(fedIdp);
        externalIdPConfig.setParameterMap(parameterMap);

        return externalIdPConfig;

    }
 
Example 15
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 16
Source File: APIManagerConfiguration.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
private void setRuntimeArtifactsSyncGatewayConfig (OMElement omElement){

        OMElement enableElement = omElement
                .getFirstChildWithName(new QName(APIConstants.GatewayArtifactSynchronizer.ENABLE_CONFIG));
        if (enableElement != null) {
            gatewayArtifactSynchronizerProperties.setRetrieveFromStorageEnabled(
                    JavaUtils.isTrueExplicitly(enableElement.getText()));
        } else {
            log.debug("Retrieve from storage is not set. Set to default false");
        }

        OMElement retrieverElement = omElement.getFirstChildWithName(
                new QName(APIConstants.GatewayArtifactSynchronizer.RETRIEVER_CONFIG));
        if (retrieverElement != null) {
            String artifactRetriever = retrieverElement.getText();
            gatewayArtifactSynchronizerProperties.setRetrieverName(artifactRetriever);
        } else {
            log.debug("Artifact retriever Element is not set. Set to default DB Retriever");
        }

        OMElement gatewayLabelElement = omElement
                .getFirstChildWithName(new QName(APIConstants.GatewayArtifactSynchronizer.GATEWAY_LABELS_CONFIG));
        if (gatewayLabelElement != null) {
            Iterator labelsIterator = gatewayLabelElement
                    .getChildrenWithLocalName(APIConstants.GatewayArtifactSynchronizer.LABEL_CONFIG);
            while (labelsIterator.hasNext()) {
                OMElement labelElement = (OMElement) labelsIterator.next();
                if (labelElement != null) {
                    gatewayArtifactSynchronizerProperties.getGatewayLabels().add(labelElement.getText());
                }
            }
        }
    }
 
Example 17
Source File: PropertyWithinSequenceTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = {"wso2.esb"}, description = "Defining a property within Iterator")
public void testPropertyWithinIteratorMediator() throws IOException, XMLStreamException {
    int responseCount = 0;
    for (int i = 0; i < 10; i++) {
        String Response = aggregatedRequestClient.getResponse();
        Assert.assertNotNull(Response);
        OMElement Response2 = AXIOMUtil.stringToOM(Response);
        OMElement soapBody = Response2.getFirstElement();
        Iterator iterator = soapBody.getChildrenWithLocalName("getQuoteResponse");

        while (iterator.hasNext()) {

            OMElement omeReturn = (OMElement) iterator.next();
            responseCount++;
            Iterator<OMElement> itr = omeReturn.getFirstElement().getChildrenWithLocalName("symbol");
            boolean isSymbolFound = false;
            while (itr.hasNext()) {
                OMElement symbol = itr.next();
                //to get the number attached by iterator mediator
                String[] values = symbol.getText().split(" ");
                Assert.assertEquals(values.length, 2, "Response does not contained the property value attached by Iterator mediator");
                double property = Double.parseDouble(values[1]);
                //value must be less tha to 16
                Assert.assertTrue(16 > property, "Value attached by Iterator mediator to response must be less than to 16");

                isSymbolFound = true;
            }
            Assert.assertTrue(isSymbolFound, "Symbol Element not found in the response message");
        }
        Assert.assertEquals(responseCount, responseCount, "Response does not contains all getQuoteResponses as in the request");
    }
}
 
Example 18
Source File: PolicyAttributeBuilder.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * This extract policy meta data from target element in the policy
 *
 * @param omElement     target element as an OMElement
 * @param attributeDTOs list of AttributeDTO object which holds the policy meta data
 *                      in String format
 * @return list of AttributeDTO object which holds the policy meta data in String format
 */
public List<AttributeDTO> createMetaDataFromXACML3TargetElement(OMElement omElement,
                                                                List<AttributeDTO> attributeDTOs) {

    if (omElement != null) {

        Iterator iterator1 = omElement.
                getChildrenWithLocalName(PDPConstants.ANY_OF);
        while (iterator1.hasNext()) {

            OMElement anyOff = (OMElement) iterator1.next();

            Iterator iterator2 = anyOff.
                    getChildrenWithLocalName(PDPConstants.ALL_OF);

            while (iterator2.hasNext()) {
                OMElement allOf = (OMElement) iterator2.next();

                Iterator iterator3 = allOf.
                        getChildrenWithLocalName(PDPConstants.MATCH_ELEMENT);

                while (iterator3.hasNext()) {
                    OMElement resourceMatch = (OMElement) iterator3.next();
                    List<AttributeDTO> attributeDTOList =
                            createMetaDataFromXACML3MatchElement(resourceMatch);
                    for (AttributeDTO attributeDTO : attributeDTOList) {
                        attributeDTOs.add(attributeDTO);
                    }
                }
            }
        }
    }

    return attributeDTOs;
}
 
Example 19
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 20
Source File: ApplicationConfiguration.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
/**
 * Builds the cApp configuration from the given OMElement which represents the artifacts.xml
 *
 * @param documentElement - root OMElement
 * @throws CarbonException - error while building
 */
private void buildConfiguration(OMElement documentElement) throws CarbonException {
    if (documentElement == null) {
        throw new CarbonException("Document element for artifacts.xml is null. Can't build " +
                "the cApp configuration");
    }

    Iterator artifactItr = documentElement.getChildrenWithLocalName(
            org.wso2.micro.application.deployer.config.Artifact.ARTIFACT);
    org.wso2.micro.application.deployer.config.Artifact appArtifact = null;
    while (artifactItr.hasNext()) {
        org.wso2.micro.application.deployer.config.Artifact temp = org.wso2.micro.application.deployer.AppDeployerUtils
                .populateArtifact((OMElement) artifactItr.next());
        if (org.wso2.micro.application.deployer.AppDeployerConstants.CARBON_APP_TYPE.equals(temp.getType())) {
            appArtifact = temp;
            break;
        }
    }
    if (appArtifact == null) {
        throw new CarbonException("artifacts.xml is invalid. No Artifact " +
                "found with the type - " + AppDeployerConstants.CARBON_APP_TYPE);
    }
    this.appName = appArtifact.getName();
    this.appVersion = appArtifact.getVersion();

    String[] serverRoles = AppDeployerUtils.readServerRoles();
    List<org.wso2.micro.application.deployer.config.Artifact.Dependency> depsToRemove = new ArrayList<org.wso2.micro.application.deployer.config.Artifact.Dependency>();

    /**
     * serverRoles contains regular expressions. So for each dependency's role, we have to
     * check whether there's a matching role from the list of serverRoles.
     */
    String role;
    for (org.wso2.micro.application.deployer.config.Artifact.Dependency dep : appArtifact.getDependencies()) {
        boolean matched = false;
        role = dep.getServerRole();
        // try to find a matching serverRole for this dep
        for (String currentRole : serverRoles) {
            if (role.matches(currentRole)) {
                matched = true;
                break;
            }
        }
        
        if (!matched) {
            depsToRemove.add(dep);
        }
    }

    // removing unwanted dependencies for the current server
    for (Artifact.Dependency item : depsToRemove) {
        appArtifact.removeDependency(item);
    }
    this.applicationArtifact = appArtifact;
}