Skip to content

Commit

Permalink
fix(jans-auth-server): npe - regression in token endpoint (#2763)
Browse files Browse the repository at this point in the history
* fix(jans-auth-server): npe - regression in token endpoint

Native SSO

#2518
#2762

* fix(jans-auth-server): added test for npe fix

Native SSO

#2518
#2762
  • Loading branch information
yuriyz authored Oct 28, 2022
1 parent c368a02 commit fe659d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ public JSONObject processTokenExchange(String scope, Function<JsonWebResponse, V
}

public void putNewDeviceSecret(JSONObject jsonObj, String sessionDn, Client client, String scope) {
if (!scope.contains(ScopeConstants.DEVICE_SSO)) {
if (StringUtils.isBlank(scope) || !scope.contains(ScopeConstants.DEVICE_SSO)) {
return;
}
if (!ArrayUtils.contains(client.getGrantTypes(), GrantType.TOKEN_EXCHANGE)) {
if (client == null || !ArrayUtils.contains(client.getGrantTypes(), GrantType.TOKEN_EXCHANGE)) {
log.debug("Skip device secret. Scope has {} value but client does not have Token Exchange Grant Type enabled ('urn:ietf:params:oauth:grant-type:token-exchange')", ScopeConstants.DEVICE_SSO);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ public class TokenExchangeServiceTest {
@InjectMocks
private TokenExchangeService tokenExchangeService;

@Test
public void putNewDeviceSecret_whenScopeIsNull_shouldNotGenerateDeviceSecretAndShouldNotThrowNPE() {
SessionId sessionId = new SessionId();
Client client = new Client();
client.setGrantTypes(new GrantType[] {GrantType.AUTHORIZATION_CODE, GrantType.TOKEN_EXCHANGE});

final JSONObject jsonObj = new JSONObject();
tokenExchangeService.putNewDeviceSecret(jsonObj, "sessionDn", client, null);

assertTrue(sessionId.getDeviceSecrets().isEmpty());
assertFalse(jsonObj.has("device_token"));
}

@Test
public void putNewDeviceSecret_whenScopeDeviceSSOIsNotPresent_shouldNotGenerateDeviceSecret() {
SessionId sessionId = new SessionId();
Expand All @@ -60,7 +73,6 @@ public void putNewDeviceSecret_whenScopeDeviceSSOIsNotPresent_shouldNotGenerateD
assertFalse(jsonObj.has("device_token"));
}


@Test
public void putNewDeviceSecret_whenTokenExchangeGrantIsNotPresent_shouldNotGenerateDeviceSecret() {
SessionId sessionId = new SessionId();
Expand Down

0 comments on commit fe659d7

Please sign in to comment.