View Javadoc
1   package org.oxerr.spring.security.guest.config.annotation.web.configurers;
2   
3   import org.oxerr.spring.security.guest.authentication.GuestAuthenticationProvider;
4   import org.oxerr.spring.security.guest.core.userdetails.GuestUserDetailsService;
5   import org.oxerr.spring.security.guest.web.authentication.GuestAuthenticationFilter;
6   import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
7   import org.springframework.security.config.annotation.web.configurers.AbstractAuthenticationFilterConfigurer;
8   import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
9   import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
10  import org.springframework.security.web.util.matcher.RequestMatcher;
11  
12  public final class GuestConfigurer<H extends HttpSecurityBuilder<H>>
13  		extends AbstractAuthenticationFilterConfigurer<H, GuestConfigurer<H>, GuestAuthenticationFilter> {
14  
15  	private final GuestUserDetailsService guestUserDetailsService;
16  
17  	public GuestConfigurer(GuestUserDetailsService guestUserDetailsService) {
18  		super(new GuestAuthenticationFilter(), "/");
19  		this.guestUserDetailsService = guestUserDetailsService;
20  	}
21  
22  	@Override
23  	protected RequestMatcher createLoginProcessingUrlMatcher(String loginProcessingUrl) {
24  		return new AntPathRequestMatcher("/");
25  	}
26  
27  	@Override
28  	public void init(H http) throws Exception {
29  		super.init(http);
30  
31  		GuestAuthenticationProvider guestAuthenticationProvider = new GuestAuthenticationProvider(
32  				guestUserDetailsService);
33  		postProcess(guestAuthenticationProvider);
34  		http.authenticationProvider(guestAuthenticationProvider);
35  	}
36  
37  	@Override
38  	public void configure(H http) throws Exception {
39  
40  		// Make sure the filter be registered in
41  		// org.springframework.security.config.annotation.web.builders.FilterComparator
42  		http.addFilterBefore(getAuthenticationFilter(), AnonymousAuthenticationFilter.class);
43  
44  		super.configure(http);
45  	}
46  
47  }