1 package org.oxerr.spring.security.otp.config.annotation.web.configurers;
2
3 import org.oxerr.spring.security.otp.authentication.OTPAuthenticationProvider;
4 import org.oxerr.spring.security.otp.core.OTPAuthenticationService;
5 import org.oxerr.spring.security.otp.web.authentication.OTPAuthenticationFilter;
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 OTPLoginConfigurer<H extends HttpSecurityBuilder<H>>
13 extends
14 AbstractAuthenticationFilterConfigurer<H, OTPLoginConfigurer<H>,
15 OTPAuthenticationFilter> {
16
17 private final OTPAuthenticationService otpAuthenticationService;
18
19 public OTPLoginConfigurer(OTPAuthenticationService otpAuthenticationService) {
20 super(new OTPAuthenticationFilter(), "/**");
21 this.otpAuthenticationService = otpAuthenticationService;
22 }
23
24 @Override
25 protected RequestMatcher createLoginProcessingUrlMatcher(
26 String loginProcessingUrl) {
27 return new AntPathRequestMatcher(loginProcessingUrl);
28 }
29
30 @Override
31 public void init(H http) throws Exception {
32 super.init(http);
33
34 OTPAuthenticationProvider authenticationProvider = new OTPAuthenticationProvider(
35 otpAuthenticationService);
36 postProcess(authenticationProvider);
37 http.authenticationProvider(authenticationProvider);
38 }
39
40 @Override
41 public void configure(H http) throws Exception {
42
43
44
45 http.addFilterBefore(getAuthenticationFilter(), AnonymousAuthenticationFilter.class);
46
47 super.configure(http);
48 }
49
50 public OTPLoginConfigurer<H> oneTimePasswordParameter(String oneTimePasswordParameter) {
51 getAuthenticationFilter().setOneTimePasswordParameter(oneTimePasswordParameter);
52 return this;
53 }
54
55 }