Skip to content

Commit 64aae42

Browse files
committed
ATO-2559: Use feature flag in BaseAuthorizeValidator
1 parent 47c4562 commit 64aae42

3 files changed

Lines changed: 85 additions & 2 deletions

File tree

oidc-api/src/main/java/uk/gov/di/authentication/oidc/validators/BaseAuthorizeValidator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.Objects;
2727
import java.util.Optional;
2828

29+
import static uk.gov.di.orchestration.shared.utils.ClientUtils.getTokenAuthMethodOrDefault;
30+
2931
public abstract class BaseAuthorizeValidator {
3032

3133
protected static final String VTR_PARAM = "vtr";
@@ -205,8 +207,9 @@ protected Optional<ErrorObject> errorIfIdentityLoCAndIdentityUnsupported(
205207

206208
protected void logIdentityJourneyRequestWithInsufficientlySecureTokenAuthMethod(
207209
List<VectorOfTrust> vtrList, ClientRegistry client) {
208-
if (requestContainsIdentityLoC(vtrList)
209-
&& ("client_secret_post".equals(client.getTokenAuthMethod()))) {
210+
String tokenAuthMethod = getTokenAuthMethodOrDefault(client, configurationService);
211+
212+
if (requestContainsIdentityLoC(vtrList) && ("client_secret_post".equals(tokenAuthMethod))) {
210213
LOG.info(
211214
"Request contains level of confidence values for an identity journey but the tokenAuthMethod is incompatible.");
212215
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package uk.gov.di.orchestration.shared.utils;
2+
3+
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod;
4+
import uk.gov.di.orchestration.shared.entity.ClientRegistry;
5+
import uk.gov.di.orchestration.shared.services.ConfigurationService;
6+
7+
import java.util.Objects;
8+
9+
public class ClientUtils {
10+
private ClientUtils() {}
11+
12+
public static String getTokenAuthMethodOrDefault(
13+
ClientRegistry clientRegistry, ConfigurationService configurationService) {
14+
var tokenAuthMethod = clientRegistry.getTokenAuthMethod();
15+
if (Objects.isNull(tokenAuthMethod) && configurationService.isUseDefaultTokenAuthMethod()) {
16+
tokenAuthMethod = ClientAuthenticationMethod.PRIVATE_KEY_JWT.getValue();
17+
}
18+
return tokenAuthMethod;
19+
}
20+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package uk.gov.di.orchestration.shared.utils;
2+
3+
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
import uk.gov.di.orchestration.shared.entity.ClientRegistry;
7+
import uk.gov.di.orchestration.shared.services.ConfigurationService;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
import static org.junit.jupiter.api.Assertions.assertNull;
11+
import static org.mockito.Mockito.mock;
12+
import static org.mockito.Mockito.when;
13+
14+
public class ClientUtilsTest {
15+
private final ConfigurationService configurationService = mock(ConfigurationService.class);
16+
17+
@BeforeEach
18+
public void setup() {
19+
when(configurationService.isUseDefaultTokenAuthMethod()).thenReturn(false);
20+
}
21+
22+
@Test
23+
void shouldDefaultToPrivateKeyJwtIfFeatureFlagIsEnabledAndTokenAuthMethodIsNull() {
24+
when(configurationService.isUseDefaultTokenAuthMethod()).thenReturn(true);
25+
var client = clientWithTokenAuthMethod(null);
26+
27+
var actualTokenAuthMethod =
28+
ClientUtils.getTokenAuthMethodOrDefault(client, configurationService);
29+
assertEquals(actualTokenAuthMethod, ClientAuthenticationMethod.PRIVATE_KEY_JWT.getValue());
30+
}
31+
32+
@Test
33+
void shouldNotDefaultToPrivateKeyJwtIfFeatureFlagDisabled() {
34+
when(configurationService.isUseDefaultTokenAuthMethod()).thenReturn(false);
35+
var client = clientWithTokenAuthMethod(null);
36+
37+
var actualTokenAuthMethod =
38+
ClientUtils.getTokenAuthMethodOrDefault(client, configurationService);
39+
assertNull(actualTokenAuthMethod);
40+
}
41+
42+
@Test
43+
void shouldNotDefaultToPrivateKeyJwtIfFeatureFlagIsEnabledAndTokenAuthMethodIsAlreadySet() {
44+
when(configurationService.isUseDefaultTokenAuthMethod()).thenReturn(true);
45+
var client =
46+
clientWithTokenAuthMethod(ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue());
47+
48+
var actualTokenAuthMethod =
49+
ClientUtils.getTokenAuthMethodOrDefault(client, configurationService);
50+
assertEquals(
51+
actualTokenAuthMethod, ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue());
52+
}
53+
54+
private ClientRegistry clientWithTokenAuthMethod(String tokenAuthMethod) {
55+
return new ClientRegistry()
56+
.withClientID("client-id")
57+
.withClientName("client-one")
58+
.withTokenAuthMethod(tokenAuthMethod);
59+
}
60+
}

0 commit comments

Comments
 (0)