Skip to content

Commit b430a71

Browse files
committed
Just for review: Remove specialized wrapper exception class to reduce
number of classes
1 parent be92253 commit b430a71

28 files changed

+6
-855
lines changed

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

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

1919
import com.webauthn4j.util.Base64UrlUtil;
2020
import com.webauthn4j.util.UUIDUtil;
21+
import com.webauthn4j.util.exception.WebAuthnException;
2122
import org.apache.commons.logging.Log;
2223
import org.apache.commons.logging.LogFactory;
2324
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,8 +34,7 @@
3334
import org.springframework.security.webauthn.authenticator.WebAuthnAuthenticator;
3435
import org.springframework.security.webauthn.authenticator.WebAuthnAuthenticatorImpl;
3536
import org.springframework.security.webauthn.authenticator.WebAuthnAuthenticatorTransport;
36-
import org.springframework.security.webauthn.exception.DataConversionException;
37-
import org.springframework.security.webauthn.exception.ValidationException;
37+
import org.springframework.security.webauthn.exception.WebAuthnAuthenticationException;
3838
import org.springframework.security.webauthn.userdetails.InMemoryWebAuthnAndPasswordUserDetailsManager;
3939
import org.springframework.security.webauthn.userdetails.WebAuthnAndPasswordUser;
4040
import org.springframework.stereotype.Controller;
@@ -126,14 +126,10 @@ public String create(HttpServletRequest request, @Valid @ModelAttribute("userFor
126126
try {
127127
registrationRequestValidator.validate(webAuthnRegistrationRequest);
128128
}
129-
catch (ValidationException e){
129+
catch (WebAuthnException | WebAuthnAuthenticationException e){
130130
logger.debug("WebAuthn registration request validation failed.", e);
131131
return VIEW_SIGNUP_SIGNUP;
132132
}
133-
catch (DataConversionException e){
134-
logger.debug("WebAuthn registration request data conversion failed.", e);
135-
return VIEW_SIGNUP_SIGNUP;
136-
}
137133

138134
AuthenticatorCreateForm sourceAuthenticator = userCreateForm.getAuthenticator();
139135

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

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -77,67 +77,6 @@ public WebAuthn4JWebAuthnManager() {
7777
this(new WebAuthnDataConverter());
7878
}
7979

80-
/**
81-
* Wraps WebAuthnAuthentication to proper {@link RuntimeException} (mainly {@link AuthenticationException} subclass.
82-
*
83-
* @param e exception to be wrapped
84-
* @return wrapping exception
85-
*/
86-
@SuppressWarnings("squid:S3776")
87-
static RuntimeException wrapWithAuthenticationException(WebAuthnException e) {
88-
// ValidationExceptions
89-
if (e instanceof com.webauthn4j.validator.exception.BadAaguidException) {
90-
return new BadAaguidException(e.getMessage(), e);
91-
} else if (e instanceof com.webauthn4j.validator.exception.BadAlgorithmException) {
92-
return new BadAlgorithmException(e.getMessage(), e);
93-
} else if (e instanceof com.webauthn4j.validator.exception.BadAttestationStatementException) {
94-
if (e instanceof com.webauthn4j.validator.exception.KeyDescriptionValidationException) {
95-
return new KeyDescriptionValidationException(e.getMessage(), e);
96-
} else {
97-
return new BadAttestationStatementException(e.getMessage(), e);
98-
}
99-
} else if (e instanceof com.webauthn4j.validator.exception.BadChallengeException) {
100-
return new BadChallengeException(e.getMessage(), e);
101-
} else if (e instanceof com.webauthn4j.validator.exception.BadOriginException) {
102-
return new BadOriginException(e.getMessage(), e);
103-
} else if (e instanceof com.webauthn4j.validator.exception.BadRpIdException) {
104-
return new BadRpIdException(e.getMessage(), e);
105-
} else if (e instanceof com.webauthn4j.validator.exception.BadSignatureException) {
106-
return new BadSignatureException(e.getMessage(), e);
107-
} else if (e instanceof com.webauthn4j.validator.exception.CertificateException) {
108-
return new CertificateException(e.getMessage(), e);
109-
} else if (e instanceof com.webauthn4j.validator.exception.ConstraintViolationException) {
110-
return new ConstraintViolationException(e.getMessage(), e);
111-
} else if (e instanceof com.webauthn4j.validator.exception.MaliciousCounterValueException) {
112-
return new MaliciousCounterValueException(e.getMessage(), e);
113-
} else if (e instanceof com.webauthn4j.validator.exception.MaliciousDataException) {
114-
return new MaliciousDataException(e.getMessage(), e);
115-
} else if (e instanceof com.webauthn4j.validator.exception.MissingChallengeException) {
116-
return new MissingChallengeException(e.getMessage(), e);
117-
} else if (e instanceof com.webauthn4j.validator.exception.PublicKeyMismatchException) {
118-
return new PublicKeyMismatchException(e.getMessage(), e);
119-
} else if (e instanceof com.webauthn4j.validator.exception.SelfAttestationProhibitedException) {
120-
return new SelfAttestationProhibitedException(e.getMessage(), e);
121-
} else if (e instanceof com.webauthn4j.validator.exception.TokenBindingException) {
122-
return new TokenBindingException(e.getMessage(), e);
123-
} else if (e instanceof com.webauthn4j.validator.exception.TrustAnchorNotFoundException) {
124-
return new TrustAnchorNotFoundException(e.getMessage(), e);
125-
} else if (e instanceof com.webauthn4j.validator.exception.UnexpectedExtensionException) {
126-
return new UnexpectedExtensionException(e.getMessage(), e);
127-
} else if (e instanceof com.webauthn4j.validator.exception.UserNotPresentException) {
128-
return new UserNotPresentException(e.getMessage(), e);
129-
} else if (e instanceof com.webauthn4j.validator.exception.UserNotVerifiedException) {
130-
return new UserNotVerifiedException(e.getMessage(), e);
131-
} else if (e instanceof com.webauthn4j.validator.exception.ValidationException) {
132-
return new ValidationException("WebAuthn validation error", e);
133-
}
134-
// DataConversionException
135-
else if (e instanceof com.webauthn4j.converter.exception.DataConversionException) {
136-
return new DataConversionException("WebAuthn data conversion error", e);
137-
} else {
138-
return new AuthenticationServiceException(null, e);
139-
}
140-
}
14180

14281
public void verifyRegistrationData(
14382
WebAuthnRegistrationData registrationData
@@ -152,11 +91,7 @@ public void verifyRegistrationData(
15291

15392
WebAuthnRegistrationContext registrationContext = createRegistrationContext(registrationData);
15493

155-
try {
156-
registrationContextValidator.validate(registrationContext);
157-
} catch (WebAuthnException e) {
158-
throw wrapWithAuthenticationException(e);
159-
}
94+
registrationContextValidator.validate(registrationContext);
16095
}
16196

16297
@Override
@@ -184,11 +119,7 @@ public void verifyAuthenticationData(WebAuthnAuthenticationData authenticationDa
184119
transports
185120
);
186121

187-
try {
188-
authenticationContextValidator.validate(authenticationContext, authenticator);
189-
} catch (WebAuthnException e) {
190-
throw wrapWithAuthenticationException(e);
191-
}
122+
authenticationContextValidator.validate(authenticationContext, authenticator);
192123

193124
}
194125

webauthn/src/main/java/org/springframework/security/webauthn/exception/BadAaguidException.java

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

webauthn/src/main/java/org/springframework/security/webauthn/exception/BadAlgorithmException.java

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

webauthn/src/main/java/org/springframework/security/webauthn/exception/BadAttestationStatementException.java

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

webauthn/src/main/java/org/springframework/security/webauthn/exception/BadChallengeException.java

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

webauthn/src/main/java/org/springframework/security/webauthn/exception/BadCredentialIdException.java

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

webauthn/src/main/java/org/springframework/security/webauthn/exception/BadOriginException.java

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

webauthn/src/main/java/org/springframework/security/webauthn/exception/BadRpIdException.java

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

webauthn/src/main/java/org/springframework/security/webauthn/exception/BadSignatureException.java

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

0 commit comments

Comments
 (0)