|
@@ -29,7 +29,8 @@ public class ConcurrentSessionsBeanDefinitionParser implements BeanDefinitionPar
|
|
|
static final String ATT_EXPIRY_URL = "expired-url";
|
|
|
static final String ATT_MAX_SESSIONS = "max-sessions";
|
|
|
static final String ATT_EXCEPTION_IF_MAX_EXCEEDED = "exception-if-maximum-exceeded";
|
|
|
- static final String ATT_SESSION_REGISTRY_ALIAS = "session-registry-alias";
|
|
|
+ static final String ATT_SESSION_REGISTRY_ALIAS = "session-registry-alias";
|
|
|
+ static final String ATT_SESSION_REGISTRY_REF = "session-registry-ref";
|
|
|
|
|
|
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
|
|
CompositeComponentDefinition compositeDef =
|
|
@@ -38,26 +39,43 @@ public class ConcurrentSessionsBeanDefinitionParser implements BeanDefinitionPar
|
|
|
|
|
|
BeanDefinitionRegistry beanRegistry = parserContext.getRegistry();
|
|
|
|
|
|
- RootBeanDefinition sessionRegistry = new RootBeanDefinition(SessionRegistryImpl.class);
|
|
|
+ String sessionRegistryId = element.getAttribute(ATT_SESSION_REGISTRY_REF);
|
|
|
+
|
|
|
+ if (!StringUtils.hasText(sessionRegistryId)) {
|
|
|
+ RootBeanDefinition sessionRegistry = new RootBeanDefinition(SessionRegistryImpl.class);
|
|
|
+ beanRegistry.registerBeanDefinition(BeanIds.SESSION_REGISTRY, sessionRegistry);
|
|
|
+ parserContext.registerComponent(new BeanComponentDefinition(sessionRegistry, BeanIds.SESSION_REGISTRY));
|
|
|
+ sessionRegistryId = BeanIds.SESSION_REGISTRY;
|
|
|
+ } else {
|
|
|
+ // Register the default ID as an alias so that things like session fixation filter can access it
|
|
|
+ beanRegistry.registerAlias(sessionRegistryId, BeanIds.SESSION_REGISTRY);
|
|
|
+ }
|
|
|
+
|
|
|
+ String registryAlias = element.getAttribute(ATT_SESSION_REGISTRY_ALIAS);
|
|
|
+ if (StringUtils.hasText(registryAlias)) {
|
|
|
+ beanRegistry.registerAlias(sessionRegistryId, registryAlias);
|
|
|
+ }
|
|
|
+
|
|
|
BeanDefinitionBuilder filterBuilder =
|
|
|
BeanDefinitionBuilder.rootBeanDefinition(ConcurrentSessionFilter.class);
|
|
|
- BeanDefinitionBuilder controllerBuilder
|
|
|
- = BeanDefinitionBuilder.rootBeanDefinition(ConcurrentSessionControllerImpl.class);
|
|
|
- controllerBuilder.addPropertyValue("sessionRegistry", new RuntimeBeanReference(BeanIds.SESSION_REGISTRY));
|
|
|
- filterBuilder.addPropertyValue("sessionRegistry", new RuntimeBeanReference(BeanIds.SESSION_REGISTRY));
|
|
|
+ filterBuilder.addPropertyValue("sessionRegistry", new RuntimeBeanReference(sessionRegistryId));
|
|
|
|
|
|
Object source = parserContext.extractSource(element);
|
|
|
filterBuilder.setSource(source);
|
|
|
filterBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
|
|
- controllerBuilder.setSource(source);
|
|
|
- controllerBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
|
|
-
|
|
|
+
|
|
|
String expiryUrl = element.getAttribute(ATT_EXPIRY_URL);
|
|
|
|
|
|
if (StringUtils.hasText(expiryUrl)) {
|
|
|
ConfigUtils.validateHttpRedirect(expiryUrl, parserContext, source);
|
|
|
filterBuilder.addPropertyValue("expiredUrl", expiryUrl);
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ BeanDefinitionBuilder controllerBuilder
|
|
|
+ = BeanDefinitionBuilder.rootBeanDefinition(ConcurrentSessionControllerImpl.class);
|
|
|
+ controllerBuilder.setSource(source);
|
|
|
+ controllerBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
|
|
+ controllerBuilder.addPropertyValue("sessionRegistry", new RuntimeBeanReference(sessionRegistryId));
|
|
|
|
|
|
String maxSessions = element.getAttribute(ATT_MAX_SESSIONS);
|
|
|
|
|
@@ -72,23 +90,14 @@ public class ConcurrentSessionsBeanDefinitionParser implements BeanDefinitionPar
|
|
|
}
|
|
|
|
|
|
BeanDefinition controller = controllerBuilder.getBeanDefinition();
|
|
|
- beanRegistry.registerBeanDefinition(BeanIds.SESSION_REGISTRY, sessionRegistry);
|
|
|
- parserContext.registerComponent(new BeanComponentDefinition(sessionRegistry, BeanIds.SESSION_REGISTRY));
|
|
|
|
|
|
- String registryAlias = element.getAttribute(ATT_SESSION_REGISTRY_ALIAS);
|
|
|
- if (StringUtils.hasText(registryAlias)) {
|
|
|
- beanRegistry.registerAlias(BeanIds.SESSION_REGISTRY, registryAlias);
|
|
|
- }
|
|
|
-
|
|
|
beanRegistry.registerBeanDefinition(BeanIds.CONCURRENT_SESSION_CONTROLLER, controller);
|
|
|
parserContext.registerComponent(new BeanComponentDefinition(controller, BeanIds.CONCURRENT_SESSION_CONTROLLER));
|
|
|
beanRegistry.registerBeanDefinition(BeanIds.CONCURRENT_SESSION_FILTER, filterBuilder.getBeanDefinition());
|
|
|
parserContext.registerComponent(new BeanComponentDefinition(filterBuilder.getBeanDefinition(), BeanIds.CONCURRENT_SESSION_FILTER));
|
|
|
ConfigUtils.addHttpFilter(parserContext, new RuntimeBeanReference(BeanIds.CONCURRENT_SESSION_FILTER));
|
|
|
|
|
|
- BeanDefinition providerManager = ConfigUtils.registerProviderManagerIfNecessary(parserContext);
|
|
|
-
|
|
|
- providerManager.getPropertyValues().addPropertyValue("sessionController", controller);
|
|
|
+ ConfigUtils.setSessionControllerOnAuthenticationManager(parserContext, BeanIds.CONCURRENT_SESSION_CONTROLLER, element);
|
|
|
|
|
|
parserContext.popAndRegisterContainingComponent();
|
|
|
|