Refactor to use standard config default values

This commit is contained in:
Alexey Klyucherev 2024-12-19 13:18:10 +07:00
parent f2573b4485
commit 2e92a7cda8
2 changed files with 4 additions and 6 deletions

View File

@ -704,7 +704,8 @@ public final class Keys {
*/
public static final ConfigKey<String> OPENID_GROUPS_CLAIM_NAME = new StringConfigKey(
"openid.groupsClaimName",
List.of(KeyType.CONFIG));
List.of(KeyType.CONFIG),
"groups");
/**
* OpenID Connect group to restrict access to.

View File

@ -33,7 +33,6 @@ import java.security.GeneralSecurityException;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.util.Objects;
import jakarta.servlet.http.HttpServletRequest;
@ -122,7 +121,7 @@ public class OpenIdProvider {
Scope scope = new Scope("openid", "profile", "email");
if (adminGroup != null) {
scope.add(Objects.requireNonNullElse(groupsClaimName, "groups"));
scope.add(groupsClaimName);
}
AuthenticationRequest.Builder request = new AuthenticationRequest.Builder(
@ -187,9 +186,7 @@ public class OpenIdProvider {
UserInfo userInfo = getUserInfo(bearerToken);
List<String> userGroups = groupsClaimName != null
? userInfo.getStringListClaim(groupsClaimName)
: userInfo.getStringListClaim("groups");
List<String> userGroups = userInfo.getStringListClaim(groupsClaimName);
boolean administrator = adminGroup != null && userGroups.contains(adminGroup);
if (!(administrator || allowGroup == null || userGroups.contains(allowGroup))) {