|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -202,6 +202,14 @@ final class AuthenticationConfigBuilder {
|
202 | 202 |
|
203 | 203 | private BeanDefinition oauth2LoginLinks;
|
204 | 204 |
|
| 205 | + private BeanDefinition saml2AuthenticationUrlToProviderName; |
| 206 | + |
| 207 | + private BeanDefinition saml2AuthorizationRequestFilter; |
| 208 | + |
| 209 | + private String saml2AuthenticationFilterId; |
| 210 | + |
| 211 | + private String saml2AuthenticationRequestFilterId; |
| 212 | + |
205 | 213 | private boolean oauth2ClientEnabled;
|
206 | 214 |
|
207 | 215 | private BeanDefinition authorizationRequestRedirectFilter;
|
@@ -238,6 +246,7 @@ final class AuthenticationConfigBuilder {
|
238 | 246 | createFormLoginFilter(sessionStrategy, authenticationManager);
|
239 | 247 | createOAuth2ClientFilters(sessionStrategy, requestCache, authenticationManager);
|
240 | 248 | createOpenIDLoginFilter(sessionStrategy, authenticationManager);
|
| 249 | + createSaml2LoginFilter(authenticationManager); |
241 | 250 | createX509Filter(authenticationManager);
|
242 | 251 | createJeeFilter(authenticationManager);
|
243 | 252 | createLogoutFilter();
|
@@ -412,6 +421,29 @@ void createOpenIDLoginFilter(BeanReference sessionStrategy, BeanReference authMa
|
412 | 421 | }
|
413 | 422 | }
|
414 | 423 |
|
| 424 | + private void createSaml2LoginFilter(BeanReference authenticationManager) { |
| 425 | + Element saml2LoginElt = DomUtils.getChildElementByTagName(this.httpElt, Elements.SAML2_LOGIN); |
| 426 | + if (saml2LoginElt == null) { |
| 427 | + return; |
| 428 | + } |
| 429 | + Saml2LoginBeanDefinitionParser parser = new Saml2LoginBeanDefinitionParser(this.csrfIgnoreRequestMatchers, |
| 430 | + this.portMapper, this.portResolver, this.requestCache, this.allowSessionCreation, authenticationManager, |
| 431 | + this.authenticationProviders, this.defaultEntryPointMappings); |
| 432 | + BeanDefinition saml2WebSsoAuthenticationFilter = parser.parse(saml2LoginElt, this.pc); |
| 433 | + this.saml2AuthorizationRequestFilter = parser.getSaml2WebSsoAuthenticationRequestFilter(); |
| 434 | + |
| 435 | + this.saml2AuthenticationFilterId = this.pc.getReaderContext().generateBeanName(saml2WebSsoAuthenticationFilter); |
| 436 | + this.saml2AuthenticationRequestFilterId = this.pc.getReaderContext() |
| 437 | + .generateBeanName(this.saml2AuthorizationRequestFilter); |
| 438 | + this.saml2AuthenticationUrlToProviderName = parser.getSaml2AuthenticationUrlToProviderName(); |
| 439 | + |
| 440 | + // register the component |
| 441 | + this.pc.registerBeanComponent( |
| 442 | + new BeanComponentDefinition(saml2WebSsoAuthenticationFilter, this.saml2AuthenticationFilterId)); |
| 443 | + this.pc.registerBeanComponent(new BeanComponentDefinition(this.saml2AuthorizationRequestFilter, |
| 444 | + this.saml2AuthenticationRequestFilterId)); |
| 445 | + } |
| 446 | + |
415 | 447 | /**
|
416 | 448 | * Parses OpenID 1.0 and 2.0 - related parts of configuration xmls
|
417 | 449 | * @param sessionStrategy sessionStrategy
|
@@ -666,6 +698,12 @@ void createLoginPageFilterIfNeeded() {
|
666 | 698 | loginPageFilter.addPropertyValue("Oauth2LoginEnabled", true);
|
667 | 699 | loginPageFilter.addPropertyValue("Oauth2AuthenticationUrlToClientName", this.oauth2LoginLinks);
|
668 | 700 | }
|
| 701 | + if (this.saml2AuthenticationFilterId != null) { |
| 702 | + loginPageFilter.addConstructorArgReference(this.saml2AuthenticationFilterId); |
| 703 | + loginPageFilter.addPropertyValue("saml2LoginEnabled", true); |
| 704 | + loginPageFilter.addPropertyValue("saml2AuthenticationUrlToProviderName", |
| 705 | + this.saml2AuthenticationUrlToProviderName); |
| 706 | + } |
669 | 707 | this.loginPageGenerationFilter = loginPageFilter.getBeanDefinition();
|
670 | 708 | this.logoutPageGenerationFilter = logoutPageFilter.getBeanDefinition();
|
671 | 709 | }
|
@@ -840,7 +878,8 @@ private BeanMetadataElement selectEntryPoint() {
|
840 | 878 | if (formLoginElt != null && this.oauth2LoginEntryPoint != null) {
|
841 | 879 | return this.formEntryPoint;
|
842 | 880 | }
|
843 |
| - // If form login was enabled through auto-config, and Oauth2 login was not |
| 881 | + // If form login was enabled through auto-config, and Oauth2 login & Saml2 |
| 882 | + // login was not |
844 | 883 | // enabled then use form login
|
845 | 884 | if (this.oauth2LoginEntryPoint == null) {
|
846 | 885 | return this.formEntryPoint;
|
@@ -923,6 +962,12 @@ List<OrderDecorator> getFilters() {
|
923 | 962 | filters.add(new OrderDecorator(this.authorizationCodeGrantFilter,
|
924 | 963 | SecurityFilters.OAUTH2_AUTHORIZATION_CODE_GRANT_FILTER));
|
925 | 964 | }
|
| 965 | + if (this.saml2AuthenticationFilterId != null) { |
| 966 | + filters.add(new OrderDecorator(new RuntimeBeanReference(this.saml2AuthenticationFilterId), |
| 967 | + SecurityFilters.SAML2_AUTHENTICATION_FILTER)); |
| 968 | + filters.add(new OrderDecorator(new RuntimeBeanReference(this.saml2AuthenticationRequestFilterId), |
| 969 | + SecurityFilters.SAML2_AUTHENTICATION_REQUEST_FILTER)); |
| 970 | + } |
926 | 971 | filters.add(new OrderDecorator(this.etf, SecurityFilters.EXCEPTION_TRANSLATION_FILTER));
|
927 | 972 | return filters;
|
928 | 973 | }
|
|
0 commit comments