# include "Application.h"
# include "ServiceProvider.h"
# include "SessionCache.h"
-# include "attribute/Attribute.h"
-# include "attribute/filtering/AttributeFilter.h"
-# include "attribute/filtering/BasicFilteringContext.h"
-# include "attribute/resolver/AttributeExtractor.h"
# include "attribute/resolver/ResolutionContext.h"
# include <saml/saml2/core/Protocols.h>
# include <saml/saml2/profile/BrowserSSOProfileValidator.h>
using namespace shibsp;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
namespace shibsp {
{
public:
SAML2Consumer(const DOMElement* e, const char* appId)
- : AssertionConsumerService(e, appId, Category::getInstance(SHIBSP_LOGCAT".SAML2SSO")) {
+ : AssertionConsumerService(e, appId, Category::getInstance(SHIBSP_LOGCAT".SSO.SAML2")) {
}
virtual ~SAML2Consumer() {}
// Remember whether we already established trust.
// None of the SAML 2 bindings require security at the protocol layer.
- bool alreadySecured = policy.isSecure();
+ bool alreadySecured = policy.isAuthenticated();
// Check for errors...this will throw if it's not a successful message.
checkError(&xmlObject);
try {
// We clear the security flag, so we can tell whether the token was secured on its own.
- policy.setSecure(false);
-
- // Run the policy over the assertion. Handles issuer consistency, replay, freshness,
- // and signature verification, assuming the relevant rules are configured.
+ policy.setAuthenticated(false);
+ policy.reset(true);
+
+ // Extract message bits and re-verify Issuer information.
+ extractMessageDetails(*(*a), samlconstants::SAML20P_NS, policy);
+
+ // Run the policy over the assertion. Handles replay, freshness, and
+ // signature verification, assuming the relevant rules are configured.
policy.evaluate(*(*a));
// If no security is in place now, we kick it.
- if (!alreadySecured && !policy.isSecure()) {
+ if (!alreadySecured && !policy.isAuthenticated()) {
m_log.warn("unable to establish security of assertion");
badtokens.push_back(*a);
continue;
try {
// We clear the security flag, so we can tell whether the token was secured on its own.
- policy.setSecure(false);
-
- // Run the policy over the assertion. Handles issuer consistency, replay, freshness,
- // and signature verification, assuming the relevant rules are configured.
+ policy.setAuthenticated(false);
+ policy.reset(true);
+
+ // Extract message bits and re-verify Issuer information.
+ extractMessageDetails(*decrypted, samlconstants::SAML20P_NS, policy);
+
+ // Run the policy over the assertion. Handles replay, freshness, and
+ // signature verification, assuming the relevant rules are configured.
// We have to marshall the object first to ensure signatures can be checked.
+ if (!decrypted->getDOM())
+ decrypted->marshall();
policy.evaluate(*decrypted);
// If no security is in place now, we kick it.
- if (!alreadySecured && !policy.isSecure()) {
+ if (!alreadySecured && !policy.isAuthenticated()) {
m_log.warn("unable to establish security of assertion");
badtokens.push_back(decrypted);
continue;
else
sessionExp = min(sessionExp, now + lifetime.second); // Use the lowest.
- multimap<string,Attribute*> resolvedAttributes;
- AttributeExtractor* extractor = application.getAttributeExtractor();
- if (extractor) {
- m_log.debug("extracting pushed attributes...");
- Locker extlocker(extractor);
- try {
- extractor->extractAttributes(application, policy.getIssuerMetadata(), *ssoName, resolvedAttributes);
- }
- catch (exception& ex) {
- m_log.error("caught exception extracting attributes: %s", ex.what());
- }
- for (vector<const opensaml::Assertion*>::const_iterator t = tokens.begin(); t!=tokens.end(); ++t) {
- try {
- extractor->extractAttributes(application, policy.getIssuerMetadata(), *(*t), resolvedAttributes);
- }
- catch (exception& ex) {
- m_log.error("caught exception extracting attributes: %s", ex.what());
- }
- }
- }
-
const AuthnContext* authnContext = ssoStatement->getAuthnContext();
- AttributeFilter* filter = application.getAttributeFilter();
- if (filter && !resolvedAttributes.empty()) {
- BasicFilteringContext fc(
- application,
- resolvedAttributes,
- policy.getIssuerMetadata(),
- (authnContext && authnContext->getAuthnContextClassRef()) ? authnContext->getAuthnContextClassRef()->getReference() : NULL,
- (authnContext && authnContext->getAuthnContextDeclRef()) ? authnContext->getAuthnContextDeclRef()->getReference() : NULL
- );
- Locker filtlocker(filter);
- try {
- filter->filterAttributes(fc, resolvedAttributes);
- }
- catch (exception& ex) {
- m_log.error("caught exception filtering attributes: %s", ex.what());
- m_log.error("dumping extracted attributes due to filtering exception");
- for_each(resolvedAttributes.begin(), resolvedAttributes.end(), cleanup_pair<string,shibsp::Attribute>());
- resolvedAttributes.clear();
- }
- }
-
try {
- const EntityDescriptor* issuerMetadata =
- policy.getIssuerMetadata() ? dynamic_cast<const EntityDescriptor*>(policy.getIssuerMetadata()->getParent()) : NULL;
+ // The context will handle deleting attributes and new tokens.
auto_ptr<ResolutionContext> ctx(
resolveAttributes(
application,
- issuerMetadata,
+ policy.getIssuerMetadata(),
samlconstants::SAML20P_NS,
+ NULL,
ssoName,
(authnContext && authnContext->getAuthnContextClassRef()) ? authnContext->getAuthnContextClassRef()->getReference() : NULL,
(authnContext && authnContext->getAuthnContextDeclRef()) ? authnContext->getAuthnContextDeclRef()->getReference() : NULL,
- &tokens,
- &resolvedAttributes
+ &tokens
)
);
if (ctx.get()) {
// Copy over any new tokens, but leave them in the context for cleanup.
tokens.insert(tokens.end(), ctx->getResolvedAssertions().begin(), ctx->getResolvedAssertions().end());
-
- // Copy over new attributes, and transfer ownership.
- resolvedAttributes.insert(ctx->getResolvedAttributes().begin(), ctx->getResolvedAttributes().end());
- ctx->getResolvedAttributes().clear();
}
// Now merge in bad tokens for caching.
sessionExp,
application,
httpRequest.getRemoteAddr().c_str(),
- issuerMetadata,
+ policy.getIssuerMetadata() ? dynamic_cast<const EntityDescriptor*>(policy.getIssuerMetadata()->getParent()) : NULL,
samlconstants::SAML20P_NS,
ssoName,
ssoStatement->getAuthnInstant() ? ssoStatement->getAuthnInstant()->getRawData() : NULL,
(authnContext && authnContext->getAuthnContextClassRef()) ? authnContext->getAuthnContextClassRef()->getReference() : NULL,
(authnContext && authnContext->getAuthnContextDeclRef()) ? authnContext->getAuthnContextDeclRef()->getReference() : NULL,
&tokens,
- &resolvedAttributes
+ ctx.get() ? &ctx->getResolvedAttributes() : NULL
);
- resolvedAttributes.clear(); // Attributes are owned by cache now.
if (ownedName)
delete ssoName;
for_each(ownedtokens.begin(), ownedtokens.end(), xmltooling::cleanup<saml2::Assertion>());
- for_each(resolvedAttributes.begin(), resolvedAttributes.end(), cleanup_pair<string,Attribute>());
return key;
}
catch (exception&) {
if (ownedName)
delete ssoName;
for_each(ownedtokens.begin(), ownedtokens.end(), xmltooling::cleanup<saml2::Assertion>());
- for_each(resolvedAttributes.begin(), resolvedAttributes.end(), cleanup_pair<string,Attribute>());
throw;
}
}