GCube* names changed to D4Science*
This commit is contained in:
parent
e7d3518740
commit
3a0a0d8bfc
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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<ProviderConfigProperty> 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
|
|
@ -1 +1 @@
|
|||
org.gcube.keycloak.protocol.oidc.mapper.GCubeContextMapper
|
||||
org.gcube.keycloak.protocol.oidc.mapper.D4ScienceContextMapper
|
|
@ -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<String> configPropertyNames = new GCubeContextMapper().getConfigProperties().stream()
|
||||
final List<String> 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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue