gpt4 book ai didi

Spring SAML - 如何在 SP HTTP 请求中添加自定义字段?

转载 作者:行者123 更新时间:2023-12-04 23:21:20 25 4
gpt4 key购买 nike

我的服务提供商使用 HTTP-Post 绑定(bind)将请求发送到 IDP。我需要在表单中添加新字段。现在我正在发送“SAMLRequest”和“RelayState”,但我还需要发送“option”和“profile”,这些是我们的 IDP 所需的字段。如何使用 Spring Saml 安全性来实现这一点?

最佳答案

您可以在 Extensions 中包含其他字段SAML 的元素 AuthnRequest信息。为此,您需要重写类 WebSSOProfileImpl并在 securityContext.xml 中配置您的新实现类. Extensions可以像这样构造元素:

package example;

import org.opensaml.common.SAMLException;
import org.opensaml.saml2.common.Extensions;
import org.opensaml.saml2.common.impl.ExtensionsBuilder;
import org.opensaml.saml2.core.AuthnRequest;
import org.opensaml.saml2.metadata.AssertionConsumerService;
import org.opensaml.saml2.metadata.SingleSignOnService;
import org.opensaml.saml2.metadata.provider.MetadataProviderException;
import org.opensaml.xml.schema.XSAny;
import org.opensaml.xml.schema.impl.XSAnyBuilder;
import org.springframework.security.saml.context.SAMLMessageContext;
import org.springframework.security.saml.metadata.MetadataManager;
import org.springframework.security.saml.processor.SAMLProcessor;
import org.springframework.security.saml.websso.WebSSOProfileImpl;
import org.springframework.security.saml.websso.WebSSOProfileOptions;

/**
* Customization of the AuthnRequest generation.
*/
public class WebSSOProfile extends WebSSOProfileImpl {

public WebSSOProfile() {
}

public WebSSOProfile(SAMLProcessor processor, MetadataManager manager) {
super(processor, manager);
}

@Override
protected AuthnRequest getAuthnRequest(SAMLMessageContext context, WebSSOProfileOptions options, AssertionConsumerService assertionConsumer, SingleSignOnService bindingService) throws SAMLException, MetadataProviderException {
AuthnRequest authnRequest = super.getAuthnRequest(context, options, assertionConsumer, bindingService);
authnRequest.setExtensions(buildExtensions());
return authnRequest;
}

protected Extensions buildExtensions() {

XSAny extraElement = new XSAnyBuilder().buildObject("urn:myexample:extraAttribute", "ExtraElement", "myexample");
extraElement.setTextContent("extraValue");

Extensions extensions = new ExtensionsBuilder().buildObject();
extensions.getUnknownXMLObjects().add(extraElement);

return extensions;

}

}

关于Spring SAML - 如何在 SP HTTP 请求中添加自定义字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25630285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com