diff --git a/docker-compose.yaml b/docker-compose.yaml
index f622ff31b1..334f094204 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -89,7 +89,7 @@ services:
- CONSOLE_LOGGING_LEVEL=trace
depends_on:
api-lagoon-migrations:
- condition: service_completed_successfully # don't start the API until the lagoon migrations are completed
+ condition: service_started
keycloak:
condition: service_started
ports:
diff --git a/services/keycloak/Dockerfile b/services/keycloak/Dockerfile
index c5a0bb53e2..58fd58477b 100644
--- a/services/keycloak/Dockerfile
+++ b/services/keycloak/Dockerfile
@@ -1,3 +1,9 @@
+FROM maven:3.8.2-jdk-11 as builder
+
+COPY custom-mapper/. .
+
+RUN mvn clean compile package
+
ARG UPSTREAM_REPO
ARG UPSTREAM_TAG
FROM ${UPSTREAM_REPO:-uselagoon}/commons:${UPSTREAM_TAG:-latest} as commons
@@ -67,6 +73,11 @@ ENV TMPDIR=/tmp \
KEYCLOAK_API_CLIENT_SECRET=39d5282d-3684-4026-b4ed-04bbc034b61a \
KEYCLOAK_AUTH_SERVER_CLIENT_SECRET=f605b150-7636-4447-abd3-70988786b330 \
KEYCLOAK_SERVICE_API_CLIENT_SECRET=d3724d52-34d1-4967-a802-4d178678564b \
+ LAGOON_DB_VENDOR=mariadb \
+ LAGOON_DB_DATABASE=infrastructure \
+ LAGOON_DB_USER=api \
+ LAGOON_DB_PASSWORD=api \
+ LAGOON_DB_HOST=api-db \
JAVA_OPTS="-server -Xms2048m -Xmx4096m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true"
VOLUME /opt/jboss/keycloak/standalone/data
@@ -78,6 +89,7 @@ COPY profile.properties /opt/jboss/keycloak/standalone/configuration/profile.pro
COPY configure-ds-pool.cli /opt/jboss/tools/cli/databases/configure-ds-pool.cli
COPY themes/lagoon /opt/jboss/keycloak/themes/lagoon
COPY --from=commons /tmp/lagoon-scripts.jar /opt/jboss/keycloak/standalone/deployments/lagoon-scripts.jar
+COPY --from=builder /target/custom-protocol-mapper-1.0.0.jar /opt/jboss/keycloak/standalone/deployments/custom-protocol-mapper-1.0.0.jar
ENTRYPOINT ["/sbin/tini", "--", "/lagoon/entrypoints.bash"]
CMD ["-b", "0.0.0.0"]
diff --git a/services/keycloak/custom-mapper/pom.xml b/services/keycloak/custom-mapper/pom.xml
new file mode 100644
index 0000000000..2b6bcec1f3
--- /dev/null
+++ b/services/keycloak/custom-mapper/pom.xml
@@ -0,0 +1,78 @@
+
+
+ 4.0.0
+
+ net.cake.keycloak.custom
+ custom-protocol-mapper
+ 1.0.0
+ jar
+
+
+ 17.0.1
+
+
+
+
+
+ org.keycloak
+ keycloak-core
+ ${keycloak.version}
+ provided
+
+
+ org.keycloak
+ keycloak-server-spi
+ ${keycloak.version}
+ provided
+
+
+ org.keycloak
+ keycloak-server-spi-private
+ ${keycloak.version}
+ provided
+
+
+ org.keycloak
+ keycloak-services
+ ${keycloak.version}
+ provided
+
+
+ org.mariadb.jdbc
+ mariadb-java-client
+ LATEST
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.7.0
+
+ true
+
+ 1.8
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.1.0
+
+
+
+ package
+
+ shade
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/services/keycloak/custom-mapper/src/main/java/CustomOIDCProtocolMapper.java b/services/keycloak/custom-mapper/src/main/java/CustomOIDCProtocolMapper.java
new file mode 100644
index 0000000000..dc80053237
--- /dev/null
+++ b/services/keycloak/custom-mapper/src/main/java/CustomOIDCProtocolMapper.java
@@ -0,0 +1,167 @@
+import org.keycloak.models.ClientSessionContext;
+import org.keycloak.models.KeycloakSession;
+import org.keycloak.models.ProtocolMapperModel;
+import org.keycloak.models.UserSessionModel;
+import org.keycloak.protocol.oidc.OIDCLoginProtocol;
+import org.keycloak.protocol.oidc.mappers.*;
+import org.keycloak.provider.ProviderConfigProperty;
+import org.keycloak.representations.AccessToken;
+import org.jboss.logging.Logger;
+
+import org.keycloak.models.IdentityProviderMapperModel;
+import org.keycloak.models.RealmModel;
+import org.keycloak.models.GroupModel;
+import org.keycloak.models.UserModel;
+import org.keycloak.models.RoleModel;
+import org.keycloak.models.utils.KeycloakModelUtils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
+import java.sql.PreparedStatement;
+
+public class CustomOIDCProtocolMapper extends AbstractOIDCProtocolMapper implements OIDCAccessTokenMapper, OIDCIDTokenMapper, UserInfoTokenMapper {
+
+ public static final String PROVIDER_ID = "lagoon-search-customprotocolmapper";
+
+ private static final Logger logger = Logger.getLogger(CustomOIDCProtocolMapper.class);
+
+ private static final List configProperties = new ArrayList();
+
+ /**
+ * Maybe you want to have config fields for your Mapper
+ */
+ /*
+ static {
+ ProviderConfigProperty property;
+ property = new ProviderConfigProperty();
+ property.setName(ProtocolMapperUtils.USER_ATTRIBUTE);
+ property.setLabel(ProtocolMapperUtils.USER_MODEL_ATTRIBUTE_LABEL);
+ property.setHelpText(ProtocolMapperUtils.USER_MODEL_ATTRIBUTE_HELP_TEXT);
+ property.setType(ProviderConfigProperty.STRING_TYPE);
+ configProperties.add(property);
+
+ property = new ProviderConfigProperty();
+ property.setName(ProtocolMapperUtils.MULTIVALUED);
+ property.setLabel(ProtocolMapperUtils.MULTIVALUED_LABEL);
+ property.setHelpText(ProtocolMapperUtils.MULTIVALUED_HELP_TEXT);
+ property.setType(ProviderConfigProperty.BOOLEAN_TYPE);
+ configProperties.add(property);
+
+ }
+ */
+ @Override
+ public List getConfigProperties() {
+ return configProperties;
+ }
+
+ @Override
+ public String getDisplayCategory() {
+ return TOKEN_MAPPER_CATEGORY;
+ }
+
+ @Override
+ public String getDisplayType() {
+ return "Lagoon Project Group Mapper";
+ }
+
+ @Override
+ public String getId() {
+ return PROVIDER_ID;
+ }
+
+ @Override
+ public String getHelpText() {
+ return "A mapper that can retrieve groups and projects from the lagoon API to store in the token";
+ }
+
+ public AccessToken transformAccessToken(AccessToken token, ProtocolMapperModel mappingModel, KeycloakSession keycloakSession,
+ UserSessionModel userSession, ClientSessionContext clientSessionCtx) {
+
+ List