Skip to content

Commit 985c95d

Browse files
authored
Populate OpenIDConnect metadata collections (elastic#50893)
The OpenIdConnectRealm had a bug which would cause it not to populate User metadata for collections contained in the user JWT claims. This commit fixes that bug. Backport of: elastic#50521
1 parent fa116a6 commit 985c95d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/oidc/OpenIdConnectRealm.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.net.URI;
5050
import java.net.URISyntaxException;
5151

52+
import java.util.Collection;
5253
import java.util.Collections;
5354
import java.util.HashMap;
5455
import java.util.List;
@@ -218,7 +219,7 @@ private void buildUserFromClaims(JWTClaimsSet claims, ActionListener<Authenticat
218219
*/
219220
Set<Map.Entry> allowedEntries = claimsMap.entrySet().stream().filter(entry -> {
220221
Object v = entry.getValue();
221-
return (v instanceof String || v instanceof Boolean || v instanceof Number || v instanceof Collections);
222+
return (v instanceof String || v instanceof Boolean || v instanceof Number || v instanceof Collection);
222223
}).collect(Collectors.toSet());
223224
for (Map.Entry entry : allowedEntries) {
224225
userMetadata.put("oidc(" + entry.getKey() + ")", entry.getValue());

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/oidc/OpenIdConnectRealmTests.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.elasticsearch.env.Environment;
1717
import org.elasticsearch.env.TestEnvironment;
1818
import org.elasticsearch.license.XPackLicenseState;
19-
2019
import org.elasticsearch.xpack.core.security.action.oidc.OpenIdConnectLogoutResponse;
2120
import org.elasticsearch.xpack.core.security.action.oidc.OpenIdConnectPrepareAuthenticationResponse;
2221
import org.elasticsearch.xpack.core.security.authc.AuthenticationResult;
@@ -31,6 +30,7 @@
3130
import org.junit.Before;
3231

3332
import java.util.Arrays;
33+
import java.util.Collection;
3434
import java.util.Collections;
3535
import java.util.Date;
3636
import java.util.HashSet;
@@ -43,6 +43,7 @@
4343
import static org.elasticsearch.xpack.core.security.authc.RealmSettings.getFullSettingKey;
4444
import static org.elasticsearch.xpack.security.authc.oidc.OpenIdConnectRealm.CONTEXT_TOKEN_DATA;
4545
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
46+
import static org.hamcrest.Matchers.contains;
4647
import static org.hamcrest.Matchers.containsString;
4748
import static org.hamcrest.Matchers.equalTo;
4849
import static org.hamcrest.Matchers.instanceOf;
@@ -91,6 +92,10 @@ public void testAuthentication() throws Exception {
9192
} else {
9293
assertThat(result.getUser().metadata().get("oidc(iss)"), equalTo("https://op.company.org"));
9394
assertThat(result.getUser().metadata().get("oidc(name)"), equalTo("Clinton Barton"));
95+
final Object groups = result.getUser().metadata().get("oidc(groups)");
96+
assertThat(groups, notNullValue());
97+
assertThat(groups, instanceOf(Collection.class));
98+
assertThat((Collection<?>) groups, contains("group1", "group2", "groups3"));
9499
}
95100
}
96101

0 commit comments

Comments
 (0)