in saml-authentication-server/src/main/java/jetbrains/buildServer/auth/saml/plugin/SamlAuthenticationScheme.java [216:258]
private String getAttribute(@NotNull Auth saml, @NotNull SamlAttributeMappingSettings attributeMappingSettings) {
switch (attributeMappingSettings.getMappingType()) {
case SamlAttributeMappingSettings.TYPE_NONE: return "";
case SamlAttributeMappingSettings.TYPE_NAME_ID: return saml.getNameId();
case SamlAttributeMappingSettings.TYPE_OTHER:
if (StringUtil.isEmpty(attributeMappingSettings.getCustomAttributeName())) {
LOG.warn("Custom attribute name is not set");
return "";
}
String attributeName = attributeMappingSettings.getCustomAttributeName();
var attributeValue = saml.getAttribute(attributeName);
if (attributeValue == null) {
LOG.warn(String.format("Attribute '%s' not found in SAML response", attributeName));
return "";
}
if (attributeValue.size() == 0) return "";
return String.join(", ", attributeValue);
case SamlAttributeMappingSettings.TYPE_EXPRESSION:
if (StringUtil.isEmpty(attributeMappingSettings.getCustomAttributeName())) {
LOG.warn("Expression is not set");
return "";
}
var expression = attributeMappingSettings.getCustomAttributeName();
var executor = new SpelExpressionExecutor();
var context = new SpelExpressionContext(saml);
try {
String result = executor.evaluate(expression, context);
if (StringUtils.isEmpty(result)) {
LOG.warn(String.format("Expression %s evaluated to empty value.", expression));
}
return result;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
LOG.warn(String.format("Available properties are: %s", context.getRootObjectAsMap().keySet().stream().collect(Collectors.joining(", "))));
return "";
}
default:
LOG.warn(String.format("Unknown mapping type: %s", attributeMappingSettings.getMappingType()));
return "";
}
}