Skip to content

Commit 514f34e

Browse files
authored
Merge pull request #1158 from TGITS/feat/new_constructor_for_WebAuthnProcessingFilter
Proposition to introduce a new constructor for WebAuthnProcessingFilter
2 parents 6a7aecb + 73d1a3f commit 514f34e

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

webauthn4j-spring-security-core/src/main/java/com/webauthn4j/springframework/security/WebAuthnProcessingFilter.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@
3636

3737

3838
/**
39-
* Processes a WebAuthn authentication form submission. For supporting username/password authentication for first step of
40-
* two step authentication, if credentialId is not found in the HTTP request, this filter try to find username/password
41-
* parameters.
39+
* Processes a WebAuthn authentication form submission.
40+
* <p>
41+
* For supporting the username/password authentication in the first step of a two factors authentication,
42+
* if credentialId is not found in the HTTP request, this filter try to find username/password parameters.
4243
* <p>
4344
* Login forms must present WebAuthn parameters (credentialId, clientDataJSON, authenticatorData,signature and
4445
* clientExtensionJSON) or Password authentication parameters (username and password).
@@ -75,7 +76,7 @@ public class WebAuthnProcessingFilter extends UsernamePasswordAuthenticationFilt
7576
private String clientExtensionsJSONParameter = SPRING_SECURITY_FORM_CLIENT_EXTENSIONS_JSON_KEY;
7677

7778
private ServerPropertyProvider serverPropertyProvider;
78-
private UserVerificationStrategy userVerificationStrategy = new DefaultUserVerificationStrategy();
79+
private UserVerificationStrategy userVerificationStrategy;
7980

8081
private boolean postOnly = true;
8182

@@ -91,7 +92,7 @@ public WebAuthnProcessingFilter() {
9192
}
9293

9394
/**
94-
* Constructor
95+
* Constructor which initializes the filter with a default user verification strategy
9596
*
9697
* @param authorities authorities for FirstOfMultiFactorAuthenticationToken
9798
* @param serverPropertyProvider provider for ServerProperty
@@ -101,6 +102,23 @@ public WebAuthnProcessingFilter(List<GrantedAuthority> authorities, ServerProper
101102
Assert.notNull(serverPropertyProvider, "serverPropertyProvider must not be null");
102103
this.authorities = authorities;
103104
this.serverPropertyProvider = serverPropertyProvider;
105+
this.userVerificationStrategy = new DefaultUserVerificationStrategy();
106+
}
107+
108+
/**
109+
* Overloading constructor in which the user verification strategy with which initializing the filter can be specified
110+
*
111+
* @param authorities authorities for FirstOfMultiFactorAuthenticationToken
112+
* @param serverPropertyProvider provider for ServerProperty
113+
* @param userVerificationStrategy the user verification strategy to be used by the filter
114+
*/
115+
public WebAuthnProcessingFilter(List<GrantedAuthority> authorities, ServerPropertyProvider serverPropertyProvider, UserVerificationStrategy userVerificationStrategy) {
116+
Assert.notNull(authorities, "authorities must not be null");
117+
Assert.notNull(serverPropertyProvider, "serverPropertyProvider must not be null");
118+
Assert.notNull(userVerificationStrategy, "userVerificationStrategy must not be null");
119+
this.authorities = authorities;
120+
this.serverPropertyProvider = serverPropertyProvider;
121+
this.userVerificationStrategy = userVerificationStrategy;
104122
}
105123

106124
// ~ Methods

webauthn4j-spring-security-core/src/test/java/com/webauthn4j/springframework/security/WebAuthnProcessingFilterTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,21 @@ public void attemptAuthentication_test_with_wrong_port() {
247247
}
248248

249249
@Test
250-
public void constructor_test() {
250+
public void first_constructor_test() {
251251
ServerPropertyProvider serverPropertyProvider = mock(ServerPropertyProvider.class);
252252
WebAuthnProcessingFilter webAuthnProcessingFilter = new WebAuthnProcessingFilter(AuthorityUtils.NO_AUTHORITIES, serverPropertyProvider);
253253
assertThat(webAuthnProcessingFilter.getServerPropertyProvider()).isEqualTo(serverPropertyProvider);
254254
assertThat(webAuthnProcessingFilter.getUserVerificationStrategy()).isNotNull();
255255
}
256256

257+
@Test
258+
public void second_constructor_test() {
259+
ServerPropertyProvider serverPropertyProvider = mock(ServerPropertyProvider.class);
260+
UserVerificationStrategy userVerificationStrategy = mock(UserVerificationStrategy.class);
261+
WebAuthnProcessingFilter webAuthnProcessingFilter = new WebAuthnProcessingFilter(AuthorityUtils.NO_AUTHORITIES, serverPropertyProvider, userVerificationStrategy);
262+
assertThat(webAuthnProcessingFilter.getServerPropertyProvider()).isEqualTo(serverPropertyProvider);
263+
assertThat(webAuthnProcessingFilter.getUserVerificationStrategy()).isNotNull();
264+
}
265+
257266

258267
}

0 commit comments

Comments
 (0)