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): Duplicate iss and aud on introspection as jwt #3366 #3387

Merged
merged 1 commit into from
Dec 22, 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 @@ -202,11 +202,25 @@ public void setClaimObject(String key, Object value, boolean overrideValue) {
}

private void setClaimString(String key, Object value, boolean overrideValue) {
Object currentValue = getClaim(key);
if (overrideValue || currentValue == null) {
if (overrideValue) {
setClaim(key, (String) value);
} else {
setClaim(key, Lists.newArrayList(currentValue.toString(), (String) value));
return;
}

Object currentValue = getClaim(key);
String valueAsString = (String) value;

if (currentValue instanceof String) {
if (!currentValue.equals(value)) {
setClaim(key, Lists.newArrayList(currentValue.toString(), valueAsString));
} else {
setClaim(key, (String) value);
}
} else if (currentValue instanceof List) {
List<String> currentValueAsList = (List) currentValue;
if (!currentValueAsList.contains(valueAsString)) {
currentValueAsList.add(valueAsString);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.jans.as.model.jwt;

import com.google.common.collect.Lists;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

/**
* @author Yuriy Z
*/
public class JwtClaimsTest {

@Test
public void setClaimObject_whenSetSameValue_shouldNotCreateDuplicate() {
JwtClaims claims = new JwtClaims();
claims.addAudience("client1");

claims.setClaimObject("aud", "client1", false);
assertEquals(claims.getClaim("aud"), "client1");
}

@Test
public void setClaimObject_whenSetDifferentValues_shouldCreateCorrectArray() {
JwtClaims claims = new JwtClaims();
claims.addAudience("client1");

claims.setClaimObject("aud", "client2", false);
assertEquals(claims.getClaim("aud"), Lists.newArrayList("client1", "client2"));
}

@Test
public void setClaimObject_whenSetDifferentValue_shouldCreateCorrectArray() {
JwtClaims claims = new JwtClaims();
claims.addAudience("client1");

claims.setClaimObject("aud", "client2", false);
claims.setClaimObject("aud", "client3", false);
assertEquals(claims.getClaim("aud"), Lists.newArrayList("client1", "client2", "client3"));
}

@Test
public void setClaimObject_whenSetDifferentValueWithOverride_shouldOverrideValue() {
JwtClaims claims = new JwtClaims();
claims.addAudience("client1");

claims.setClaimObject("aud", "client2", false);
claims.setClaimObject("aud", "client3", true);
assertEquals(claims.getClaim("aud"), "client3");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ private String createResponseAsJwt(JSONObject response, AuthorizationGrant grant
}
}
}
if (log.isTraceEnabled()) {
log.trace("Response before signing: {}", jwt.getClaims().toJsonString());
}

return jwtSigner.sign().toString();
}
Expand Down