Skip to content

Commit

Permalink
Just for review: Remove specialized wrapper exception class to reduce
Browse files Browse the repository at this point in the history
number of classes
  • Loading branch information
ynojima committed Oct 19, 2019
1 parent be92253 commit b430a71
Show file tree
Hide file tree
Showing 28 changed files with 6 additions and 855 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.webauthn4j.util.Base64UrlUtil;
import com.webauthn4j.util.UUIDUtil;
import com.webauthn4j.util.exception.WebAuthnException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -33,8 +34,7 @@
import org.springframework.security.webauthn.authenticator.WebAuthnAuthenticator;
import org.springframework.security.webauthn.authenticator.WebAuthnAuthenticatorImpl;
import org.springframework.security.webauthn.authenticator.WebAuthnAuthenticatorTransport;
import org.springframework.security.webauthn.exception.DataConversionException;
import org.springframework.security.webauthn.exception.ValidationException;
import org.springframework.security.webauthn.exception.WebAuthnAuthenticationException;
import org.springframework.security.webauthn.userdetails.InMemoryWebAuthnAndPasswordUserDetailsManager;
import org.springframework.security.webauthn.userdetails.WebAuthnAndPasswordUser;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -126,14 +126,10 @@ public String create(HttpServletRequest request, @Valid @ModelAttribute("userFor
try {
registrationRequestValidator.validate(webAuthnRegistrationRequest);
}
catch (ValidationException e){
catch (WebAuthnException | WebAuthnAuthenticationException e){
logger.debug("WebAuthn registration request validation failed.", e);
return VIEW_SIGNUP_SIGNUP;
}
catch (DataConversionException e){
logger.debug("WebAuthn registration request data conversion failed.", e);
return VIEW_SIGNUP_SIGNUP;
}

AuthenticatorCreateForm sourceAuthenticator = userCreateForm.getAuthenticator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,67 +77,6 @@ public WebAuthn4JWebAuthnManager() {
this(new WebAuthnDataConverter());
}

/**
* Wraps WebAuthnAuthentication to proper {@link RuntimeException} (mainly {@link AuthenticationException} subclass.
*
* @param e exception to be wrapped
* @return wrapping exception
*/
@SuppressWarnings("squid:S3776")
static RuntimeException wrapWithAuthenticationException(WebAuthnException e) {
// ValidationExceptions
if (e instanceof com.webauthn4j.validator.exception.BadAaguidException) {
return new BadAaguidException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.BadAlgorithmException) {
return new BadAlgorithmException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.BadAttestationStatementException) {
if (e instanceof com.webauthn4j.validator.exception.KeyDescriptionValidationException) {
return new KeyDescriptionValidationException(e.getMessage(), e);
} else {
return new BadAttestationStatementException(e.getMessage(), e);
}
} else if (e instanceof com.webauthn4j.validator.exception.BadChallengeException) {
return new BadChallengeException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.BadOriginException) {
return new BadOriginException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.BadRpIdException) {
return new BadRpIdException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.BadSignatureException) {
return new BadSignatureException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.CertificateException) {
return new CertificateException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.ConstraintViolationException) {
return new ConstraintViolationException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.MaliciousCounterValueException) {
return new MaliciousCounterValueException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.MaliciousDataException) {
return new MaliciousDataException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.MissingChallengeException) {
return new MissingChallengeException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.PublicKeyMismatchException) {
return new PublicKeyMismatchException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.SelfAttestationProhibitedException) {
return new SelfAttestationProhibitedException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.TokenBindingException) {
return new TokenBindingException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.TrustAnchorNotFoundException) {
return new TrustAnchorNotFoundException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.UnexpectedExtensionException) {
return new UnexpectedExtensionException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.UserNotPresentException) {
return new UserNotPresentException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.UserNotVerifiedException) {
return new UserNotVerifiedException(e.getMessage(), e);
} else if (e instanceof com.webauthn4j.validator.exception.ValidationException) {
return new ValidationException("WebAuthn validation error", e);
}
// DataConversionException
else if (e instanceof com.webauthn4j.converter.exception.DataConversionException) {
return new DataConversionException("WebAuthn data conversion error", e);
} else {
return new AuthenticationServiceException(null, e);
}
}

public void verifyRegistrationData(
WebAuthnRegistrationData registrationData
Expand All @@ -152,11 +91,7 @@ public void verifyRegistrationData(

WebAuthnRegistrationContext registrationContext = createRegistrationContext(registrationData);

try {
registrationContextValidator.validate(registrationContext);
} catch (WebAuthnException e) {
throw wrapWithAuthenticationException(e);
}
registrationContextValidator.validate(registrationContext);
}

@Override
Expand Down Expand Up @@ -184,11 +119,7 @@ public void verifyAuthenticationData(WebAuthnAuthenticationData authenticationDa
transports
);

try {
authenticationContextValidator.validate(authenticationContext, authenticator);
} catch (WebAuthnException e) {
throw wrapWithAuthenticationException(e);
}
authenticationContextValidator.validate(authenticationContext, authenticator);

}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b430a71

Please sign in to comment.