use of org.springframework.beans.BeanMetadataElement in project spring-security-oauth by spring-projects.
the class OAuthProviderBeanDefinitionParser method parse.
public BeanDefinition parse(Element element, ParserContext parserContext) {
String consumerDetailsRef = element.getAttribute("consumer-details-service-ref");
String tokenServicesRef = element.getAttribute("token-services-ref");
BeanDefinitionBuilder requestTokenFilterBean = BeanDefinitionBuilder.rootBeanDefinition(UnauthenticatedRequestTokenProcessingFilter.class);
if (StringUtils.hasText(consumerDetailsRef)) {
requestTokenFilterBean.addPropertyReference("consumerDetailsService", consumerDetailsRef);
}
if (StringUtils.hasText(tokenServicesRef)) {
requestTokenFilterBean.addPropertyReference("tokenServices", tokenServicesRef);
}
String requestTokenURL = element.getAttribute("request-token-url");
if (StringUtils.hasText(requestTokenURL)) {
requestTokenFilterBean.addPropertyValue("filterProcessesUrl", requestTokenURL);
}
BeanDefinitionBuilder authenticateTokenFilterBean = BeanDefinitionBuilder.rootBeanDefinition(UserAuthorizationProcessingFilter.class);
authenticateTokenFilterBean.addPropertyReference("authenticationManager", BeanIds.AUTHENTICATION_MANAGER);
if (StringUtils.hasText(tokenServicesRef)) {
authenticateTokenFilterBean.addPropertyReference("tokenServices", tokenServicesRef);
}
String authenticateTokenURL = element.getAttribute("authenticate-token-url");
if (StringUtils.hasText(authenticateTokenURL)) {
authenticateTokenFilterBean.addPropertyValue("filterProcessesUrl", authenticateTokenURL);
}
String accessGrantedURL = element.getAttribute("access-granted-url");
if (!StringUtils.hasText(accessGrantedURL)) {
// create the simple URl handler and add it.
accessGrantedURL = "/";
}
authenticateTokenFilterBean.addConstructorArgValue(accessGrantedURL);
BeanDefinitionBuilder successfulAuthenticationHandler = BeanDefinitionBuilder.rootBeanDefinition(UserAuthorizationSuccessfulAuthenticationHandler.class);
successfulAuthenticationHandler.addConstructorArgValue(accessGrantedURL);
String callbackUrlParam = element.getAttribute("callback-url-param");
if (StringUtils.hasText(callbackUrlParam)) {
successfulAuthenticationHandler.addPropertyValue("callbackParameterName", callbackUrlParam);
}
// create a AuthenticationFailureHandler
BeanDefinitionBuilder simpleUrlAuthenticationFailureHandler = BeanDefinitionBuilder.rootBeanDefinition(SimpleUrlAuthenticationFailureHandler.class);
String authenticationFailedURL = element.getAttribute("authentication-failed-url");
if (StringUtils.hasText(authenticationFailedURL)) {
simpleUrlAuthenticationFailureHandler.addConstructorArgValue(authenticationFailedURL);
}
// create a AuthenticationFailureHandler
BeanDefinitionBuilder failedAuthenticationHandler = BeanDefinitionBuilder.rootBeanDefinition(SimpleUrlAuthenticationFailureHandler.class);
String userApprovalUrl = element.getAttribute("user-approval-url");
if (StringUtils.hasText(userApprovalUrl)) {
failedAuthenticationHandler.addConstructorArgValue(userApprovalUrl);
} else {
failedAuthenticationHandler.addConstructorArgValue("/");
}
String tokenIdParam = element.getAttribute("token-id-param");
if (StringUtils.hasText(tokenIdParam)) {
authenticateTokenFilterBean.addPropertyValue("tokenIdParameterName", tokenIdParam);
successfulAuthenticationHandler.addPropertyValue("tokenIdParameterName", tokenIdParam);
}
BeanDefinitionBuilder accessTokenFilterBean = BeanDefinitionBuilder.rootBeanDefinition(AccessTokenProcessingFilter.class);
if (StringUtils.hasText(consumerDetailsRef)) {
accessTokenFilterBean.addPropertyReference("consumerDetailsService", consumerDetailsRef);
}
if (StringUtils.hasText(tokenServicesRef)) {
accessTokenFilterBean.addPropertyReference("tokenServices", tokenServicesRef);
}
String accessTokenURL = element.getAttribute("access-token-url");
if (StringUtils.hasText(accessTokenURL)) {
accessTokenFilterBean.addPropertyValue("filterProcessesUrl", accessTokenURL);
}
BeanDefinitionBuilder protectedResourceFilterBean = BeanDefinitionBuilder.rootBeanDefinition(ProtectedResourceProcessingFilter.class);
if (StringUtils.hasText(consumerDetailsRef)) {
protectedResourceFilterBean.addPropertyReference("consumerDetailsService", consumerDetailsRef);
}
if (StringUtils.hasText(tokenServicesRef)) {
protectedResourceFilterBean.addPropertyReference("tokenServices", tokenServicesRef);
}
String nonceServicesRef = element.getAttribute("nonce-services-ref");
if (StringUtils.hasText(nonceServicesRef)) {
requestTokenFilterBean.addPropertyReference("nonceServices", nonceServicesRef);
accessTokenFilterBean.addPropertyReference("nonceServices", nonceServicesRef);
protectedResourceFilterBean.addPropertyReference("nonceServices", nonceServicesRef);
}
String supportRef = element.getAttribute("support-ref");
if (StringUtils.hasText(supportRef)) {
requestTokenFilterBean.addPropertyReference("providerSupport", supportRef);
accessTokenFilterBean.addPropertyReference("providerSupport", supportRef);
protectedResourceFilterBean.addPropertyReference("providerSupport", supportRef);
}
String authHandlerRef = element.getAttribute("auth-handler-ref");
if (StringUtils.hasText(authHandlerRef)) {
protectedResourceFilterBean.addPropertyReference("authHandler", authHandlerRef);
}
String require10a = element.getAttribute("require10a");
if (StringUtils.hasText(require10a)) {
requestTokenFilterBean.addPropertyValue("require10a", require10a);
authenticateTokenFilterBean.addPropertyValue("require10a", require10a);
accessTokenFilterBean.addPropertyValue("require10a", require10a);
successfulAuthenticationHandler.addPropertyValue("require10a", require10a);
}
String verifierServicesRef = element.getAttribute("verifier-services-ref");
if (!StringUtils.hasText(verifierServicesRef)) {
BeanDefinitionBuilder verifierServices = BeanDefinitionBuilder.rootBeanDefinition(RandomValueVerifierServices.class);
parserContext.getRegistry().registerBeanDefinition("oauthVerifierServices", verifierServices.getBeanDefinition());
verifierServicesRef = "oauthVerifierServices";
}
authenticateTokenFilterBean.addPropertyReference("verifierServices", verifierServicesRef);
// register the successfulAuthenticationHandler with the UserAuthorizationFilter
String oauthSuccessfulAuthenticationHandlerRef = "oauthSuccessfulAuthenticationHandler";
parserContext.getRegistry().registerBeanDefinition(oauthSuccessfulAuthenticationHandlerRef, successfulAuthenticationHandler.getBeanDefinition());
authenticateTokenFilterBean.addPropertyReference("authenticationSuccessHandler", oauthSuccessfulAuthenticationHandlerRef);
// register the failure handler with the UserAuthorizationFilter
String oauthFailedAuthenticationHandlerRef = "oauthFailedAuthenticationHandler";
parserContext.getRegistry().registerBeanDefinition(oauthFailedAuthenticationHandlerRef, failedAuthenticationHandler.getBeanDefinition());
authenticateTokenFilterBean.addPropertyReference("authenticationFailureHandler", oauthFailedAuthenticationHandlerRef);
List<BeanMetadataElement> filterChain = ConfigUtils.findFilterChain(parserContext, element.getAttribute("filter-chain-ref"));
int index = insertIndex(filterChain);
parserContext.getRegistry().registerBeanDefinition("oauthRequestTokenFilter", requestTokenFilterBean.getBeanDefinition());
filterChain.add(index++, new RuntimeBeanReference("oauthRequestTokenFilter"));
parserContext.getRegistry().registerBeanDefinition("oauthAuthenticateTokenFilter", authenticateTokenFilterBean.getBeanDefinition());
filterChain.add(index++, new RuntimeBeanReference("oauthAuthenticateTokenFilter"));
parserContext.getRegistry().registerBeanDefinition("oauthAccessTokenFilter", accessTokenFilterBean.getBeanDefinition());
filterChain.add(index++, new RuntimeBeanReference("oauthAccessTokenFilter"));
parserContext.getRegistry().registerBeanDefinition("oauthProtectedResourceFilter", protectedResourceFilterBean.getBeanDefinition());
filterChain.add(index++, new RuntimeBeanReference("oauthProtectedResourceFilter"));
return null;
}
use of org.springframework.beans.BeanMetadataElement in project spring-security-oauth by spring-projects.
the class ClientDetailsServiceBeanDefinitionParser method doParse.
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
List<Element> clientElements = DomUtils.getChildElementsByTagName(element, "client");
ManagedMap<String, BeanMetadataElement> clients = new ManagedMap<String, BeanMetadataElement>();
for (Element clientElement : clientElements) {
BeanDefinitionBuilder client = BeanDefinitionBuilder.rootBeanDefinition(BaseClientDetails.class);
String clientId = clientElement.getAttribute("client-id");
if (StringUtils.hasText(clientId)) {
client.addConstructorArgValue(clientId);
} else {
parserContext.getReaderContext().error("A client id must be supplied with the definition of a client.", clientElement);
}
String secret = clientElement.getAttribute("secret");
if (StringUtils.hasText(secret)) {
client.addPropertyValue("clientSecret", secret);
}
String resourceIds = clientElement.getAttribute("resource-ids");
if (StringUtils.hasText(clientId)) {
client.addConstructorArgValue(resourceIds);
} else {
client.addConstructorArgValue("");
}
String redirectUri = clientElement.getAttribute("redirect-uri");
String tokenValidity = clientElement.getAttribute("access-token-validity");
if (StringUtils.hasText(tokenValidity)) {
client.addPropertyValue("accessTokenValiditySeconds", tokenValidity);
}
String refreshValidity = clientElement.getAttribute("refresh-token-validity");
if (StringUtils.hasText(refreshValidity)) {
client.addPropertyValue("refreshTokenValiditySeconds", refreshValidity);
}
client.addConstructorArgValue(clientElement.getAttribute("scope"));
client.addConstructorArgValue(clientElement.getAttribute("authorized-grant-types"));
client.addConstructorArgValue(clientElement.getAttribute("authorities"));
if (StringUtils.hasText(redirectUri)) {
client.addConstructorArgValue(redirectUri);
}
client.addPropertyValue("autoApproveScopes", clientElement.getAttribute("autoapprove"));
clients.put(clientId, client.getBeanDefinition());
}
builder.addPropertyValue("clientDetailsStore", clients);
}
use of org.springframework.beans.BeanMetadataElement in project spring-framework by spring-projects.
the class DatabasePopulatorConfigUtils method createDatabasePopulator.
private static BeanDefinition createDatabasePopulator(Element element, List<Element> scripts, String execution) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CompositeDatabasePopulator.class);
boolean ignoreFailedDrops = element.getAttribute("ignore-failures").equals("DROPS");
boolean continueOnError = element.getAttribute("ignore-failures").equals("ALL");
ManagedList<BeanMetadataElement> delegates = new ManagedList<>();
for (Element scriptElement : scripts) {
String executionAttr = scriptElement.getAttribute("execution");
if (!StringUtils.hasText(executionAttr)) {
executionAttr = "INIT";
}
if (!execution.equals(executionAttr)) {
continue;
}
BeanDefinitionBuilder delegate = BeanDefinitionBuilder.genericBeanDefinition(ResourceDatabasePopulator.class);
delegate.addPropertyValue("ignoreFailedDrops", ignoreFailedDrops);
delegate.addPropertyValue("continueOnError", continueOnError);
// Use a factory bean for the resources so they can be given an order if a pattern is used
BeanDefinitionBuilder resourcesFactory = BeanDefinitionBuilder.genericBeanDefinition(SortedResourcesFactoryBean.class);
resourcesFactory.addConstructorArgValue(new TypedStringValue(scriptElement.getAttribute("location")));
delegate.addPropertyValue("scripts", resourcesFactory.getBeanDefinition());
if (StringUtils.hasLength(scriptElement.getAttribute("encoding"))) {
delegate.addPropertyValue("sqlScriptEncoding", new TypedStringValue(scriptElement.getAttribute("encoding")));
}
String separator = getSeparator(element, scriptElement);
if (separator != null) {
delegate.addPropertyValue("separator", new TypedStringValue(separator));
}
delegates.add(delegate.getBeanDefinition());
}
builder.addPropertyValue("populators", delegates);
return builder.getBeanDefinition();
}
Aggregations