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);
}
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);
}
Aggregations