X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=saml%2Fsaml2%2Fbinding%2Fimpl%2FSAML2ArtifactDecoder.cpp;h=46ec815c4e089ac18b07649a203253f16bbabd2f;hb=1462057b3b9ae7e165d34d988e30b14c213672ca;hp=081787f6e2cddb5e596f4dfcc4624159435ba888;hpb=003e73203da5cdf8c3d001a75a56b9e45ef6465b;p=shibboleth%2Fcpp-opensaml.git diff --git a/saml/saml2/binding/impl/SAML2ArtifactDecoder.cpp b/saml/saml2/binding/impl/SAML2ArtifactDecoder.cpp index 081787f..46ec815 100644 --- a/saml/saml2/binding/impl/SAML2ArtifactDecoder.cpp +++ b/saml/saml2/binding/impl/SAML2ArtifactDecoder.cpp @@ -1,34 +1,41 @@ -/* - * Copyright 2001-2007 Internet2 +/** + * Licensed to the University Corporation for Advanced Internet + * Development, Inc. (UCAID) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * UCAID licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. */ /** * SAML2ArtifactDecoder.cpp * - * SAML 2.0 Artifact binding message decoder + * SAML 2.0 Artifact binding message decoder. */ #include "internal.h" #include "exceptions.h" +#include "binding/SecurityPolicy.h" #include "saml2/binding/SAML2Artifact.h" #include "saml2/binding/SAML2MessageDecoder.h" #include "saml2/core/Protocols.h" #include "saml2/metadata/Metadata.h" #include "saml2/metadata/MetadataProvider.h" +#include #include +#include #include #include #include @@ -39,6 +46,7 @@ using namespace opensaml::saml2; using namespace opensaml; using namespace xmltooling::logging; using namespace xmltooling; +using namespace boost; using namespace std; namespace opensaml { @@ -72,7 +80,7 @@ XMLObject* SAML2ArtifactDecoder::decode( #ifdef _DEBUG xmltooling::NDC ndc("decode"); #endif - Category& log = Category::getInstance(SAML_LOGCAT".MessageDecoder.SAML2Artifact"); + Category& log = Category::getInstance(SAML_LOGCAT ".MessageDecoder.SAML2Artifact"); log.debug("validating input"); const HTTPRequest* httpRequest=dynamic_cast(&genericRequest); @@ -89,14 +97,14 @@ XMLObject* SAML2ArtifactDecoder::decode( throw BindingException("Artifact binding requires ArtifactResolver and MetadataProvider implementations be supplied."); // Import the artifact. - SAMLArtifact* artifact=NULL; + scoped_ptr artifact; try { log.debug("processing encoded artifact (%s)", SAMLart); // Check replay. ReplayCache* replayCache = XMLToolingConfig::getConfig().getReplayCache(); if (replayCache) { - if (!replayCache->check("SAML2Artifact", SAMLart, time(NULL) + (2*XMLToolingConfig::getConfig().clock_skew_secs))) { + if (!replayCache->check("SAML2Artifact", SAMLart, time(nullptr) + (2*XMLToolingConfig::getConfig().clock_skew_secs))) { log.error("replay detected of artifact (%s)", SAMLart); throw BindingException("Rejecting replayed artifact ($1).", params(1,SAMLart)); } @@ -104,7 +112,7 @@ XMLObject* SAML2ArtifactDecoder::decode( else log.warn("replay cache was not provided, this is a serious security risk!"); - artifact = SAMLArtifact::parse(SAMLart); + artifact.reset(SAMLArtifact::parse(SAMLart)); } catch (ArtifactException&) { log.error("error parsing artifact (%s)", SAMLart); @@ -112,15 +120,15 @@ XMLObject* SAML2ArtifactDecoder::decode( } // Check the type. - auto_ptr artifact2(dynamic_cast(artifact)); - if (!artifact2.get()) { + SAML2Artifact* artifact2 = dynamic_cast(artifact.get()); + if (!artifact2) { + log.error("wrong artifact type"); throw BindingException("Artifact binding requires SAML 2.0 artifact."); - delete artifact; } log.debug("attempting to determine source of artifact..."); MetadataProvider::Criteria& mc = policy.getMetadataProviderCriteria(); - mc.artifact = artifact; + mc.artifact = artifact.get(); mc.role = policy.getRole(); mc.protocol = samlconstants::SAML20P_NS; pair provider=policy.getMetadataProvider()->getEntityDescriptor(mc); @@ -147,7 +155,7 @@ XMLObject* SAML2ArtifactDecoder::decode( log.debug("calling ArtifactResolver..."); auto_ptr response( - m_artifactResolver->resolve(*(artifact2.get()), dynamic_cast(*provider.second), policy) + m_artifactResolver->resolve(*artifact2, dynamic_cast(*provider.second), policy) ); // The policy should be enforced against the ArtifactResponse by the resolve step. @@ -156,8 +164,10 @@ XMLObject* SAML2ArtifactDecoder::decode( // Now extract details from the payload and check that message. XMLObject* payload = response->getPayload(); - if (!payload) + if (!payload) { + log.error("ArtifactResponse message did not contain a protocol message"); throw BindingException("ArtifactResponse message did not contain a protocol message."); + } extractMessageDetails(*payload, genericRequest, samlconstants::SAML20P_NS, policy); policy.evaluate(*payload, &genericRequest);