|
|
@@ -29,7 +29,7 @@ public class FormLoginBeanDefinitionParser implements BeanDefinitionParser {
|
|
|
static final String DEF_LOGIN_PAGE = DefaultLoginPageGeneratingFilter.DEFAULT_LOGIN_PAGE_URL;
|
|
|
|
|
|
static final String ATT_FORM_LOGIN_TARGET_URL = "default-target-url";
|
|
|
- static final String ATT_ALWAYS_USE_DEFAULT_TARGET_URL = "always-use-default-target";
|
|
|
+ static final String ATT_ALWAYS_USE_DEFAULT_TARGET_URL = "always-use-default-target";
|
|
|
static final String DEF_FORM_LOGIN_TARGET_URL = "/";
|
|
|
|
|
|
static final String ATT_FORM_LOGIN_AUTHENTICATION_FAILURE_URL = "authentication-failure-url";
|
|
|
@@ -37,14 +37,14 @@ public class FormLoginBeanDefinitionParser implements BeanDefinitionParser {
|
|
|
|
|
|
String defaultLoginProcessingUrl;
|
|
|
String filterClassName;
|
|
|
-
|
|
|
+
|
|
|
RootBeanDefinition filterBean;
|
|
|
RootBeanDefinition entryPointBean;
|
|
|
String loginPage;
|
|
|
-
|
|
|
+
|
|
|
FormLoginBeanDefinitionParser(String defaultLoginProcessingUrl, String filterClassName) {
|
|
|
- this.defaultLoginProcessingUrl = defaultLoginProcessingUrl;
|
|
|
- this.filterClassName = filterClassName;
|
|
|
+ this.defaultLoginProcessingUrl = defaultLoginProcessingUrl;
|
|
|
+ this.filterClassName = filterClassName;
|
|
|
}
|
|
|
|
|
|
public BeanDefinition parse(Element elt, ParserContext pc) {
|
|
|
@@ -52,23 +52,23 @@ public class FormLoginBeanDefinitionParser implements BeanDefinitionParser {
|
|
|
String defaultTargetUrl = null;
|
|
|
String authenticationFailureUrl = null;
|
|
|
String alwaysUseDefault = null;
|
|
|
-
|
|
|
+
|
|
|
Object source = null;
|
|
|
|
|
|
- // Copy values from the session fixation protection filter
|
|
|
- final Boolean sessionFixationProtectionEnabled =
|
|
|
+ // Copy values from the session fixation protection filter
|
|
|
+ final Boolean sessionFixationProtectionEnabled =
|
|
|
new Boolean(pc.getRegistry().containsBeanDefinition(BeanIds.SESSION_FIXATION_PROTECTION_FILTER));
|
|
|
Boolean migrateSessionAttributes = Boolean.FALSE;
|
|
|
-
|
|
|
+
|
|
|
if (sessionFixationProtectionEnabled.booleanValue()) {
|
|
|
- PropertyValue pv =
|
|
|
+ PropertyValue pv =
|
|
|
pc.getRegistry().getBeanDefinition(BeanIds.SESSION_FIXATION_PROTECTION_FILTER)
|
|
|
.getPropertyValues().getPropertyValue("migrateSessionAttributes");
|
|
|
- migrateSessionAttributes = (Boolean)pv.getValue();
|
|
|
- }
|
|
|
-
|
|
|
+ migrateSessionAttributes = (Boolean)pv.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
if (elt != null) {
|
|
|
- source = pc.extractSource(elt);
|
|
|
+ source = pc.extractSource(elt);
|
|
|
loginUrl = elt.getAttribute(ATT_LOGIN_URL);
|
|
|
ConfigUtils.validateHttpRedirect(loginUrl, pc, source);
|
|
|
defaultTargetUrl = elt.getAttribute(ATT_FORM_LOGIN_TARGET_URL);
|
|
|
@@ -77,58 +77,58 @@ public class FormLoginBeanDefinitionParser implements BeanDefinitionParser {
|
|
|
ConfigUtils.validateHttpRedirect(authenticationFailureUrl, pc, source);
|
|
|
alwaysUseDefault = elt.getAttribute(ATT_ALWAYS_USE_DEFAULT_TARGET_URL);
|
|
|
loginPage = elt.getAttribute(ATT_LOGIN_PAGE);
|
|
|
-
|
|
|
+
|
|
|
if (!StringUtils.hasText(loginPage)) {
|
|
|
- loginPage = null;
|
|
|
+ loginPage = null;
|
|
|
}
|
|
|
ConfigUtils.validateHttpRedirect(loginPage, pc, source);
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
ConfigUtils.registerProviderManagerIfNecessary(pc);
|
|
|
-
|
|
|
+
|
|
|
filterBean = createFilterBean(loginUrl, defaultTargetUrl, alwaysUseDefault, loginPage, authenticationFailureUrl);
|
|
|
filterBean.setSource(source);
|
|
|
filterBean.getPropertyValues().addPropertyValue("authenticationManager",
|
|
|
new RuntimeBeanReference(BeanIds.AUTHENTICATION_MANAGER));
|
|
|
-
|
|
|
- filterBean.getPropertyValues().addPropertyValue("invalidateSessionOnSuccessfulAuthentication",
|
|
|
+
|
|
|
+ filterBean.getPropertyValues().addPropertyValue("invalidateSessionOnSuccessfulAuthentication",
|
|
|
sessionFixationProtectionEnabled);
|
|
|
- filterBean.getPropertyValues().addPropertyValue("migrateInvalidatedSessionAttributes",
|
|
|
- migrateSessionAttributes);
|
|
|
-
|
|
|
+ filterBean.getPropertyValues().addPropertyValue("migrateInvalidatedSessionAttributes",
|
|
|
+ migrateSessionAttributes);
|
|
|
+
|
|
|
if (pc.getRegistry().containsBeanDefinition(BeanIds.REMEMBER_ME_SERVICES)) {
|
|
|
- filterBean.getPropertyValues().addPropertyValue("rememberMeServices",
|
|
|
+ filterBean.getPropertyValues().addPropertyValue("rememberMeServices",
|
|
|
new RuntimeBeanReference(BeanIds.REMEMBER_ME_SERVICES) );
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (pc.getRegistry().containsBeanDefinition(BeanIds.SESSION_REGISTRY)) {
|
|
|
- filterBean.getPropertyValues().addPropertyValue("sessionRegistry",
|
|
|
+ filterBean.getPropertyValues().addPropertyValue("sessionRegistry",
|
|
|
new RuntimeBeanReference(BeanIds.SESSION_REGISTRY));
|
|
|
}
|
|
|
|
|
|
BeanDefinitionBuilder entryPointBuilder =
|
|
|
BeanDefinitionBuilder.rootBeanDefinition(AuthenticationProcessingFilterEntryPoint.class);
|
|
|
- entryPointBuilder.setSource(source);
|
|
|
+ entryPointBuilder.getRawBeanDefinition().setSource(source);
|
|
|
entryPointBuilder.addPropertyValue("loginFormUrl", loginPage != null ? loginPage : DEF_LOGIN_PAGE);
|
|
|
entryPointBean = (RootBeanDefinition) entryPointBuilder.getBeanDefinition();
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private RootBeanDefinition createFilterBean(String loginUrl, String defaultTargetUrl, String alwaysUseDefault,
|
|
|
- String loginPage, String authenticationFailureUrl) {
|
|
|
-
|
|
|
+ private RootBeanDefinition createFilterBean(String loginUrl, String defaultTargetUrl, String alwaysUseDefault,
|
|
|
+ String loginPage, String authenticationFailureUrl) {
|
|
|
+
|
|
|
BeanDefinitionBuilder filterBuilder = BeanDefinitionBuilder.rootBeanDefinition(filterClassName);
|
|
|
|
|
|
if (!StringUtils.hasText(loginUrl)) {
|
|
|
- loginUrl = defaultLoginProcessingUrl;
|
|
|
+ loginUrl = defaultLoginProcessingUrl;
|
|
|
}
|
|
|
|
|
|
if ("true".equals(alwaysUseDefault)) {
|
|
|
- filterBuilder.addPropertyValue("alwaysUseDefaultTargetUrl", Boolean.TRUE);
|
|
|
+ filterBuilder.addPropertyValue("alwaysUseDefaultTargetUrl", Boolean.TRUE);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
filterBuilder.addPropertyValue("filterProcessesUrl", loginUrl);
|
|
|
|
|
|
if (!StringUtils.hasText(defaultTargetUrl)) {
|
|
|
@@ -138,12 +138,12 @@ public class FormLoginBeanDefinitionParser implements BeanDefinitionParser {
|
|
|
filterBuilder.addPropertyValue("defaultTargetUrl", defaultTargetUrl);
|
|
|
|
|
|
if (!StringUtils.hasText(authenticationFailureUrl)) {
|
|
|
- // Fallback to redisplaying the custom login page, if one was specified
|
|
|
- if (StringUtils.hasText(loginPage)) {
|
|
|
- authenticationFailureUrl = loginPage;
|
|
|
- } else {
|
|
|
+ // Fallback to redisplaying the custom login page, if one was specified
|
|
|
+ if (StringUtils.hasText(loginPage)) {
|
|
|
+ authenticationFailureUrl = loginPage;
|
|
|
+ } else {
|
|
|
authenticationFailureUrl = DEF_FORM_LOGIN_AUTHENTICATION_FAILURE_URL;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
filterBuilder.addPropertyValue("authenticationFailureUrl", authenticationFailureUrl);
|
|
|
@@ -151,15 +151,15 @@ public class FormLoginBeanDefinitionParser implements BeanDefinitionParser {
|
|
|
return (RootBeanDefinition) filterBuilder.getBeanDefinition();
|
|
|
}
|
|
|
|
|
|
- RootBeanDefinition getFilterBean() {
|
|
|
- return filterBean;
|
|
|
- }
|
|
|
+ RootBeanDefinition getFilterBean() {
|
|
|
+ return filterBean;
|
|
|
+ }
|
|
|
|
|
|
- RootBeanDefinition getEntryPointBean() {
|
|
|
- return entryPointBean;
|
|
|
- }
|
|
|
+ RootBeanDefinition getEntryPointBean() {
|
|
|
+ return entryPointBean;
|
|
|
+ }
|
|
|
|
|
|
- String getLoginPage() {
|
|
|
- return loginPage;
|
|
|
- }
|
|
|
+ String getLoginPage() {
|
|
|
+ return loginPage;
|
|
|
+ }
|
|
|
}
|