Class ScriptBasedMapper
- java.lang.Object
- 
- org.keycloak.protocol.saml.mappers.AbstractSAMLProtocolMapper
- 
- org.keycloak.protocol.saml.mappers.ScriptBasedMapper
 
 
- 
- All Implemented Interfaces:
- ProtocolMapper,- SAMLAttributeStatementMapper,- ConfiguredProvider,- EnvironmentDependentProviderFactory,- Provider,- ProviderFactory<ProtocolMapper>
 - Direct Known Subclasses:
- DeployedScriptSAMLProtocolMapper
 
 public class ScriptBasedMapper extends AbstractSAMLProtocolMapper implements SAMLAttributeStatementMapper, EnvironmentDependentProviderFactory This class provides a mapper that uses javascript to attach a value to an attribute for SAML tokens. The mapper can handle both a result that is a single value, or multiple values (an array or a list for example). For the latter case, it can return the result as a single attribute with multiple values, or as multiple attributes However, in all cases, the returned values must be castable to String values.- Author:
- Alistair Doswald
 
- 
- 
Field SummaryFields Modifier and Type Field Description static StringPROVIDER_ID
 - 
Constructor SummaryConstructors Constructor Description ScriptBasedMapper()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ProtocolMapperModelcreate(String name, String samlAttributeName, String nameFormat, String friendlyName, String script, boolean singleAttribute)Creates an protocol mapper model for the this script based mapper.List<ProviderConfigProperty>getConfigProperties()StringgetDisplayCategory()StringgetDisplayType()StringgetHelpText()StringgetId()protected StringgetScriptCode(ProtocolMapperModel mappingModel)booleanisSupported()voidtransformAttributeStatement(AttributeStatementType attributeStatement, ProtocolMapperModel mappingModel, KeycloakSession session, UserSessionModel userSession, AuthenticatedClientSessionModel clientSession)This method attaches one or many attributes to the passed attribute statement.voidvalidateConfig(KeycloakSession session, RealmModel realm, ProtocolMapperContainerModel client, ProtocolMapperModel mapperModel)Called when instance of mapperModel is created/updated for this protocolMapper through admin endpoint- 
Methods inherited from class org.keycloak.protocol.saml.mappers.AbstractSAMLProtocolMapperclose, create, getProtocol, init, postInit
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.keycloak.provider.ConfiguredProvidergetConfig
 - 
Methods inherited from interface org.keycloak.provider.EnvironmentDependentProviderFactoryisSupported
 - 
Methods inherited from interface org.keycloak.protocol.ProtocolMappergetPriority
 - 
Methods inherited from interface org.keycloak.provider.ProviderFactorygetConfigMetadata, order
 
- 
 
- 
- 
- 
Field Detail- 
PROVIDER_IDpublic static final String PROVIDER_ID - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getConfigPropertiespublic List<ProviderConfigProperty> getConfigProperties() - Specified by:
- getConfigPropertiesin interface- ConfiguredProvider
 
 - 
getIdpublic String getId() - Specified by:
- getIdin interface- ProviderFactory<ProtocolMapper>
 
 - 
getDisplayTypepublic String getDisplayType() - Specified by:
- getDisplayTypein interface- ProtocolMapper
 
 - 
getDisplayCategorypublic String getDisplayCategory() - Specified by:
- getDisplayCategoryin interface- ProtocolMapper
 
 - 
getHelpTextpublic String getHelpText() - Specified by:
- getHelpTextin interface- ConfiguredProvider
 
 - 
isSupportedpublic boolean isSupported() - Specified by:
- isSupportedin interface- EnvironmentDependentProviderFactory
- Returns:
- trueif the provider is supported and should be available,- falseotherwise
 
 - 
transformAttributeStatementpublic void transformAttributeStatement(AttributeStatementType attributeStatement, ProtocolMapperModel mappingModel, KeycloakSession session, UserSessionModel userSession, AuthenticatedClientSessionModel clientSession) This method attaches one or many attributes to the passed attribute statement. To obtain the attribute values, it executes the mapper's script and returns attaches the returned value to the attribute. If the returned attribute is an Array or is iterable, the mapper will either return multiple attributes, or an attribute with multiple values. The variant chosen depends on the configuration of the mapper- Specified by:
- transformAttributeStatementin interface- SAMLAttributeStatementMapper
- Parameters:
- attributeStatement- The attribute statements to be added to a token
- mappingModel- The mapping model reflects the values that are actually input in the GUI
- session- The current session
- userSession- The current user session
- clientSession- The current client session
 
 - 
validateConfigpublic void validateConfig(KeycloakSession session, RealmModel realm, ProtocolMapperContainerModel client, ProtocolMapperModel mapperModel) throws ProtocolMapperConfigException Description copied from interface:ProtocolMapperCalled when instance of mapperModel is created/updated for this protocolMapper through admin endpoint- Specified by:
- validateConfigin interface- ProtocolMapper
- client- client or clientTemplate
- Throws:
- ProtocolMapperConfigException- if configuration provided in mapperModel is not valid
 
 - 
getScriptCodeprotected String getScriptCode(ProtocolMapperModel mappingModel) 
 - 
createpublic static ProtocolMapperModel create(String name, String samlAttributeName, String nameFormat, String friendlyName, String script, boolean singleAttribute) Creates an protocol mapper model for the this script based mapper. This mapper model is meant to be used for testing, as normally such objects are created in a different manner through the keycloak GUI.- Parameters:
- name- The name of the mapper (this has no functional use)
- samlAttributeName- The name of the attribute in the SAML attribute
- nameFormat- can be "basic", "URI reference" or "unspecified"
- friendlyName- a display name, only useful for the keycloak GUI
- script- the javascript to be executed by the mapper
- singleAttribute- If true, all groups will be stored under one attribute with multiple attribute values
- Returns:
- a Protocol Mapper for a group mapping
 
 
- 
 
-