Search in sources :

Example 1 with SPRING_BEANS_NS_URI

use of com.mulesoft.tools.migration.library.mule.steps.spring.SpringBeans.SPRING_BEANS_NS_URI in project mule-migration-assistant by mulesoft.

the class OAuth2ProviderConfig method migrateAuthorizationConfig.

private void migrateAuthorizationConfig(Element element, MigrationReport report) {
    final Element authorizationConfig = new Element("authorization-config", OAUTH2_PROVIDER_NAMESPACE);
    if (element.getAttributeValue("loginPage") != null) {
        authorizationConfig.setAttribute("loginPage", element.getAttributeValue("loginPage"));
        element.removeAttribute("loginPage");
    }
    final String path = element.getAttributeValue("authorizationEndpointPath");
    if (path != null) {
        authorizationConfig.setAttribute("path", path.startsWith("/") ? path : "/" + path);
        element.removeAttribute("authorizationEndpointPath");
    }
    if (element.getAttributeValue("authorizationCodeStore-ref") != null) {
        getApplicationModel().getNodeOptional("//*[namespace-uri() = '" + SPRING_BEANS_NS_URI + "' and local-name() = 'bean' and @name='" + element.getAttributeValue("authorizationCodeStore-ref") + "']").ifPresent(b -> {
            authorizationConfig.setAttribute("authorizationCodeStore", b.getAttributes().stream().filter(att -> "objectStore-ref".equals(att.getName())).map(att -> att.getValue()).findFirst().get());
        });
        element.removeAttribute("authorizationCodeStore-ref");
        if (element.getAttributeValue("authorizationTtlSeconds") != null) {
            report.report("oauth2Provider.authorizationTtl", element, authorizationConfig);
            element.removeAttribute("authorizationTtlSeconds");
        }
    }
    element.addContent(authorizationConfig);
}
Also used : HTTP_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE_URI) SPRING_BEANS_NS_URI(com.mulesoft.tools.migration.library.mule.steps.spring.SpringBeans.SPRING_BEANS_NS_URI) HttpInboundEndpoint.extractListenerConfig(com.mulesoft.tools.migration.library.mule.steps.http.HttpInboundEndpoint.extractListenerConfig) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors.joining(java.util.stream.Collectors.joining) Collections.singletonList(java.util.Collections.singletonList) HTTPS_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTPS_NAMESPACE_URI) HttpsInboundEndpoint.handleHttpsListenerConfig(com.mulesoft.tools.migration.library.mule.steps.http.HttpsInboundEndpoint.handleHttpsListenerConfig) HTTP_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) HTTPS_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTPS_NAMESPACE) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) Namespace(org.jdom2.Namespace) Namespace.getNamespace(org.jdom2.Namespace.getNamespace) Arrays.stream(java.util.Arrays.stream) Element(org.jdom2.Element) Element(org.jdom2.Element)

Example 2 with SPRING_BEANS_NS_URI

use of com.mulesoft.tools.migration.library.mule.steps.spring.SpringBeans.SPRING_BEANS_NS_URI in project mule-migration-assistant by mulesoft.

the class OAuth2ProviderConfig method migrateTokenConfig.

private void migrateTokenConfig(Element element, MigrationReport report) {
    final Element tokenConfig = new Element("token-config", OAUTH2_PROVIDER_NAMESPACE);
    final String path = element.getAttributeValue("accessTokenEndpointPath");
    if (path != null) {
        tokenConfig.setAttribute("path", path.startsWith("/") ? path : "/" + path);
        element.removeAttribute("accessTokenEndpointPath");
    }
    AtomicReference<Element> refreshTokens = new AtomicReference<>();
    if ("true".equals(element.getAttributeValue("enableRefreshToken"))) {
        if ("true".equals(element.getAttributeValue("issueNewRefreshToken"))) {
            refreshTokens.set(new Element("multiple-refresh-tokens", OAUTH2_PROVIDER_NAMESPACE));
        } else {
            refreshTokens.set(new Element("single-refresh-tokens", OAUTH2_PROVIDER_NAMESPACE));
        }
        element.removeAttribute("issueNewRefreshToken");
        tokenConfig.addContent(new Element("refresh-token-strategy", OAUTH2_PROVIDER_NAMESPACE).addContent(refreshTokens.get()));
        if (element.getAttributeValue("refreshTokenTtlSeconds") != null) {
            report.report("oauth2Provider.refreshTokenTtl", element, tokenConfig);
            element.removeAttribute("refreshTokenTtlSeconds");
        }
    }
    element.removeAttribute("enableRefreshToken");
    getApplicationModel().getNodeOptional("//*[namespace-uri() = '" + SPRING_BEANS_NS_URI + "' and local-name() = 'bean' and @name='" + element.getAttributeValue("tokenStore-ref") + "']").ifPresent(b -> {
        tokenConfig.setAttribute("tokenStore", b.getAttributes().stream().filter(att -> "accessTokenObjectStore-ref".equals(att.getName())).map(att -> att.getValue()).findFirst().get());
        if (refreshTokens.get() != null) {
            refreshTokens.get().setAttribute("objectStore", b.getAttributes().stream().filter(att -> "refreshTokenObjectStore-ref".equals(att.getName())).map(att -> att.getValue()).findFirst().get());
        }
    });
    if (element.getAttributeValue("tokenStore-ref") != null) {
        element.removeAttribute("tokenStore-ref");
        if (element.getAttributeValue("tokenTtlSeconds") != null) {
            report.report("oauth2Provider.tokenTtl", element, tokenConfig);
            element.removeAttribute("tokenTtlSeconds");
        }
    }
    element.addContent(tokenConfig);
}
Also used : HTTP_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE_URI) SPRING_BEANS_NS_URI(com.mulesoft.tools.migration.library.mule.steps.spring.SpringBeans.SPRING_BEANS_NS_URI) HttpInboundEndpoint.extractListenerConfig(com.mulesoft.tools.migration.library.mule.steps.http.HttpInboundEndpoint.extractListenerConfig) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors.joining(java.util.stream.Collectors.joining) Collections.singletonList(java.util.Collections.singletonList) HTTPS_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTPS_NAMESPACE_URI) HttpsInboundEndpoint.handleHttpsListenerConfig(com.mulesoft.tools.migration.library.mule.steps.http.HttpsInboundEndpoint.handleHttpsListenerConfig) HTTP_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) HTTPS_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTPS_NAMESPACE) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) Namespace(org.jdom2.Namespace) Namespace.getNamespace(org.jdom2.Namespace.getNamespace) Arrays.stream(java.util.Arrays.stream) Element(org.jdom2.Element) Element(org.jdom2.Element) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

HTTPS_NAMESPACE (com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTPS_NAMESPACE)2 HTTPS_NAMESPACE_URI (com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTPS_NAMESPACE_URI)2 HTTP_NAMESPACE (com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE)2 HTTP_NAMESPACE_URI (com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE_URI)2 HttpInboundEndpoint.extractListenerConfig (com.mulesoft.tools.migration.library.mule.steps.http.HttpInboundEndpoint.extractListenerConfig)2 HttpsInboundEndpoint.handleHttpsListenerConfig (com.mulesoft.tools.migration.library.mule.steps.http.HttpsInboundEndpoint.handleHttpsListenerConfig)2 SPRING_BEANS_NS_URI (com.mulesoft.tools.migration.library.mule.steps.spring.SpringBeans.SPRING_BEANS_NS_URI)2 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)2 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)2 XmlDslUtils.addElementAfter (com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter)2 Arrays.stream (java.util.Arrays.stream)2 Collections.singletonList (java.util.Collections.singletonList)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Collectors.joining (java.util.stream.Collectors.joining)2 Element (org.jdom2.Element)2 Namespace (org.jdom2.Namespace)2 Namespace.getNamespace (org.jdom2.Namespace.getNamespace)2