X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=shibsp%2Fattribute%2Fresolver%2Fimpl%2FDelegationAttributeExtractor.cpp;h=5e3a3dba9fc8ae697479876c5a2813f386db84fd;hb=c51bfd77603cf0ddb0b5e374c35586a8435895d6;hp=3f410cd830931a1fcd8eff7626a1d1a740ce5be2;hpb=44efbaf72f94cbaa256fb044aa2a10d47736721b;p=shibboleth%2Fcpp-sp.git diff --git a/shibsp/attribute/resolver/impl/DelegationAttributeExtractor.cpp b/shibsp/attribute/resolver/impl/DelegationAttributeExtractor.cpp index 3f410cd..5e3a3db 100644 --- a/shibsp/attribute/resolver/impl/DelegationAttributeExtractor.cpp +++ b/shibsp/attribute/resolver/impl/DelegationAttributeExtractor.cpp @@ -1,17 +1,21 @@ -/* - * Copyright 2009-2010 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. */ /** @@ -27,6 +31,8 @@ #include "attribute/resolver/AttributeExtractor.h" #include "util/SPConstants.h" +#include +#include #include #include #include @@ -39,6 +45,7 @@ using namespace shibsp; using namespace opensaml::saml2md; using namespace opensaml; using namespace xmltooling; +using namespace boost; using namespace std; namespace shibsp { @@ -100,7 +107,7 @@ void DelegationExtractor::extractAttributes( if (!assertion || !assertion->getConditions()) return; - Category& log = Category::getInstance(SHIBSP_LOGCAT".AttributeExtractor.Delegation"); + Category& log = Category::getInstance(SHIBSP_LOGCAT ".AttributeExtractor.Delegation"); const vector& conditions = const_cast(assertion->getConditions())->getConditions(); for (vector::const_iterator c = conditions.begin(); c != conditions.end(); ++c) { @@ -109,14 +116,16 @@ void DelegationExtractor::extractAttributes( auto_ptr attr(new ExtensibleAttribute(vector(1,m_attributeId), m_formatter.c_str())); const vector& dels = drt->getDelegates(); - for (vector::const_iterator d = dels.begin(); d != dels.end(); ++d) { - if ((*d)->getBaseID()) { + for (indirect_iterator::const_iterator> d = make_indirect_iterator(dels.begin()); + d != make_indirect_iterator(dels.end()); ++d) { + if (d->getBaseID()) { log.error("delegate identified by saml:BaseID cannot be processed into an attribute value"); continue; } saml2::NameID* n = nullptr; - if ((*d)->getEncryptedID()) { + boost::shared_ptr namewrapper; + if (d->getEncryptedID()) { CredentialResolver* cr = application.getCredentialResolver(); if (!cr) { log.warn("found encrypted Delegate, but no CredentialResolver was available"); @@ -129,61 +138,56 @@ void DelegationExtractor::extractAttributes( Locker credlocker(cr); if (issuer) { MetadataCredentialCriteria mcc(*issuer); - auto_ptr decrypted((*d)->getEncryptedID()->decrypt(*cr, recipient, &mcc)); - n = dynamic_cast(decrypted.release()); + boost::shared_ptr decrypted(d->getEncryptedID()->decrypt(*cr, recipient, &mcc)); + namewrapper = dynamic_pointer_cast(decrypted); + n = namewrapper.get(); } else { - auto_ptr decrypted((*d)->getEncryptedID()->decrypt(*cr, recipient)); - n = dynamic_cast(decrypted.release()); + boost::shared_ptr decrypted(d->getEncryptedID()->decrypt(*cr, recipient)); + namewrapper = dynamic_pointer_cast(decrypted); + n = namewrapper.get(); } if (n && log.isDebugEnabled()) log.debugStream() << "decrypted Delegate: " << *n << logging::eol; } - catch (exception& ex) { + catch (std::exception& ex) { log.error("caught exception decrypting Delegate: %s", ex.what()); } } else { - n = (*d)->getNameID(); + n = d->getNameID(); } if (n) { DDF val = DDF(nullptr).structure(); - if ((*d)->getConfirmationMethod()) { - auto_ptr_char temp((*d)->getConfirmationMethod()); + if (d->getConfirmationMethod()) { + auto_ptr_char temp(d->getConfirmationMethod()); val.addmember("ConfirmationMethod").string(temp.get()); } - if ((*d)->getDelegationInstant()) { - auto_ptr_char temp((*d)->getDelegationInstant()->getRawData()); + if (d->getDelegationInstant()) { + auto_ptr_char temp(d->getDelegationInstant()->getRawData()); val.addmember("DelegationInstant").string(temp.get()); } auto_arrayptr name(toUTF8(n->getName())); if (name.get() && *name.get()) { val.addmember("Name").string(name.get()); - char* str = toUTF8(n->getFormat()); - if (str && *str) - val.addmember("Format").string(str); - delete[] str; - - str = toUTF8(n->getNameQualifier()); - if (str && *str) - val.addmember("NameQualifier").string(str); - delete[] str; - - str = toUTF8(n->getSPNameQualifier()); - if (str && *str) - val.addmember("SPNameQualifier").string(str); - delete[] str; - - str = toUTF8(n->getSPProvidedID()); - if (str && *str) - val.addmember("SPProvidedID").string(str); - delete[] str; - } + auto_arrayptr format(toUTF8(n->getFormat())); + if (format.get()) + val.addmember("Format").string(format.get()); + + auto_arrayptr nq(toUTF8(n->getNameQualifier())); + if (nq.get()) + val.addmember("NameQualifier").string(nq.get()); - if (n != (*d)->getNameID()) - delete n; + auto_arrayptr spnq(toUTF8(n->getSPNameQualifier())); + if (spnq.get()) + val.addmember("SPNameQualifier").string(spnq.get()); + + auto_arrayptr sppid(toUTF8(n->getSPProvidedID())); + if (sppid.get()) + val.addmember("SPProvidedID").string(sppid.get()); + } if (val.integer()) attr->getValues().add(val); @@ -192,7 +196,8 @@ void DelegationExtractor::extractAttributes( } } - attributes.push_back(attr.release()); + attributes.push_back(attr.get()); + attr.release(); } } }