Skip to content

Commit 60a3314

Browse files
tvernumSivagurunathanV
authored andcommitted
Populate OpenIDConnect metadata collections (elastic#50521)
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. Resolves: elastic#50250
1 parent c241318 commit 60a3314

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
import java.net.URI;
5050
import java.net.URISyntaxException;
51-
import java.util.Collections;
51+
import java.util.Collection;
5252
import java.util.HashMap;
5353
import java.util.List;
5454
import java.util.Map;
@@ -215,7 +215,7 @@ private void buildUserFromClaims(JWTClaimsSet claims, ActionListener<Authenticat
215215
* We whitelist the Types that we want to parse as metadata from the Claims, explicitly filtering out {@link Date}s
216216
*/
217217
Object v = entry.getValue();
218-
return (v instanceof String || v instanceof Boolean || v instanceof Number || v instanceof Collections);
218+
return (v instanceof String || v instanceof Boolean || v instanceof Number || v instanceof Collection);
219219
}).collect(Collectors.toUnmodifiableMap(entry -> "oidc(" + entry.getKey() + ")", Map.Entry::getValue));
220220
} else {
221221
userMetadata = Map.of();

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

Lines changed: 6 additions & 1 deletion
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)