Мой поставщик услуг использует привязку HTTP-Post для отправки запроса в IDP. Мне нужно добавить новые поля в форму. Прямо сейчас я отправляю «SAMLRequest» и «RelayState», но мне также нужно отправить «вариант» и «профиль», это поля, требуемые нашим IDP. Как я могу это сделать с помощью безопасности Spring Saml?Spring SAML - как добавить пользовательские поля в HTTP-запрос SP?
4
A
ответ
6
Вы можете включить дополнительные поля в элемент 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;
}
}
Отлично! Спасибо! – user3754289
Любая идея, как это сделать в приложении Grails? Мне нужно переопределить метод WebSSOProfileImpl.buildReturnAddress. – Newerth
Это выглядит нормально. Как читать атрибут на стороне IDP? –