From 04a2ba0f952ade45ca14b4fcc6bd53779df75800 Mon Sep 17 00:00:00 2001 From: Xander Smeets Date: Thu, 4 Apr 2024 23:25:14 +0200 Subject: [PATCH] Fix issue 3 described in https://github.com/jacekkow/keycloak-protocol-cas/pull/49#issuecomment-1106850038 --- .../cas/mappers/CASUsernameMapper.java | 11 -------- ...UsernameMapper.java => CasUserMapper.java} | 25 +++++++++++++++++-- .../cas/utils/UsernameMapperHelper.java | 6 ++--- 3 files changed, 26 insertions(+), 16 deletions(-) delete mode 100644 src/main/java/org/keycloak/protocol/cas/mappers/CASUsernameMapper.java rename src/main/java/org/keycloak/protocol/cas/mappers/{UserAttributeCasUsernameMapper.java => CasUserMapper.java} (85%) diff --git a/src/main/java/org/keycloak/protocol/cas/mappers/CASUsernameMapper.java b/src/main/java/org/keycloak/protocol/cas/mappers/CASUsernameMapper.java deleted file mode 100644 index 0f6e310..0000000 --- a/src/main/java/org/keycloak/protocol/cas/mappers/CASUsernameMapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.keycloak.protocol.cas.mappers; - -import org.keycloak.models.*; -import org.keycloak.protocol.ProtocolMapper; - -public interface CASUsernameMapper extends ProtocolMapper { - - String getMappedUsername(ProtocolMapperModel mappingModel, KeycloakSession session, - UserSessionModel userSession, AuthenticatedClientSessionModel clientSession); - -} \ No newline at end of file diff --git a/src/main/java/org/keycloak/protocol/cas/mappers/UserAttributeCasUsernameMapper.java b/src/main/java/org/keycloak/protocol/cas/mappers/CasUserMapper.java similarity index 85% rename from src/main/java/org/keycloak/protocol/cas/mappers/UserAttributeCasUsernameMapper.java rename to src/main/java/org/keycloak/protocol/cas/mappers/CasUserMapper.java index caa998e..5de000e 100644 --- a/src/main/java/org/keycloak/protocol/cas/mappers/UserAttributeCasUsernameMapper.java +++ b/src/main/java/org/keycloak/protocol/cas/mappers/CasUserMapper.java @@ -10,7 +10,7 @@ import java.util.ArrayList; import java.util.List; -public class UserAttributeCasUsernameMapper extends AbstractCASProtocolMapper implements CASUsernameMapper { +public class CASUserMapper implements ProtocolMapper { public static final String PROVIDER_ID = "cas-usermodel-username-mapper"; public static final String USERNAME_MAPPER_CATEGORY = "CAS Username Mapper"; private static final String CONF_FALLBACK_TO_USERNAME_IF_NULL = "username_fallback"; @@ -36,6 +36,28 @@ public class UserAttributeCasUsernameMapper extends AbstractCASProtocolMapper im } + @Override + public String getProtocol() { + return CASLoginProtocol.LOGIN_PROTOCOL; + } + + @Override + public void close() { + } + + @Override + public final ProtocolMapper create(KeycloakSession session) { + throw new RuntimeException("UNSUPPORTED METHOD"); + } + + @Override + public void init(Config.Scope config) { + } + + @Override + public void postInit(KeycloakSessionFactory factory) { + } + @Override public final String getDisplayCategory() { return USERNAME_MAPPER_CATEGORY; @@ -61,7 +83,6 @@ public List getConfigProperties() { return configProperties; } - @Override public String getMappedUsername(ProtocolMapperModel mappingModel, KeycloakSession session, UserSessionModel userSession, AuthenticatedClientSessionModel clientSession) { diff --git a/src/main/java/org/keycloak/protocol/cas/utils/UsernameMapperHelper.java b/src/main/java/org/keycloak/protocol/cas/utils/UsernameMapperHelper.java index 907cdfa..1a40649 100644 --- a/src/main/java/org/keycloak/protocol/cas/utils/UsernameMapperHelper.java +++ b/src/main/java/org/keycloak/protocol/cas/utils/UsernameMapperHelper.java @@ -3,7 +3,7 @@ import org.keycloak.models.*; import org.keycloak.protocol.ProtocolMapper; import org.keycloak.protocol.ProtocolMapperUtils; -import org.keycloak.protocol.cas.mappers.CASUsernameMapper; +import org.keycloak.protocol.cas.mappers.CASUserMapper; import org.keycloak.services.util.DefaultClientSessionContext; import java.util.Map; @@ -16,7 +16,7 @@ public static String getMappedUsername(KeycloakSession session, AuthenticatedCli Map.Entry mapperPair = ProtocolMapperUtils.getSortedProtocolMappers(session,clientSessionCtx) - .filter(e -> e.getValue() instanceof CASUsernameMapper) + .filter(e -> e.getValue() instanceof CASUserMapper) .findFirst() .orElse(null); @@ -24,7 +24,7 @@ public static String getMappedUsername(KeycloakSession session, AuthenticatedCli if(mapperPair != null) { ProtocolMapperModel mapping = mapperPair.getKey(); - CASUsernameMapper casUsernameMapper = (CASUsernameMapper) mapperPair.getValue(); + CASUserMapper casUsernameMapper = (CASUserMapper) mapperPair.getValue(); mappedUsername = casUsernameMapper.getMappedUsername(mapping, session, userSession, clientSession); } return mappedUsername;