View Javadoc
1   package org.oxerr.spring.security.wechat.config.annotation.web.configurers;
2   
3   import org.oxerr.spring.security.wechat.authentication.WeChatAuthenticationProvider;
4   import org.oxerr.spring.security.wechat.core.userdetails.WeChatUserDetailsService;
5   import org.oxerr.spring.security.wechat.web.authentication.WeChatAuthenticationFilter;
6   import org.oxerr.spring.security.wechat.web.authentication.WeChatService;
7   import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
8   import org.springframework.security.config.annotation.web.configurers.AbstractAuthenticationFilterConfigurer;
9   import org.springframework.security.web.authentication.logout.LogoutFilter;
10  import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
11  import org.springframework.security.web.util.matcher.RequestMatcher;
12  
13  public final class WeChatLoginConfigurer<H extends HttpSecurityBuilder<H>>
14  		extends
15  		AbstractAuthenticationFilterConfigurer<H, WeChatLoginConfigurer<H>,
16  		WeChatAuthenticationFilter> {
17  
18  	private final WeChatUserDetailsService weChatUserDetailsService;
19  
20  	public WeChatLoginConfigurer(
21  		WeChatService weChatService,
22  		WeChatUserDetailsService weChatUserDetailsService
23  	) {
24  		super(new WeChatAuthenticationFilter(weChatService), "/login/wechat");
25  		this.weChatUserDetailsService = weChatUserDetailsService;
26  	}
27  
28  	/**
29  	 * {@inheritDoc}
30  	 */
31  	@Override
32  	public void configure(H http) throws Exception {
33  
34  		// Make sure the filter be registered in
35  		// org.springframework.security.config.annotation.web.builders.FilterComparator
36  		http.addFilterAfter(getAuthenticationFilter(), LogoutFilter.class);
37  
38  		super.configure(http);
39  	}
40  
41  	@Override
42  	public WeChatLoginConfigurer<H> loginPage(String loginPage) {
43  		return super.loginPage(loginPage);
44  	}
45  
46  	/**
47  	 * {@inheritDoc}
48  	 */
49  	@Override
50  	public void init(H http) throws Exception {
51  		super.init(http);
52  
53  		WeChatAuthenticationProvider authenticationProvider = new WeChatAuthenticationProvider(weChatUserDetailsService);
54  		postProcess(authenticationProvider);
55  		http.authenticationProvider(authenticationProvider);
56  	}
57  
58  	/**
59  	 * {@inheritDoc}
60  	 */
61  	@Override
62  	protected RequestMatcher createLoginProcessingUrlMatcher(
63  			String loginProcessingUrl) {
64  		return new AntPathRequestMatcher(loginProcessingUrl, "GET");
65  	}
66  
67  }