-/*
- * 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.
*/
/**
#include "attribute/resolver/AttributeExtractor.h"
#include "util/SPConstants.h"
+#include <boost/shared_ptr.hpp>
+#include <boost/iterator/indirect_iterator.hpp>
#include <saml/saml2/core/Assertions.h>
#include <saml/saml2/metadata/Metadata.h>
#include <saml/saml2/metadata/MetadataCredentialCriteria.h>
using namespace opensaml::saml2md;
using namespace opensaml;
using namespace xmltooling;
+using namespace boost;
using namespace std;
namespace shibsp {
if (!assertion || !assertion->getConditions())
return;
- Category& log = Category::getInstance(SHIBSP_LOGCAT".AttributeExtractor.Delegation");
+ Category& log = Category::getInstance(SHIBSP_LOGCAT ".AttributeExtractor.Delegation");
const vector<saml2::Condition*>& conditions = const_cast<const saml2::Conditions*>(assertion->getConditions())->getConditions();
for (vector<saml2::Condition*>::const_iterator c = conditions.begin(); c != conditions.end(); ++c) {
auto_ptr<ExtensibleAttribute> attr(new ExtensibleAttribute(vector<string>(1,m_attributeId), m_formatter.c_str()));
const vector<saml2::Delegate*>& dels = drt->getDelegates();
- for (vector<saml2::Delegate*>::const_iterator d = dels.begin(); d != dels.end(); ++d) {
- if ((*d)->getBaseID()) {
+ for (indirect_iterator<vector<saml2::Delegate*>::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<saml2::NameID> namewrapper;
+ if (d->getEncryptedID()) {
CredentialResolver* cr = application.getCredentialResolver();
if (!cr) {
log.warn("found encrypted Delegate, but no CredentialResolver was available");
Locker credlocker(cr);
if (issuer) {
MetadataCredentialCriteria mcc(*issuer);
- auto_ptr<XMLObject> decrypted((*d)->getEncryptedID()->decrypt(*cr, recipient, &mcc));
- n = dynamic_cast<saml2::NameID*>(decrypted.release());
+ boost::shared_ptr<XMLObject> decrypted(d->getEncryptedID()->decrypt(*cr, recipient, &mcc));
+ namewrapper = dynamic_pointer_cast<saml2::NameID>(decrypted);
+ n = namewrapper.get();
}
else {
- auto_ptr<XMLObject> decrypted((*d)->getEncryptedID()->decrypt(*cr, recipient));
- n = dynamic_cast<saml2::NameID*>(decrypted.release());
+ boost::shared_ptr<XMLObject> decrypted(d->getEncryptedID()->decrypt(*cr, recipient));
+ namewrapper = dynamic_pointer_cast<saml2::NameID>(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<char> 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<char> format(toUTF8(n->getFormat()));
+ if (format.get())
+ val.addmember("Format").string(format.get());
+
+ auto_arrayptr<char> nq(toUTF8(n->getNameQualifier()));
+ if (nq.get())
+ val.addmember("NameQualifier").string(nq.get());
- if (n != (*d)->getNameID())
- delete n;
+ auto_arrayptr<char> spnq(toUTF8(n->getSPNameQualifier()));
+ if (spnq.get())
+ val.addmember("SPNameQualifier").string(spnq.get());
+
+ auto_arrayptr<char> sppid(toUTF8(n->getSPProvidedID()));
+ if (sppid.get())
+ val.addmember("SPProvidedID").string(sppid.get());
+ }
if (val.integer())
attr->getValues().add(val);
}
}
- attributes.push_back(attr.release());
+ attributes.push_back(attr.get());
+ attr.release();
}
}
}