From 083720b8904a50f58bc4a8a0fc573aff3ae9039f Mon Sep 17 00:00:00 2001 From: Esteban Garcia Date: Fri, 23 Jul 2021 13:14:21 +0100 Subject: [PATCH] fix(oauth2): add roles to user info mapping --- .../config/security/authn/oauth2/EditOAuth2Command.java | 8 ++++++++ .../halyard/config/model/v1/security/OAuth2.java | 2 ++ 2 files changed, 10 insertions(+) diff --git a/halyard-cli/src/main/java/com/netflix/spinnaker/halyard/cli/command/v1/config/security/authn/oauth2/EditOAuth2Command.java b/halyard-cli/src/main/java/com/netflix/spinnaker/halyard/cli/command/v1/config/security/authn/oauth2/EditOAuth2Command.java index 71b810747e..ba8c4e89b8 100644 --- a/halyard-cli/src/main/java/com/netflix/spinnaker/halyard/cli/command/v1/config/security/authn/oauth2/EditOAuth2Command.java +++ b/halyard-cli/src/main/java/com/netflix/spinnaker/halyard/cli/command/v1/config/security/authn/oauth2/EditOAuth2Command.java @@ -80,6 +80,11 @@ public class EditOAuth2Command extends AbstractEditAuthnMethodCommand { description = "The username field returned from your OAuth provider.") private String userInfoMappingUsername; + @Parameter( + names = "--user-info-mapping-roles", + description = "The roles field returned from your OAuth provider.") + private String userInfoMappingRoles; + @Parameter( names = "--provider", description = @@ -144,6 +149,9 @@ protected AuthnMethod editAuthnMethod(OAuth2 authnMethod) { userInfoMapping.setUsername( isSet(userInfoMappingUsername) ? userInfoMappingUsername : userInfoMapping.getUsername()); + userInfoMapping.setRoles( + isSet(userInfoMappingRoles) ? userInfoMappingRoles : userInfoMapping.getRoles()); + authnMethod.setProvider(provider != null ? provider : authnMethod.getProvider()); if (!userInfoRequirements.isEmpty()) { diff --git a/halyard-config/src/main/java/com/netflix/spinnaker/halyard/config/model/v1/security/OAuth2.java b/halyard-config/src/main/java/com/netflix/spinnaker/halyard/config/model/v1/security/OAuth2.java index 8183835fdc..186c55d13f 100644 --- a/halyard-config/src/main/java/com/netflix/spinnaker/halyard/config/model/v1/security/OAuth2.java +++ b/halyard-config/src/main/java/com/netflix/spinnaker/halyard/config/model/v1/security/OAuth2.java @@ -128,6 +128,7 @@ public void setProvider(Provider provider) { newUserInfoMapping.setFirstName(userInfoMapping.getFirstName()); newUserInfoMapping.setLastName(userInfoMapping.getLastName()); newUserInfoMapping.setUsername(userInfoMapping.getUsername()); + newUserInfoMapping.setRoles(userInfoMapping.getRoles()); break; default: throw new RuntimeException("Unknown provider type " + provider); @@ -161,6 +162,7 @@ public static class UserInfoMapping { private String firstName; private String lastName; private String username; + private String roles; } @Data