SessionAuthenticationStrategy . :
public class MatcherSessionAuthenticationStrategy implements SessionAuthenticationStrategy {
private final SessionAuthenticationStrategy delegate;
private final RequestMatcher matcher;
public MatcherSessionAuthenticationStrategy(
SessionAuthenticationStrategy delegate, RequestMatcher matcher) {
super();
this.delegate = delegate;
this.matcher = matcher;
}
public void onAuthentication(Authentication authentication,
HttpServletRequest request, HttpServletResponse response)
throws SessionAuthenticationException {
if(matcher.matches(request)) {
delegate.onAuthentication(authentication, request, response);
}
}
}
RequestMatcher ConcurrentSessionControlAuthenticationStrategy. - BeanPostProcessor:
public class ConcurrentSessionControlAuthenticationStrategyBeanPostProcessor
implements BeanPostProcessor {
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
return bean;
}
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
if(!(bean instanceof CompositeSessionAuthenticationStrategy)) {
return bean;
}
RequestMatcher matcher = antMatchers("/about", "/","/contact");
SessionAuthenticationStrategy original = (SessionAuthenticationStrategy) bean;
return new MatcherSessionAuthenticationStrategy(original, matcher);
}
public static RequestMatcher antMatchers(
String... antPatterns) {
List<RequestMatcher> matchers = new ArrayList<RequestMatcher>();
for (String pattern : antPatterns) {
matchers.add(new AntPathRequestMatcher(pattern));
}
return new OrRequestMatcher(matchers);
}
}
:
@Bean
public static BeanPostProcessor sessionBeanPostProcessor() {
return new ConcurrentSessionControlAuthenticationStrategyBeanPostProcessor();
}
, BeanPostProcessor, .
PS