Получение информации о пользователе из ответа SAML. В системе единого входа мы получаем запрос SAML (язык разметки утверждений безопасности), который содержит идентификатор пользователя (внешний идентификатор или адрес электронной почты), чтобы узнать, какой пользователь пытается войти в систему. Мы должны попросить администратора SSO клиента как минимум добавить ниже выделенные атрибуты / утверждения безопасности, чтобы позволить нам создавать пользователей JIT.
<Attribute
Name=”http://schemas.xmlsoap.org/ws/2005/05/identity/claims/firstname”>
<AttributeValue>Anuj</AttributeValue>
</Attribute>
<Attribute
Name=”http://schemas.xmlsoap.org/ws/2005/05/identity/claims/lastname”>
<AttributeValue>Singh</AttributeValue>
</Attribute>
<Attribute
Name=”http://schemas.xmlsoap.org/ws/2005/05/identity/claims/useremail”>
<AttributeValue>anujsingh@gmail.com</AttributeValue>
</Attribute>
<Attribute
Name=”http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name”>
<AttributeValue>anujsingh@gmail.com</AttributeValue>
</Attribute>
<Attribute
Name=”http://schemas.xmlsoap.org/ws/2005/05/identity/claims/propertyIdentifie
r”>
<AttributeValue>ABC</AttributeValue>
</Attribute>
<Attribute
Name=”http://schemas.xmlsoap.org/ws/2005/05/identity/claims/userpositionid”>
<AttributeValue>144</AttributeValue>
</Attribute>
</Attribute>
Теперь вы можете извлечь всю информацию пользователя из ответа saml -
SAMLCredential credential = (SAMLCredential)
SecurityContextHolder.getContext().getAuthentication().getCredentials();
Строка userEmail = SpringSAMLUtil.encrypt (credential.getNameID (). GetValue ());
Вы можете получить информацию о пользователе из учетных данных, как показано ниже -
Список атрибутов = credential.getAttributes ();
getAttributes () возвращает список всех атрибутов, которые содержатся в ответе SAML.
После этого вы можете извлекать информацию о пользователях один за другим -
for (Attribute attribute : attributes) {
if ((attribute.getAttributeValues() != null &&
attribute.getAttributeValues().size() > 0)) {
List<XMLObject> xmlValues = attribute.getAttributeValues();
for (XMLObject attributeValue : xmlValues) {
value = ((XSAnyImpl) attributeValue).getTextContent();
// here you can find all attributes (value) one by one as given sequence
in SAML response.
}
}
}