keycloak-service
公開メンバ関数 | 静的公開メンバ関数 | 静的公開変数類 | 静的関数 | 静的非公開変数類 | 全メンバ一覧
org.keycloak.protocol.saml.mappers.ScriptBasedMapper クラス
org.keycloak.protocol.saml.mappers.ScriptBasedMapper の継承関係図
Inheritance graph
org.keycloak.protocol.saml.mappers.ScriptBasedMapper 連携図
Collaboration graph

公開メンバ関数

List< ProviderConfigProperty > getConfigProperties ()
 
String getId ()
 
String getDisplayType ()
 
String getDisplayCategory ()
 
String getHelpText ()
 
void transformAttributeStatement (AttributeStatementType attributeStatement, ProtocolMapperModel mappingModel, KeycloakSession session, UserSessionModel userSession, AuthenticatedClientSessionModel clientSession)
 
void validateConfig (KeycloakSession session, RealmModel realm, ProtocolMapperContainerModel client, ProtocolMapperModel mapperModel) throws ProtocolMapperConfigException
 
String getProtocol ()
 
void close ()
 
final ProtocolMapper create (KeycloakSession session)
 
void init (Config.Scope config)
 
void postInit (KeycloakSessionFactory factory)
 

静的公開メンバ関数

static ProtocolMapperModel create (String name, String samlAttributeName, String nameFormat, String friendlyName, String script, boolean singleAttribute)
 

静的公開変数類

static final String PROVIDER_ID = "saml-javascript-mapper"
 

静的関数

 [static initializer]
 

静的非公開変数類

static final List< ProviderConfigProperty > configProperties = new ArrayList<>()
 
static final String SINGLE_VALUE_ATTRIBUTE = "single"
 
static final Logger LOGGER = Logger.getLogger(ScriptBasedMapper.class)
 

詳解

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.

著者
Alistair Doswald

関数詳解

◆ [static initializer]()

org.keycloak.protocol.saml.mappers.ScriptBasedMapper.[static initializer] ( )
inlinestaticpackage

◆ close()

void org.keycloak.protocol.saml.mappers.AbstractSAMLProtocolMapper.close ( )
inlineinherited
39  {
40 
41  }

◆ create() [1/2]

final ProtocolMapper org.keycloak.protocol.saml.mappers.AbstractSAMLProtocolMapper.create ( KeycloakSession  session)
inlineinherited
44  {
45  throw new RuntimeException("UNSUPPORTED METHOD");
46  }

◆ create() [2/2]

static ProtocolMapperModel org.keycloak.protocol.saml.mappers.ScriptBasedMapper.create ( String  name,
String  samlAttributeName,
String  nameFormat,
String  friendlyName,
String  script,
boolean  singleAttribute 
)
inlinestatic

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.

引数
nameThe name of the mapper (this has no functional use)
samlAttributeNameThe name of the attribute in the SAML attribute
nameFormatcan be "basic", "URI reference" or "unspecified"
friendlyNamea display name, only useful for the keycloak GUI
scriptthe javascript to be executed by the mapper
singleAttributeIf true, all groups will be stored under one attribute with multiple attribute values
戻り値
a Protocol Mapper for a group mapping
188  {
189  ProtocolMapperModel mapper = AttributeStatementHelper.createAttributeMapper(name, null, samlAttributeName, nameFormat, friendlyName,
190  PROVIDER_ID);
191  Map<String, String> config = mapper.getConfig();
192  config.put(ProviderConfigProperty.SCRIPT_TYPE, script);
193  config.put(SINGLE_VALUE_ATTRIBUTE, Boolean.toString(singleAttribute));
194  return mapper;
195  }
static final String SINGLE_VALUE_ATTRIBUTE
Definition: ScriptBasedMapper.java:27
static final String PROVIDER_ID
Definition: ScriptBasedMapper.java:26

◆ getConfigProperties()

List<ProviderConfigProperty> org.keycloak.protocol.saml.mappers.ScriptBasedMapper.getConfigProperties ( )
inline
72  {
73  return configProperties;
74  }
static final List< ProviderConfigProperty > configProperties
Definition: ScriptBasedMapper.java:25

◆ getDisplayCategory()

String org.keycloak.protocol.saml.mappers.ScriptBasedMapper.getDisplayCategory ( )
inline
86  {
87  return AttributeStatementHelper.ATTRIBUTE_STATEMENT_CATEGORY;
88  }

◆ getDisplayType()

String org.keycloak.protocol.saml.mappers.ScriptBasedMapper.getDisplayType ( )
inline
81  {
82  return "Javascript Mapper";
83  }

◆ getHelpText()

String org.keycloak.protocol.saml.mappers.ScriptBasedMapper.getHelpText ( )
inline
91  {
92  return "Evaluates a JavaScript function to produce an attribute value based on context information.";
93  }

◆ getId()

String org.keycloak.protocol.saml.mappers.ScriptBasedMapper.getId ( )
inline
76  {
77  return PROVIDER_ID;
78  }
static final String PROVIDER_ID
Definition: ScriptBasedMapper.java:26

◆ getProtocol()

String org.keycloak.protocol.saml.mappers.AbstractSAMLProtocolMapper.getProtocol ( )
inlineinherited
34  {
35  return SamlProtocol.LOGIN_PROTOCOL;
36  }

◆ init()

void org.keycloak.protocol.saml.mappers.AbstractSAMLProtocolMapper.init ( Config.Scope  config)
inlineinherited
49  {
50  }

◆ postInit()

void org.keycloak.protocol.saml.mappers.AbstractSAMLProtocolMapper.postInit ( KeycloakSessionFactory  factory)
inlineinherited
53  {
54 
55  }

◆ transformAttributeStatement()

void org.keycloak.protocol.saml.mappers.ScriptBasedMapper.transformAttributeStatement ( AttributeStatementType  attributeStatement,
ProtocolMapperModel  mappingModel,
KeycloakSession  session,
UserSessionModel  userSession,
AuthenticatedClientSessionModel  clientSession 
)
inline

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

引数
attributeStatementThe attribute statements to be added to a token
mappingModelThe mapping model reflects the values that are actually input in the GUI
sessionThe current session
userSessionThe current user session
clientSessionThe current client session

org.keycloak.protocol.saml.mappers.SAMLAttributeStatementMapperを実装しています。

111  {
112  UserModel user = userSession.getUser();
113  String scriptSource = mappingModel.getConfig().get(ProviderConfigProperty.SCRIPT_TYPE);
114  RealmModel realm = userSession.getRealm();
115 
116  String single = mappingModel.getConfig().get(SINGLE_VALUE_ATTRIBUTE);
117  boolean singleAttribute = Boolean.parseBoolean(single);
118 
119  ScriptingProvider scripting = session.getProvider(ScriptingProvider.class);
120  ScriptModel scriptModel = scripting.createScript(realm.getId(), ScriptModel.TEXT_JAVASCRIPT, "attribute-mapper-script_" + mappingModel.getName(), scriptSource, null);
121 
122  EvaluatableScriptAdapter script = scripting.prepareEvaluatableScript(scriptModel);
123  Object attributeValue;
124  try {
125  attributeValue = script.eval((bindings) -> {
126  bindings.put("user", user);
127  bindings.put("realm", realm);
128  bindings.put("clientSession", clientSession);
129  bindings.put("userSession", userSession);
130  bindings.put("keycloakSession", session);
131  });
132  //If the result is a an array or is iterable, get all values
133  if (attributeValue.getClass().isArray()){
134  attributeValue = Arrays.asList((Object[])attributeValue);
135  }
136  if (attributeValue instanceof Iterable) {
137  if (singleAttribute) {
138  AttributeType singleAttributeType = AttributeStatementHelper.createAttributeType(mappingModel);
139  attributeStatement.addAttribute(new AttributeStatementType.ASTChoiceType(singleAttributeType));
140  for (Object value : (Iterable)attributeValue) {
141  singleAttributeType.addAttributeValue(value);
142  }
143  } else {
144  for (Object value : (Iterable)attributeValue) {
145  AttributeStatementHelper.addAttribute(attributeStatement, mappingModel, value.toString());
146  }
147  }
148  } else {
149  // single value case
150  AttributeStatementHelper.addAttribute(attributeStatement, mappingModel, attributeValue.toString());
151  }
152  } catch (Exception ex) {
153  LOGGER.error("Error during execution of ProtocolMapper script", ex);
154  AttributeStatementHelper.addAttribute(attributeStatement, mappingModel, null);
155  }
156  }
static final Logger LOGGER
Definition: ScriptBasedMapper.java:28
static final String SINGLE_VALUE_ATTRIBUTE
Definition: ScriptBasedMapper.java:27

◆ validateConfig()

void org.keycloak.protocol.saml.mappers.ScriptBasedMapper.validateConfig ( KeycloakSession  session,
RealmModel  realm,
ProtocolMapperContainerModel  client,
ProtocolMapperModel  mapperModel 
) throws ProtocolMapperConfigException
inline
159  {
160 
161  String scriptCode = mapperModel.getConfig().get(ProviderConfigProperty.SCRIPT_TYPE);
162  if (scriptCode == null) {
163  return;
164  }
165 
166  ScriptingProvider scripting = session.getProvider(ScriptingProvider.class);
167  ScriptModel scriptModel = scripting.createScript(realm.getId(), ScriptModel.TEXT_JAVASCRIPT, mapperModel.getName() + "-script", scriptCode, "");
168 
169  try {
170  scripting.prepareEvaluatableScript(scriptModel);
171  } catch (ScriptCompilationException ex) {
172  throw new ProtocolMapperConfigException("error", "{0}", ex.getMessage());
173  }
174  }

メンバ詳解

◆ configProperties

final List<ProviderConfigProperty> org.keycloak.protocol.saml.mappers.ScriptBasedMapper.configProperties = new ArrayList<>()
staticprivate

◆ LOGGER

final Logger org.keycloak.protocol.saml.mappers.ScriptBasedMapper.LOGGER = Logger.getLogger(ScriptBasedMapper.class)
staticprivate

◆ PROVIDER_ID

final String org.keycloak.protocol.saml.mappers.ScriptBasedMapper.PROVIDER_ID = "saml-javascript-mapper"
static

◆ SINGLE_VALUE_ATTRIBUTE

final String org.keycloak.protocol.saml.mappers.ScriptBasedMapper.SINGLE_VALUE_ATTRIBUTE = "single"
staticprivate

このクラス詳解は次のファイルから抽出されました: