From 3a0a0d8bfcf6b742ccfcc5ee2a40403edead216c Mon Sep 17 00:00:00 2001 From: Mauro Mugnaini Date: Thu, 22 Dec 2022 16:10:32 +0100 Subject: [PATCH] GCube* names changed to D4Science* --- protocol-mapper/CHANGELOG.md | 2 +- protocol-mapper/README.md | 2 +- ...Mapper.java => D4ScienceContextMapper.java} | 16 +++++++++------- .../org.keycloak.protocol.ProtocolMapper | 2 +- ...st.java => D4ScienceContextMapperTest.java} | 18 +++++++++--------- 5 files changed, 21 insertions(+), 19 deletions(-) rename protocol-mapper/src/main/java/org/gcube/keycloak/protocol/oidc/mapper/{GCubeContextMapper.java => D4ScienceContextMapper.java} (80%) rename protocol-mapper/src/test/java/org/gcube/keycloak/protocol/oidc/mapper/{GCubeContextMapperTest.java => D4ScienceContextMapperTest.java} (86%) diff --git a/protocol-mapper/CHANGELOG.md b/protocol-mapper/CHANGELOG.md index e508305..0ff63e6 100644 --- a/protocol-mapper/CHANGELOG.md +++ b/protocol-mapper/CHANGELOG.md @@ -3,4 +3,4 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm # Changelog for "identity-provider-mapper" ## [v2.1.0-SNAPSHOT] -- Added new module to make the protocol mappers available +- Added new module to make the custom protocol mappers available diff --git a/protocol-mapper/README.md b/protocol-mapper/README.md index 630c53b..713647d 100644 --- a/protocol-mapper/README.md +++ b/protocol-mapper/README.md @@ -1,6 +1,6 @@ # Identity Provider Mapper -**Protocol Mapper** extends the [Keycloak](https://www.keycloak.org)'s OIDC protocol mapper SPI to map the token audience to the value read from a custom `X-GCube-Context` HTTP header. +**Protocol Mapper** extends the [Keycloak](https://www.keycloak.org)'s OIDC protocol mappers SPI. In this first release is introduced the possibility to specify the token audience by reading the value of a custom `X-D4Science-Context` HTTP header. ## Structure of the project diff --git a/protocol-mapper/src/main/java/org/gcube/keycloak/protocol/oidc/mapper/GCubeContextMapper.java b/protocol-mapper/src/main/java/org/gcube/keycloak/protocol/oidc/mapper/D4ScienceContextMapper.java similarity index 80% rename from protocol-mapper/src/main/java/org/gcube/keycloak/protocol/oidc/mapper/GCubeContextMapper.java rename to protocol-mapper/src/main/java/org/gcube/keycloak/protocol/oidc/mapper/D4ScienceContextMapper.java index 643356a..74f6175 100644 --- a/protocol-mapper/src/main/java/org/gcube/keycloak/protocol/oidc/mapper/GCubeContextMapper.java +++ b/protocol-mapper/src/main/java/org/gcube/keycloak/protocol/oidc/mapper/D4ScienceContextMapper.java @@ -15,23 +15,25 @@ import org.keycloak.provider.ProviderConfigProperty; import org.keycloak.representations.AccessToken; import org.keycloak.representations.IDToken; -public class GCubeContextMapper extends AbstractOIDCProtocolMapper implements OIDCAccessTokenMapper { +public class D4ScienceContextMapper extends AbstractOIDCProtocolMapper implements OIDCAccessTokenMapper { - private static final Logger logger = Logger.getLogger(GCubeContextMapper.class); + private static final Logger logger = Logger.getLogger(D4ScienceContextMapper.class); private static final List configProperties = new ArrayList<>(); // Assuring that the mapper is executed as last private static final int PRIORITY = Integer.MAX_VALUE; - private static final String DISPLAY_TYPE = "OIDC GCube Context Mapper"; - private static final String PROVIDER_ID = "oidc-gcube-context-mapper"; + private static final String DISPLAY_TYPE = "OIDC D4Science Context Mapper"; + private static final String PROVIDER_ID = "oidc-d4scince-context-mapper"; - public static final String HEADER_NAME = "X-GCube-Context"; + public static final String HEADER_NAME = "X-D4Science-Context"; +// public static final String HEADER_NAME = "X-Infrastructure-Context"; +// public static final String HEADER_NAME = "X-Infra-Context"; static { OIDCAttributeMapperHelper.addTokenClaimNameConfig(configProperties); - OIDCAttributeMapperHelper.addIncludeInTokensConfig(configProperties, GCubeContextMapper.class); + OIDCAttributeMapperHelper.addIncludeInTokensConfig(configProperties, D4ScienceContextMapper.class); } @Override @@ -51,7 +53,7 @@ public class GCubeContextMapper extends AbstractOIDCProtocolMapper implements OI @Override public String getHelpText() { - return "Reads GCube context from " + HEADER_NAME + " header and sets it as the configured token claim"; + return "Maps the D4Science context audience by reading the '" + HEADER_NAME + "' header and sets it as the configured token claim"; } @Override diff --git a/protocol-mapper/src/main/resources/META-INF/services/org.keycloak.protocol.ProtocolMapper b/protocol-mapper/src/main/resources/META-INF/services/org.keycloak.protocol.ProtocolMapper index a1a6017..5b8f773 100644 --- a/protocol-mapper/src/main/resources/META-INF/services/org.keycloak.protocol.ProtocolMapper +++ b/protocol-mapper/src/main/resources/META-INF/services/org.keycloak.protocol.ProtocolMapper @@ -1 +1 @@ -org.gcube.keycloak.protocol.oidc.mapper.GCubeContextMapper \ No newline at end of file +org.gcube.keycloak.protocol.oidc.mapper.D4ScienceContextMapper \ No newline at end of file diff --git a/protocol-mapper/src/test/java/org/gcube/keycloak/protocol/oidc/mapper/GCubeContextMapperTest.java b/protocol-mapper/src/test/java/org/gcube/keycloak/protocol/oidc/mapper/D4ScienceContextMapperTest.java similarity index 86% rename from protocol-mapper/src/test/java/org/gcube/keycloak/protocol/oidc/mapper/GCubeContextMapperTest.java rename to protocol-mapper/src/test/java/org/gcube/keycloak/protocol/oidc/mapper/D4ScienceContextMapperTest.java index c4cb833..1829ad3 100644 --- a/protocol-mapper/src/test/java/org/gcube/keycloak/protocol/oidc/mapper/GCubeContextMapperTest.java +++ b/protocol-mapper/src/test/java/org/gcube/keycloak/protocol/oidc/mapper/D4ScienceContextMapperTest.java @@ -29,7 +29,7 @@ import org.mockito.Mockito; /** * Original code repo: https://github.com/mschwartau/keycloak-custom-protocol-mapper-example */ -public class GCubeContextMapperTest { +public class D4ScienceContextMapperTest { static final String CLAIM_NAME = "haandlerIdClaimNameExample"; static final String HEADER_VALUE = "ginostilla"; @@ -37,27 +37,27 @@ public class GCubeContextMapperTest { @Test public void shouldTokenMapperDisplayCategory() { final String tokenMapperDisplayCategory = new FullNameMapper().getDisplayCategory(); - assertThat(new GCubeContextMapper().getDisplayCategory()).isEqualTo(tokenMapperDisplayCategory); + assertThat(new D4ScienceContextMapper().getDisplayCategory()).isEqualTo(tokenMapperDisplayCategory); } @Test public void shouldHaveDisplayType() { - assertThat(new GCubeContextMapper().getDisplayType()).isNotBlank(); + assertThat(new D4ScienceContextMapper().getDisplayType()).isNotBlank(); } @Test public void shouldHaveHelpText() { - assertThat(new GCubeContextMapper().getHelpText()).isNotBlank(); + assertThat(new D4ScienceContextMapper().getHelpText()).isNotBlank(); } @Test public void shouldHaveIdId() { - assertThat(new GCubeContextMapper().getId()).isNotBlank(); + assertThat(new D4ScienceContextMapper().getId()).isNotBlank(); } @Test public void shouldHaveProperties() { - final List configPropertyNames = new GCubeContextMapper().getConfigProperties().stream() + final List configPropertyNames = new D4ScienceContextMapper().getConfigProperties().stream() .map(ProviderConfigProperty::getName) .collect(Collectors.toList()); @@ -104,9 +104,9 @@ public class GCubeContextMapperTest { when(context.getRequestHeaders()).thenReturn(headers); if (withHeader) { - when(headers.getHeaderString(GCubeContextMapper.HEADER_NAME)).thenReturn(HEADER_VALUE); + when(headers.getHeaderString(D4ScienceContextMapper.HEADER_NAME)).thenReturn(HEADER_VALUE); } else { - when(headers.getHeaderString(GCubeContextMapper.HEADER_NAME)).thenReturn(""); + when(headers.getHeaderString(D4ScienceContextMapper.HEADER_NAME)).thenReturn(""); } return keycloakSession; } @@ -121,7 +121,7 @@ public class GCubeContextMapperTest { at.setResourceAccess(Maps.newHashMap(HEADER_VALUE, null)); } - return new GCubeContextMapper().transformAccessToken(at, mappingModel, keycloakSession, + return new D4ScienceContextMapper().transformAccessToken(at, mappingModel, keycloakSession, userSessionModel, givenClientSessionContext()); }