Map middle name from default OIDC profile

This commit is contained in:
AFaust 2021-10-17 11:58:40 +02:00
parent ae9b742dd7
commit 28c7ddb87f
2 changed files with 27 additions and 7 deletions

View File

@ -43,6 +43,7 @@ keycloak.authentication.userAuthority.default.property.defaultResourceRoleNameMa
keycloak.authentication.userToken.default.property.enabled=true
keycloak.authentication.userToken.default.property.mapNull=true
keycloak.authentication.userToken.default.property.mapGivenName=true
keycloak.authentication.userToken.default.property.mapMiddleName=true
keycloak.authentication.userToken.default.property.mapFamilyName=true
keycloak.authentication.userToken.default.property.mapEmail=true
keycloak.authentication.userToken.default.property.mapPhoneNumber=true

View File

@ -19,6 +19,7 @@ import java.io.Serializable;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.keycloak.representations.AccessToken;
import org.keycloak.representations.IDToken;
@ -31,12 +32,17 @@ import org.keycloak.representations.IDToken;
public class DefaultPersonProcessor implements UserProcessor
{
// missing in ContentModel constants
private static final QName PROP_MIDDLE_NAME = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "middleName");
protected boolean enabled;
protected boolean mapNull;
protected boolean mapGivenName;
protected boolean mapMiddleName;
protected boolean mapFamilyName;
protected boolean mapEmail;
@ -47,7 +53,7 @@ public class DefaultPersonProcessor implements UserProcessor
/**
* @param enabled
* the enabled to set
* the enabled to set
*/
public void setEnabled(final boolean enabled)
{
@ -56,7 +62,7 @@ public class DefaultPersonProcessor implements UserProcessor
/**
* @param mapNull
* the mapNull to set
* the mapNull to set
*/
public void setMapNull(final boolean mapNull)
{
@ -65,16 +71,25 @@ public class DefaultPersonProcessor implements UserProcessor
/**
* @param mapGivenName
* the mapGivenName to set
* the mapGivenName to set
*/
public void setMapGivenName(final boolean mapGivenName)
{
this.mapGivenName = mapGivenName;
}
/**
* @param mapMiddleName
* the mapMiddleName to set
*/
public void setMapMiddleName(final boolean mapMiddleName)
{
this.mapMiddleName = mapMiddleName;
}
/**
* @param mapFamilyName
* the mapFamilyName to set
* the mapFamilyName to set
*/
public void setMapFamilyName(final boolean mapFamilyName)
{
@ -83,7 +98,7 @@ public class DefaultPersonProcessor implements UserProcessor
/**
* @param mapEmail
* the mapEmail to set
* the mapEmail to set
*/
public void setMapEmail(final boolean mapEmail)
{
@ -92,7 +107,7 @@ public class DefaultPersonProcessor implements UserProcessor
/**
* @param mapPhoneNumber
* the mapPhoneNumber to set
* the mapPhoneNumber to set
*/
public void setMapPhoneNumber(final boolean mapPhoneNumber)
{
@ -101,7 +116,7 @@ public class DefaultPersonProcessor implements UserProcessor
/**
* @param mapPhoneNumberAsMobile
* the mapPhoneNumberAsMobile to set
* the mapPhoneNumberAsMobile to set
*/
public void setMapPhoneNumberAsMobile(final boolean mapPhoneNumberAsMobile)
{
@ -121,6 +136,10 @@ public class DefaultPersonProcessor implements UserProcessor
{
personNodeProperties.put(ContentModel.PROP_FIRSTNAME, idToken.getGivenName());
}
if ((this.mapNull || idToken.getMiddleName() != null) && this.mapMiddleName)
{
personNodeProperties.put(PROP_MIDDLE_NAME, idToken.getMiddleName());
}
if ((this.mapNull || idToken.getFamilyName() != null) && this.mapFamilyName)
{
personNodeProperties.put(ContentModel.PROP_LASTNAME, idToken.getFamilyName());