java - Spring saml 2.0 中的用户配置

标签 java spring single-sign-on saml

我曾从事 Spring saml 应用程序的工作。现在我需要在我的项目中进行用户配置。请就如何实现用户配置 SPRING SAML 应用程序(如 salesforce 中的即时配置)向我提供建议。

谢谢

最佳答案

从 SAML 响应中获取用户信息 - 在 SSO 中,我们获取 SAML(安全断言标记语言)请求,其中包含用户的标识符(外部 ID 或电子邮件地址),以了解哪个用户正在尝试登录。我们需要要求客户 SSO 管理员至少添加以下突出显示的属性/安全声明,以便我们能够创建用户 JIT。

 <Attribute 
    Name=”http://schemas.xmlsoap.org/ws/2005/05/identity/claims/firstname”&gt;
    <AttributeValue>Anuj</AttributeValue>
    </Attribute>
    <Attribute 
    Name=”http://schemas.xmlsoap.org/ws/2005/05/identity/claims/lastname”&gt;
    <AttributeValue>Singh</AttributeValue>
    </Attribute>
    <Attribute 
    Name=”http://schemas.xmlsoap.org/ws/2005/05/identity/claims/useremail”&gt;
    <AttributeValue>anujsingh@gmail.com</AttributeValue>
    </Attribute>
    <Attribute 
   Name=”http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name”&gt;
   <AttributeValue>anujsingh@gmail.com</AttributeValue>
   </Attribute>
   <Attribute 
  Name=”http://schemas.xmlsoap.org/ws/2005/05/identity/claims/propertyIdentifie 
 r”&gt;
   <AttributeValue>ABC</AttributeValue>
   </Attribute>
   <Attribute 

  Name=”http://schemas.xmlsoap.org/ws/2005/05/identity/claims/userpositionid”&gt;
   <AttributeValue>144</AttributeValue>
   </Attribute>
   </Attribute>

现在您可以从 saml 响应中提取所有用户信息 –

SAMLCredential credential = (SAMLCredential) 
SecurityContextHolder.getContext().getAuthentication().getCredentials();

String 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.
}
}
}

关于java - Spring saml 2.0 中的用户配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51103446/

相关文章:

java - sun.net.www.protocol.https.HttpsURLConnectionImpl 无法转换为 sun.net.www.protocol.http.HttpURLConnection

java - 使用 JPQL 计算关联对象的正确方法

java - spring - 从 application.properties 文件中读取环境变量

certificate - SAML 签名证书 - CA 签名与自签名

asp.net - 通过身份验证 - IIS 和 dotNet

java - 如何修复在 Chrome 73 中使用 sendKeys(fileAbsolutePath) 到 &lt;input type ="file"> 时的文件上传错误?

java - 返回数组中整数的第一个数字

java - 使用 Spring Data REST 实现更新深度嵌套 JSON 结构的最佳方法是什么?

java - MongoDB 身份验证和 Apache Camel 的问题

iframe - 拒绝在帧中显示 '',因为它使用 Looker 将 'X-Frame-Options' 设置为 'sameorigin'