Skip to content

Commit ca07572

Browse files
committed
Just for review: Remove WebAuthn4J wrapper classes to reduce number of classes
1 parent b430a71 commit ca07572

17 files changed

+73
-507
lines changed

samples/javaconfig/webauthn/src/main/java/org/springframework/security/webauthn/sample/app/web/WebAuthnSampleController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.security.webauthn.sample.app.web;
1818

19+
import com.webauthn4j.data.AuthenticatorTransport;
1920
import com.webauthn4j.util.Base64UrlUtil;
2021
import com.webauthn4j.util.UUIDUtil;
2122
import com.webauthn4j.util.exception.WebAuthnException;
@@ -33,7 +34,6 @@
3334
import org.springframework.security.webauthn.WebAuthnRegistrationRequestValidator;
3435
import org.springframework.security.webauthn.authenticator.WebAuthnAuthenticator;
3536
import org.springframework.security.webauthn.authenticator.WebAuthnAuthenticatorImpl;
36-
import org.springframework.security.webauthn.authenticator.WebAuthnAuthenticatorTransport;
3737
import org.springframework.security.webauthn.exception.WebAuthnAuthenticationException;
3838
import org.springframework.security.webauthn.userdetails.InMemoryWebAuthnAndPasswordUserDetailsManager;
3939
import org.springframework.security.webauthn.userdetails.WebAuthnAndPasswordUser;
@@ -138,13 +138,13 @@ public String create(HttpServletRequest request, @Valid @ModelAttribute("userFor
138138
byte[] attestedCredentialData = webAuthnDataConverter.extractAttestedCredentialData(authenticatorData);
139139
byte[] credentialId = webAuthnDataConverter.extractCredentialId(attestedCredentialData);
140140
long signCount = webAuthnDataConverter.extractSignCount(authenticatorData);
141-
Set<WebAuthnAuthenticatorTransport> transports;
141+
Set<AuthenticatorTransport> transports;
142142
if (sourceAuthenticator.getTransports() == null) {
143143
transports = null;
144144
}
145145
else {
146146
transports = sourceAuthenticator.getTransports().stream()
147-
.map(WebAuthnAuthenticatorTransport::create)
147+
.map(AuthenticatorTransport::create)
148148
.collect(Collectors.toSet());
149149
}
150150

webauthn/src/main/java/org/springframework/security/webauthn/WebAuthn4JWebAuthnManager.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,12 @@
2626
import com.webauthn4j.data.client.Origin;
2727
import com.webauthn4j.data.client.challenge.DefaultChallenge;
2828
import com.webauthn4j.server.ServerProperty;
29-
import com.webauthn4j.util.exception.WebAuthnException;
3029
import com.webauthn4j.validator.WebAuthnAuthenticationContextValidator;
3130
import com.webauthn4j.validator.WebAuthnRegistrationContextValidator;
32-
import org.springframework.security.authentication.AuthenticationServiceException;
33-
import org.springframework.security.core.AuthenticationException;
3431
import org.springframework.security.webauthn.authenticator.WebAuthnAuthenticator;
35-
import org.springframework.security.webauthn.exception.*;
36-
import org.springframework.security.webauthn.server.WebAuthnOrigin;
37-
import org.springframework.security.webauthn.server.WebAuthnServerProperty;
3832
import org.springframework.util.Assert;
3933

34+
import javax.servlet.ServletRequest;
4035
import javax.servlet.http.HttpServletRequest;
4136
import java.util.Collections;
4237
import java.util.Set;
@@ -129,7 +124,7 @@ public String getEffectiveRpId(HttpServletRequest request) {
129124
if (this.rpId != null) {
130125
effectiveRpId = this.rpId;
131126
} else {
132-
WebAuthnOrigin origin = WebAuthnOrigin.create(request);
127+
Origin origin = createOrigin(request);
133128
effectiveRpId = origin.getHost();
134129
}
135130
return effectiveRpId;
@@ -179,16 +174,20 @@ private WebAuthnAuthenticationContext createWebAuthnAuthenticationContext(WebAut
179174
);
180175
}
181176

182-
private Origin convertToOrigin(WebAuthnOrigin webAuthnOrigin) {
177+
private Origin convertToOrigin(Origin webAuthnOrigin) {
183178
return new Origin(webAuthnOrigin.getScheme(), webAuthnOrigin.getHost(), webAuthnOrigin.getPort());
184179
}
185180

186-
private ServerProperty convertToServerProperty(WebAuthnServerProperty webAuthnServerProperty) {
181+
private ServerProperty convertToServerProperty(ServerProperty webAuthnServerProperty) {
187182
return new ServerProperty(
188183
convertToOrigin(webAuthnServerProperty.getOrigin()),
189184
webAuthnServerProperty.getRpId(),
190185
new DefaultChallenge(webAuthnServerProperty.getChallenge().getValue()),
191186
webAuthnServerProperty.getTokenBindingId());
192187
}
193188

189+
private static Origin createOrigin(ServletRequest request) {
190+
return new Origin(request.getScheme(), request.getServerName(), request.getServerPort());
191+
}
192+
194193
}

webauthn/src/main/java/org/springframework/security/webauthn/WebAuthnAuthenticationData.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.security.webauthn;
1818

19+
import com.webauthn4j.server.ServerProperty;
1920
import com.webauthn4j.util.ArrayUtil;
20-
import org.springframework.security.webauthn.server.WebAuthnServerProperty;
2121

2222
import java.io.Serializable;
2323
import java.util.Arrays;
@@ -42,7 +42,7 @@ public class WebAuthnAuthenticationData implements Serializable {
4242
private final byte[] signature;
4343
private final String clientExtensionsJSON;
4444

45-
private final WebAuthnServerProperty serverProperty;
45+
private final ServerProperty serverProperty;
4646
private final boolean userVerificationRequired;
4747
private final boolean userPresenceRequired;
4848
private final List<String> expectedAuthenticationExtensionIds;
@@ -54,7 +54,7 @@ public WebAuthnAuthenticationData(
5454
byte[] authenticatorData,
5555
byte[] signature,
5656
String clientExtensionsJSON,
57-
WebAuthnServerProperty serverProperty,
57+
ServerProperty serverProperty,
5858
boolean userVerificationRequired,
5959
boolean userPresenceRequired,
6060
List<String> expectedAuthenticationExtensionIds) {
@@ -77,7 +77,7 @@ public WebAuthnAuthenticationData(
7777
byte[] authenticatorData,
7878
byte[] signature,
7979
String clientExtensionsJSON,
80-
WebAuthnServerProperty serverProperty,
80+
ServerProperty serverProperty,
8181
boolean userVerificationRequired,
8282
List<String> expectedAuthenticationExtensionIds) {
8383

@@ -114,7 +114,7 @@ public String getClientExtensionsJSON() {
114114
return clientExtensionsJSON;
115115
}
116116

117-
public WebAuthnServerProperty getServerProperty() {
117+
public ServerProperty getServerProperty() {
118118
return serverProperty;
119119
}
120120

webauthn/src/main/java/org/springframework/security/webauthn/WebAuthnProcessingFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.security.webauthn;
1818

19+
import com.webauthn4j.server.ServerProperty;
1920
import org.springframework.http.HttpMethod;
2021
import org.springframework.security.authentication.AbstractAuthenticationToken;
2122
import org.springframework.security.authentication.AuthenticationServiceException;
@@ -24,7 +25,6 @@
2425
import org.springframework.security.core.GrantedAuthority;
2526
import org.springframework.security.core.authority.AuthorityUtils;
2627
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
27-
import org.springframework.security.webauthn.server.WebAuthnServerProperty;
2828
import org.springframework.security.webauthn.server.WebAuthnServerPropertyProvider;
2929
import org.springframework.util.Assert;
3030
import org.springframework.util.Base64Utils;
@@ -135,7 +135,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
135135
byte[] rawAuthenticatorData = authenticatorData == null ? null : Base64Utils.decodeFromUrlSafeString(authenticatorData);
136136
byte[] signatureBytes = signature == null ? null : Base64Utils.decodeFromUrlSafeString(signature);
137137

138-
WebAuthnServerProperty webAuthnServerProperty = serverPropertyProvider.provide(request);
138+
ServerProperty webAuthnServerProperty = serverPropertyProvider.provide(request);
139139

140140
WebAuthnAuthenticationData webAuthnAuthenticationData = new WebAuthnAuthenticationData(
141141
rawId,

webauthn/src/main/java/org/springframework/security/webauthn/WebAuthnRegistrationData.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.security.webauthn;
1818

19+
import com.webauthn4j.server.ServerProperty;
1920
import com.webauthn4j.util.ArrayUtil;
20-
import org.springframework.security.webauthn.server.WebAuthnServerProperty;
2121

2222
import java.util.Collections;
2323
import java.util.List;
@@ -30,11 +30,11 @@ public class WebAuthnRegistrationData {
3030
private final Set<String> transports;
3131
private final String clientExtensionsJSON;
3232

33-
private final WebAuthnServerProperty serverProperty;
33+
private final ServerProperty serverProperty;
3434
private final List<String> expectedRegistrationExtensionIds;
3535

3636
public WebAuthnRegistrationData(byte[] clientDataJSON, byte[] attestationObject, Set<String> transports, String clientExtensionsJSON,
37-
WebAuthnServerProperty serverProperty,
37+
ServerProperty serverProperty,
3838
List<String> expectedRegistrationExtensionIds) {
3939
this.clientDataJSON = ArrayUtil.clone(clientDataJSON);
4040
this.attestationObject = ArrayUtil.clone(attestationObject);
@@ -60,7 +60,7 @@ public String getClientExtensionsJSON() {
6060
return clientExtensionsJSON;
6161
}
6262

63-
public WebAuthnServerProperty getServerProperty() {
63+
public ServerProperty getServerProperty() {
6464
return serverProperty;
6565
}
6666

webauthn/src/main/java/org/springframework/security/webauthn/WebAuthnRegistrationRequestValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.security.webauthn;
1818

19+
import com.webauthn4j.server.ServerProperty;
1920
import com.webauthn4j.util.Base64UrlUtil;
20-
import org.springframework.security.webauthn.server.WebAuthnServerProperty;
2121
import org.springframework.security.webauthn.server.WebAuthnServerPropertyProvider;
2222
import org.springframework.util.Assert;
2323

@@ -43,7 +43,7 @@ public void validate(WebAuthnRegistrationRequest registrationRequest) {
4343
Assert.notNull(registrationRequest, "target must not be null");
4444
Assert.notNull(registrationRequest.getHttpServletRequest(), "httpServletRequest must not be null");
4545

46-
WebAuthnServerProperty webAuthnServerProperty = webAuthnServerPropertyProvider.provide(registrationRequest.getHttpServletRequest());
46+
ServerProperty webAuthnServerProperty = webAuthnServerPropertyProvider.provide(registrationRequest.getHttpServletRequest());
4747

4848
WebAuthnRegistrationData webAuthnRegistrationData = new WebAuthnRegistrationData(
4949
Base64UrlUtil.decode(registrationRequest.getClientDataBase64Url()),

webauthn/src/main/java/org/springframework/security/webauthn/authenticator/WebAuthnAuthenticator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.security.webauthn.authenticator;
1818

19+
import com.webauthn4j.data.AuthenticatorTransport;
1920
import org.springframework.security.webauthn.userdetails.WebAuthnUserDetailsService;
2021

2122
import java.util.Set;
@@ -36,7 +37,7 @@ public interface WebAuthnAuthenticator {
3637

3738
void setCounter(long counter);
3839

39-
Set<WebAuthnAuthenticatorTransport> getTransports();
40+
Set<AuthenticatorTransport> getTransports();
4041

4142
String getClientExtensions();
4243

webauthn/src/main/java/org/springframework/security/webauthn/authenticator/WebAuthnAuthenticatorImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.security.webauthn.authenticator;
1818

1919

20+
import com.webauthn4j.data.AuthenticatorTransport;
2021
import com.webauthn4j.util.ArrayUtil;
2122

2223
import java.util.Arrays;
@@ -31,7 +32,7 @@ public class WebAuthnAuthenticatorImpl implements WebAuthnAuthenticator {
3132
private String name;
3233
private byte[] attestationObject;
3334
private long counter;
34-
private Set<WebAuthnAuthenticatorTransport> transports;
35+
private Set<AuthenticatorTransport> transports;
3536
private String clientExtensions;
3637

3738
// ~ Constructor
@@ -51,7 +52,7 @@ public WebAuthnAuthenticatorImpl(
5152
String name,
5253
byte[] attestationObject,
5354
long counter,
54-
Set<WebAuthnAuthenticatorTransport> transports,
55+
Set<AuthenticatorTransport> transports,
5556
String clientExtensions) {
5657
this.credentialId = credentialId;
5758
this.name = name;
@@ -88,7 +89,7 @@ public void setCounter(long counter) {
8889
}
8990

9091
@Override
91-
public Set<WebAuthnAuthenticatorTransport> getTransports() {
92+
public Set<AuthenticatorTransport> getTransports() {
9293
return transports;
9394
}
9495

webauthn/src/main/java/org/springframework/security/webauthn/authenticator/WebAuthnAuthenticatorTransport.java

Lines changed: 0 additions & 86 deletions
This file was deleted.

webauthn/src/main/java/org/springframework/security/webauthn/challenge/HttpSessionWebAuthnChallengeRepository.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.security.webauthn.challenge;
1818

19+
import com.webauthn4j.data.client.challenge.Challenge;
20+
import com.webauthn4j.data.client.challenge.DefaultChallenge;
1921
import org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository;
2022
import org.springframework.util.Assert;
2123

@@ -45,12 +47,12 @@ public class HttpSessionWebAuthnChallengeRepository implements WebAuthnChallenge
4547
// ========================================================================================================
4648

4749
@Override
48-
public WebAuthnChallenge generateChallenge() {
49-
return new WebAuthnChallengeImpl();
50+
public Challenge generateChallenge() {
51+
return new DefaultChallenge();
5052
}
5153

5254
@Override
53-
public void saveChallenge(WebAuthnChallenge challenge, HttpServletRequest request) {
55+
public void saveChallenge(Challenge challenge, HttpServletRequest request) {
5456
if (challenge == null) {
5557
HttpSession session = request.getSession(false);
5658
if (session != null) {
@@ -63,16 +65,16 @@ public void saveChallenge(WebAuthnChallenge challenge, HttpServletRequest reques
6365
}
6466

6567
@Override
66-
public WebAuthnChallenge loadChallenge(HttpServletRequest request) {
68+
public Challenge loadChallenge(HttpServletRequest request) {
6769
HttpSession session = request.getSession(false);
6870
if (session == null) {
6971
return null;
7072
}
71-
return (WebAuthnChallenge) session.getAttribute(this.sessionAttributeName);
73+
return (Challenge) session.getAttribute(this.sessionAttributeName);
7274
}
7375

7476
/**
75-
* Sets the {@link HttpSession} attribute name that the {@link WebAuthnChallenge} is stored in
77+
* Sets the {@link HttpSession} attribute name that the {@link Challenge} is stored in
7678
*
7779
* @param sessionAttributeName the new attribute name to use
7880
*/

0 commit comments

Comments
 (0)