Skip to content
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

fix(jans-auth-server): npe - regression in token endpoint #2763

Merged
merged 2 commits into from
Oct 28, 2022
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
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