Spring SAML - 处理断言

时间:2014-10-14 01:16:32

标签: spring-security saml

我们的应用程序在另一个企业应用程序(Parent)的一部分中。我们的应用程序作为父Web应用程序的子应用程序调用。用户在父应用程序上进行身份验证(SSO)。用户点击链接并弹出我们的应用程序。要求是我们处理SAML断言并使用作为断言一部分的属性。我的问题是我需要有完整的春天豆豆,或者如果我只有“webSSOprofileConsumer”对应WebSSOProfileConsumerImpl,就足够了

我们需要处理SAML断言,我们不必担心SSO /身份验证。在Spring SAML集成中可以做到这一点吗?如果是的话。

谢谢, 中号

1 个答案:

答案 0 :(得分:1)

不,你不需要完整的Spring SAML bean。您只能使用OpenSAML - 它足以解析Assertion并提取属性(这似乎是您似乎唯一需要的东西)。

以下代码是将带有SAML消息的XML流转换为SAML对象的示例:

protected T unmarshallMessage(Reader messageStream) throws MessageDecodingException {
    log.debug("Parsing message stream into DOM document");

    try {
        Document messageDoc = getPool().parse(messageStream);
        Element messageElem = messageDoc.getDocumentElement();

        if (log.isTraceEnabled()) {
            log.trace("Unmarshalled message into DOM:\n{}", XMLHelper.nodeToString(messageElem));
        }

        log.debug("Unmarshalling message DOM");
        Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(messageElem);
        if (unmarshaller == null) {
            throw new MessageDecodingException(
                    "Unable to unmarshall message, no unmarshaller registered for message element "
                    + XMLHelper.getNodeQName(messageElem));
        }

        T message = (T) unmarshaller.unmarshall(messageElem);

        log.debug("Message successfully unmarshalled");
        return message;
    } catch (XMLParserException e) {
        log.error("Encountered error parsing message into its DOM representation", e);
        throw new MessageDecodingException("Encountered error parsing message into its DOM representation", e);
    } catch (UnmarshallingException e) {
        log.error("Encountered error unmarshalling message from its DOM representation", e);
        throw new MessageDecodingException("Encountered error unmarshalling message from its DOM representation", e);
    }
}

调用getPool需要返回org.opensaml.xml.parse.ParserPool的实例,例如BasicParserPool

返回的对象将是例如类型为org.opensaml.saml2.core.Responseorg.opensaml.saml2.core.Assertion,您可以在Spring SAML的代码库中找到有关如何使用这些对象的详细信息。

参见例如有关处理属性的详细信息,请SAMLCredential#getAttributeAsStringArray

在初始化应用程序期间调用org.opensaml.DefaultBootstrap.bootstrap()初始化OpenSAML。

相关问题