Skip to content

Update dependancies + fix MFA required exception #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@
<maven.compiler.release>21</maven.compiler.release>
<logback.version>1.5.15</logback.version>

<spring-boot.version>3.4.1</spring-boot.version>
<spring-boot.version>3.4.5</spring-boot.version>
<totp-spring-boot-starter.version>1.7.1</totp-spring-boot-starter.version>
<commons-io.version>2.18.0</commons-io.version>
<commons-io.version>2.19.0</commons-io.version>

<dependency-check-maven-plugin.version>12.0.0</dependency-check-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
<maven-javadoc-plugin.version>3.4.1</maven-javadoc-plugin.version>
<dependency-check-maven-plugin.version>12.1.1</dependency-check-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.13</jacoco-maven-plugin.version>
<maven-compiler-plugin.version>3.14.0</maven-compiler-plugin.version>
<maven-gpg-plugin.version>3.2.7</maven-gpg-plugin.version>
<maven-javadoc-plugin.version>3.11.2</maven-javadoc-plugin.version>
<maven-release-plugin.version>3.1.1</maven-release-plugin.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-surefire-plugin.version>3.5.2</maven-surefire-plugin.version>
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
<maven-surefire-plugin.version>3.5.3</maven-surefire-plugin.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package nl._42.restsecure.autoconfigure.authentication.mfa;

public class MfaRequiredException extends RuntimeException {
import org.springframework.security.core.AuthenticationException;

public class MfaRequiredException extends AuthenticationException {

public MfaRequiredException(String msg) {
super(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import jakarta.servlet.http.HttpServletResponse;

import lombok.RequiredArgsConstructor;
import nl._42.restsecure.autoconfigure.authentication.mfa.MfaRequiredException;

import org.springframework.security.authentication.InsufficientAuthenticationException;
import org.springframework.security.core.AuthenticationException;

@RequiredArgsConstructor
Expand All @@ -22,7 +22,7 @@ public class DefaultLoginAuthenticationExceptionHandler implements LoginAuthenti
@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException {
// If the MFA code is needed but not provided, indicate this so the client can trigger the MFA login procedure.
if (exception instanceof InsufficientAuthenticationException
if (exception instanceof MfaRequiredException
&& exception.getMessage().equals(SERVER_MFA_CODE_REQUIRED_ERROR)) {
errorHandler.respond(response, UNAUTHORIZED, SERVER_MFA_CODE_REQUIRED_ERROR);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,18 @@ void shouldThrowIfCodeInvalid() {
}

@Test
@DisplayName("should throw InsufficientAuthenticationException if the code is missing")
@DisplayName("should throw MfaRequiredException if the code is missing")
void shouldThrowIfCodeMissing() {
User user = new UserWithMfa("username", "password", "secret-key", false, "Hoi");
inMemoryUserDetailService.register(user);
mockMfaValidationService.register("secret-key", "123456");

MfaAuthenticationToken nullToken = new MfaAuthenticationToken("username", "password", null);
InsufficientAuthenticationException e = assertThrows(InsufficientAuthenticationException.class, () -> provider.authenticate(nullToken));
MfaRequiredException e = assertThrows(MfaRequiredException.class, () -> provider.authenticate(nullToken));
assertEquals("SERVER.MFA_CODE_REQUIRED_ERROR", e.getMessage());

MfaAuthenticationToken emptyStringToken = new MfaAuthenticationToken("username", "password", "");
InsufficientAuthenticationException e2 = assertThrows(InsufficientAuthenticationException.class, () -> provider.authenticate(emptyStringToken));
MfaRequiredException e2 = assertThrows(MfaRequiredException.class, () -> provider.authenticate(emptyStringToken));
assertEquals("SERVER.MFA_CODE_REQUIRED_ERROR", e2.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import nl._42.restsecure.autoconfigure.authentication.mfa.MfaAuthenticationProvider;
import nl._42.restsecure.autoconfigure.authentication.mfa.MfaRequiredException;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand All @@ -28,7 +30,7 @@ void shouldReturnMfaCodeRequiredError() throws IOException {

MockHttpServletResponse response = new MockHttpServletResponse();
handler.handle(new MockHttpServletRequest(), response,
new InsufficientAuthenticationException(MfaAuthenticationProvider.SERVER_MFA_CODE_REQUIRED_ERROR));
new MfaRequiredException(MfaAuthenticationProvider.SERVER_MFA_CODE_REQUIRED_ERROR));

assertEquals(HttpStatus.UNAUTHORIZED.value(), response.getStatus());
assertThat(response.getContentAsString()).contains("\"errorCode\":\"SERVER.MFA_CODE_REQUIRED_ERROR\"");
Expand Down