* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-/*
- * Copyright 2001-2009 Internet2
- *
- * 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
- *
- * 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.
- */
-#include <gssapi/gssapi.h>
-#include <gssapi/gssapi_ext.h>
-#include "util.h"
-
-#include <shibsp/Application.h>
-#include <shibsp/exceptions.h>
-#include <shibsp/SPConfig.h>
-#include <shibsp/ServiceProvider.h>
-#include <shibsp/attribute/Attribute.h>
-#include <shibsp/attribute/SimpleAttribute.h>
-#include <shibsp/attribute/resolver/ResolutionContext.h>
-#include <shibsp/handler/AssertionConsumerService.h>
-#include <shibsp/metadata/MetadataProviderCriteria.h>
-#include <shibsp/util/SPConstants.h>
-
-#include <saml/saml1/core/Assertions.h>
-#include <saml/saml2/core/Assertions.h>
-#include <saml/saml2/metadata/Metadata.h>
+#include "gssapiP_eap.h"
+
+#include <sstream>
+
#include <xercesc/util/XMLUniDefs.hpp>
-#include <xmltooling/XMLToolingConfig.h>
+#include <xmltooling/XMLToolingConfig.h>
#include <xmltooling/util/XMLHelper.h>
-using namespace shibsp;
+#include <saml/saml1/core/Assertions.h>
+#include <saml/saml2/core/Assertions.h>
+#include <saml/saml2/metadata/Metadata.h>
+
+using namespace xmltooling;
using namespace opensaml::saml2md;
using namespace opensaml;
-using namespace xmltooling::logging;
-using namespace xmltooling;
using namespace xercesc;
using namespace std;
-class GSSEAPResolver : public shibsp::AssertionConsumerService
-{
-public:
- GSSEAPResolver(const DOMElement *e, const char *appId)
- : shibsp::AssertionConsumerService(e, appId, Category::getInstance(SHIBSP_LOGCAT".GSSEAPResolver")) {
- }
- virtual ~GSSEAPResolver() {}
-
- ResolutionContext* resolveAttributes (
- const Application& application,
- const RoleDescriptor* issuer,
- const XMLCh* protocol,
- const saml1::NameIdentifier* v1nameid,
- const saml2::NameID* nameid,
- const XMLCh* authncontext_class,
- const XMLCh* authncontext_decl,
- const vector<const Assertion*>* tokens
- ) const {
- return shibsp::AssertionConsumerService::resolveAttributes(
- application, issuer, protocol, v1nameid,
- nameid, authncontext_class, authncontext_decl, tokens
- );
- }
-
-private:
- void implementProtocol(
- const Application& application,
- const HTTPRequest& httpRequest,
- HTTPResponse& httpResponse,
- SecurityPolicy& policy,
- const PropertySet* settings,
- const XMLObject& xmlObject
- ) const {
- throw FatalProfileException("Should never be called.");
- }
+class auto_ptr_gss_buffer {
+ MAKE_NONCOPYABLE(auto_ptr_gss_buffer);
+ public:
+ auto_ptr_gss_buffer() : m_buf(NULL) {
+ }
+ auto_ptr_gss_buffer(const gss_buffer_t src) {
+ m_buf = new XMLCh[src->length + 1];
+ XMLString::transcode((const char *)src->value, m_buf, src->length);
+ }
+ ~auto_ptr_gss_buffer() {
+ xercesc::XMLString::release(&m_buf);
+ }
+ const XMLCh* get() const {
+ return m_buf;
+ }
+ XMLCh* release() {
+ XMLCh *temp = m_buf; m_buf = NULL; return temp;
+ }
+ private:
+ XMLCh *m_buf;
};
-struct eap_gss_saml_attr_ctx {
-public:
- eap_gss_saml_attr_ctx(const gss_buffer_t buffer) {
- parseAssertion(buffer);
- }
-
- eap_gss_saml_attr_ctx(const vector<Attribute*>& attributes,
- const Assertion *assertion = NULL) {
- if (assertion != NULL)
- m_assertion = dynamic_cast<Assertion *>(assertion->clone());
- if (attributes.size())
- setAttributes(attributes);
- }
-
- eap_gss_saml_attr_ctx(const eap_gss_saml_attr_ctx &ctx) {
- eap_gss_saml_attr_ctx(ctx.m_attributes, ctx.m_assertion);
- }
-
- eap_gss_saml_attr_ctx() {}
- ~eap_gss_saml_attr_ctx() {
- for_each(m_attributes.begin(),
- m_attributes.end(),
- xmltooling::cleanup<Attribute>())
- ;
- delete m_assertion;
- }
-
- const vector <Attribute *> getAttributes(void) const {
- return m_attributes;
- }
-
- void addAttribute(Attribute *attr, bool copy = true);
- void setAttributes(const vector<Attribute*> attributes);
-
- void setAttribute(int complete,
- const gss_buffer_t attr,
- const gss_buffer_t value);
- void deleteAttribute(const gss_buffer_t attr);
-
- int getAttributeIndex(const gss_buffer_t attr) const;
- const Attribute *getAttribute(const gss_buffer_t attr) const;
-
- bool getAttribute(const gss_buffer_t attr,
- int *authenticated,
- int *complete,
- gss_buffer_t value,
- gss_buffer_t display_value,
- int *more);
-
- const Assertion *getAssertion(void) const {
- return m_assertion;
+/*
+ * gss_eap_saml_assertion_provider is for retrieving the underlying
+ * assertion.
+ */
+gss_eap_saml_assertion_provider::gss_eap_saml_assertion_provider(const gss_eap_attr_ctx *ctx,
+ gss_cred_id_t gssCred,
+ gss_ctx_id_t gssCtx)
+ : gss_eap_attr_provider(ctx, gssCred, gssCtx)
+{
+ if (gssCtx == GSS_C_NO_CONTEXT) {
+ /* Then we are creating from an existing attribute context */
+ gss_eap_saml_assertion_provider *saml;
+
+ saml = dynamic_cast<gss_eap_saml_assertion_provider *>
+ (ctx->getProvider(ATTR_TYPE_SAML_ASSERTION));
+ if (saml != NULL)
+ setAssertion(saml->getAssertion());
+ } else {
+ gss_eap_radius_attr_provider *radius;
+ gss_buffer_desc value = GSS_C_EMPTY_BUFFER;
+ int authenticated, complete, more = -1;
+ OM_uint32 minor;
+
+ radius = dynamic_cast<gss_eap_radius_attr_provider *>
+ (ctx->getProvider(ATTR_TYPE_RADIUS));
+ if (radius != NULL &&
+ radius->getAttribute(512, &authenticated, &complete,
+ &value, NULL, &more)) {
+ m_assertion = parseAssertion(&value);
+ gss_release_buffer(&minor, &value);
+ }
}
+}
- bool getAssertion(gss_buffer_t buffer);
-
- DDF marshall() const;
- static eap_gss_saml_attr_ctx *unmarshall(DDF &in);
-
- void marshall(gss_buffer_t buffer);
- static eap_gss_saml_attr_ctx *unmarshall(const gss_buffer_t buffer);
-
-private:
- mutable vector<Attribute*> m_attributes;
- mutable Assertion *m_assertion;
-
- bool parseAssertion(const gss_buffer_t buffer);
-};
+gss_eap_saml_assertion_provider::~gss_eap_saml_assertion_provider(void)
+{
+ delete m_assertion;
+}
-static OM_uint32
-mapException(OM_uint32 *minor, exception &e)
+void
+gss_eap_saml_assertion_provider::setAssertion(const saml2::Assertion *assertion)
{
- *minor = 0;
- return GSS_S_FAILURE;
+
+ delete m_assertion;
+ m_assertion = dynamic_cast<saml2::Assertion*>(assertion->clone());
}
-bool
-eap_gss_saml_attr_ctx::parseAssertion(const gss_buffer_t buffer)
+saml2::Assertion *
+gss_eap_saml_assertion_provider::parseAssertion(const gss_buffer_t buffer)
{
- DOMDocument *doc;
- const XMLObjectBuilder *b;
- DOMElement *elem;
- XMLObject *xobj;
string str((char *)buffer->value, buffer->length);
istringstream istream(str);
+ DOMDocument *doc;
+ const XMLObjectBuilder *b;
doc = XMLToolingConfig::getConfig().getParser().parse(istream);
- b = XMLObjectBuilder::getDefaultBuilder();
- elem = doc->getDocumentElement();
- xobj = b->buildOneFromElement(elem, true);
-
- m_assertion = dynamic_cast<Assertion *>(xobj);
+ b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
- return (m_assertion != NULL);
+ return dynamic_cast<saml2::Assertion *>(b->buildFromDocument(doc));
}
-static inline void
-duplicateBuffer(gss_buffer_desc &src, gss_buffer_t dst)
+bool
+gss_eap_saml_assertion_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAttribute, void *data) const
{
- OM_uint32 minor;
-
- if (GSS_ERROR(duplicateBuffer(&minor, &src, dst)))
- throw new bad_alloc();
+ addAttribute(this, GSS_C_NO_BUFFER, data);
}
-static inline void
-duplicateBuffer(string &str, gss_buffer_t buffer)
+void
+gss_eap_saml_assertion_provider::setAttribute(int complete,
+ const gss_buffer_t attr,
+ const gss_buffer_t value)
{
- gss_buffer_desc tmp;
-
- tmp.length = str.length();
- tmp.value = (char *)str.c_str();
+ saml2::Assertion *assertion = parseAssertion(value);
- duplicateBuffer(tmp, buffer);
+ m_assertion = assertion;
}
-DDF
-eap_gss_saml_attr_ctx::marshall() const
+void
+gss_eap_saml_assertion_provider::deleteAttribute(const gss_buffer_t value)
{
- DDF obj(NULL);
- DDF attrs;
- DDF assertion;
-
- obj.addmember("version").integer(1);
-
- attrs = obj.addmember("attributes").list();
- for (vector<Attribute*>::const_iterator a = m_attributes.begin();
- a != m_attributes.end(); ++a) {
- DDF attr = (*a)->marshall();
- attrs.add(attr);
- }
-
- ostringstream sink;
- sink << *m_assertion;
- assertion = obj.addmember("assertion").string(sink.str().c_str());
-
- return obj;
+ delete m_assertion;
+ m_assertion = NULL;
}
-eap_gss_saml_attr_ctx *
-eap_gss_saml_attr_ctx::unmarshall(DDF &obj)
+bool
+gss_eap_saml_assertion_provider::getAttribute(const gss_buffer_t attr,
+ int *authenticated,
+ int *complete,
+ gss_buffer_t value,
+ gss_buffer_t display_value,
+ int *more) const
{
- eap_gss_saml_attr_ctx *ctx = new eap_gss_saml_attr_ctx();
+ string str;
- DDF version = obj["version"];
- if (version.integer() != 1)
- return NULL;
+ if (attr->length != 0 || m_assertion == NULL)
+ return false;
- DDF assertion = obj["assertion"];
- gss_buffer_desc buffer;
+ if (*more == -1)
+ *more = 0;
- if (!assertion.isnull()) {
- buffer.length = assertion.strlen();
- buffer.value = (void *)assertion.string();
- } else {
- buffer.length = 0;
- }
+ if (*more == 0) {
+ *authenticated = true;
+ *complete = false;
- if (buffer.length != 0)
- ctx->parseAssertion(&buffer);
+ XMLHelper::serialize(m_assertion->marshall((DOMDocument *)NULL), str);
- DDF attrs = obj["attributes"];
- DDF attr = attrs.first();
- while (!attr.isnull()) {
- Attribute *attribute = Attribute::unmarshall(attr);
- ctx->addAttribute(attribute, false);
- attr = attrs.next();
+ duplicateBuffer(str, value);
}
- return ctx;
+ return true;
}
-void
-eap_gss_saml_attr_ctx::marshall(gss_buffer_t buffer)
+gss_any_t
+gss_eap_saml_assertion_provider::mapToAny(int authenticated,
+ gss_buffer_t type_id) const
{
- DDF obj = marshall();
- ostringstream sink;
- sink << obj;
- string str = sink.str();
-
- duplicateBuffer(str, buffer);
-
- obj.destroy();
+ return (gss_any_t)m_assertion;
}
-eap_gss_saml_attr_ctx *
-eap_gss_saml_attr_ctx::unmarshall(const gss_buffer_t buffer)
+void
+gss_eap_saml_assertion_provider::releaseAnyNameMapping(gss_buffer_t type_id,
+ gss_any_t input) const
{
- eap_gss_saml_attr_ctx *ctx;
-
- string str((const char *)buffer->value, buffer->length);
- istringstream source(str);
- DDF obj(NULL);
- source >> obj;
-
- ctx = unmarshall(obj);
-
- obj.destroy();
-
- return ctx;
+ delete ((saml2::Assertion *)input);
}
-bool
-eap_gss_saml_attr_ctx::getAssertion(gss_buffer_t buffer)
+void
+gss_eap_saml_assertion_provider::marshall(gss_buffer_t buffer) const
{
+ ostringstream sink;
string str;
- if (m_assertion == NULL)
- return false;
-
- buffer->value = NULL;
buffer->length = 0;
+ buffer->value = NULL;
- XMLHelper::serialize(m_assertion->marshall((DOMDocument *)NULL), str);
+ if (m_assertion == NULL)
+ return;
- duplicateBuffer(str, buffer);
+ sink << *m_assertion;
+ str = sink.str();
- return true;
+ duplicateBuffer(str, buffer);
}
-static Attribute *
-duplicateAttribute(const Attribute *src)
+gss_eap_attr_provider *
+gss_eap_saml_assertion_provider::unmarshall(const gss_eap_attr_ctx *ctx,
+ const gss_buffer_t buffer)
{
- Attribute *attribute;
-
- DDF obj = src->marshall();
- attribute = Attribute::unmarshall(obj);
- obj.destroy();
-
- return attribute;
+ return new gss_eap_saml_assertion_provider(ctx, buffer);
}
-static vector <Attribute *>
-duplicateAttributes(const vector <Attribute *>src)
+bool
+gss_eap_saml_assertion_provider::init(void)
{
- vector <Attribute *> dst;
-
- for (vector<Attribute *>::const_iterator a = src.begin();
- a != src.end();
- ++a)
- dst.push_back(duplicateAttribute(*a));
-
- return dst;
}
void
-eap_gss_saml_attr_ctx::addAttribute(Attribute *attribute, bool copy)
+gss_eap_saml_assertion_provider::finalize(void)
{
- Attribute *a;
-
- a = copy ? duplicateAttribute(attribute) : attribute;
-
- m_attributes.push_back(a);
}
-void
-eap_gss_saml_attr_ctx::setAttributes(const vector<Attribute*> attributes)
+gss_eap_attr_provider *
+gss_eap_saml_assertion_provider::createAttrContext(const gss_eap_attr_ctx *ctx,
+ gss_cred_id_t gssCred,
+ gss_ctx_id_t gssCtx)
{
- for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());
- m_attributes = duplicateAttributes(attributes);
+ return new gss_eap_saml_assertion_provider(ctx, gssCred, gssCtx);
}
-int
-eap_gss_saml_attr_ctx::getAttributeIndex(const gss_buffer_t attr) const
+/*
+ * gss_eap_saml_attr_provider is for retrieving the underlying attributes.
+ */
+const saml2::Assertion *
+gss_eap_saml_attr_provider::getAssertion(void) const
{
- int i = 0;
+ gss_eap_saml_assertion_provider *saml;
+
+ saml = dynamic_cast<gss_eap_saml_assertion_provider *>(m_source->getProvider(ATTR_TYPE_SAML_ASSERTION));
+ assert(saml != NULL);
- for (vector<Attribute *>::const_iterator a = getAttributes().begin();
- a != getAttributes().end();
- ++a)
- {
- for (vector<string>::const_iterator s = (*a)->getAliases().begin();
- s != (*a)->getAliases().end();
- ++s) {
- if (attr->length == (*s).length() &&
- memcmp((*s).c_str(), attr->value, attr->length) == 0) {
- return i;
- }
- }
- }
-
- return -1;
+ return saml->getAssertion();
}
-const Attribute *
-eap_gss_saml_attr_ctx::getAttribute(const gss_buffer_t attr) const
+gss_eap_saml_attr_provider::gss_eap_saml_attr_provider(const gss_eap_attr_ctx *ctx,
+ gss_cred_id_t gssCred,
+ gss_ctx_id_t gssCtx)
+ : gss_eap_attr_provider(ctx, gssCred, gssCtx)
{
- const Attribute *ret = NULL;
-
- for (vector<Attribute *>::const_iterator a = getAttributes().begin();
- a != getAttributes().end();
- ++a)
- {
- for (vector<string>::const_iterator s = (*a)->getAliases().begin();
- s != (*a)->getAliases().end();
- ++s) {
- if (attr->length == (*s).length() &&
- memcmp((*s).c_str(), attr->value, attr->length) == 0) {
- ret = *a;
- break;
- }
- }
- if (ret != NULL)
- break;
- }
+ /* Nothing to do, we're just a wrapper around the assertion provider. */
+}
- return ret;
+gss_eap_saml_attr_provider::~gss_eap_saml_attr_provider(void)
+{
+ /* Nothing to do, we're just a wrapper around the assertion provider. */
}
bool
-eap_gss_saml_attr_ctx::getAttribute(const gss_buffer_t attr,
- int *authenticated,
- int *complete,
- gss_buffer_t value,
- gss_buffer_t display_value,
- int *more)
+gss_eap_saml_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAttribute,
+ void *data) const
{
- const Attribute *shibAttr = NULL;
- gss_buffer_desc buf;
-
- shibAttr = getAttribute(attr);
- if (shibAttr == NULL)
- return false;
+ const saml2::Assertion *assertion = getAssertion();
- if (*more == -1) {
- *more = 0;
- } else if (*more >= (int)shibAttr->valueCount()) {
- *more = 0;
+ if (assertion == NULL)
return true;
- }
- buf.value = (void *)shibAttr->getString(*more);
- buf.length = strlen((char *)buf.value);
+ const vector<saml2::Attribute*>& attrs2 =
+ const_cast<const saml2::AttributeStatement*>(assertion->getAttributeStatements().front())->getAttributes();
+ for (vector<saml2::Attribute*>::const_iterator a = attrs2.begin();
+ a != attrs2.end();
+ ++a)
+ {
+ gss_buffer_desc attribute;
+
+ attribute.value = (void *)toUTF8((*a)->getName(), true);
+ attribute.length = strlen((char *)attribute.value);
- duplicateBuffer(buf, value);
-
- *authenticated = TRUE;
- *complete = FALSE;
+ if (!addAttribute(this, &attribute, data))
+ return false;
+
+ delete (char *)attribute.value;
+ }
return true;
}
void
-eap_gss_saml_attr_ctx::setAttribute(int complete,
- const gss_buffer_t attr,
- const gss_buffer_t value)
+gss_eap_saml_attr_provider::setAttribute(int complete,
+ const gss_buffer_t attr,
+ const gss_buffer_t value)
{
- string attrStr((char *)attr->value, attr->length);
- vector <string> ids(1);
- SimpleAttribute *a;
-
- ids.push_back(attrStr);
-
- a = new SimpleAttribute(ids);
-
- if (value->length != 0) {
- string valStr((char *)value->value, value->length);
-
- a->getValues().push_back(valStr);
- }
-
- m_attributes.push_back(a);
}
void
-eap_gss_saml_attr_ctx::deleteAttribute(const gss_buffer_t attr)
+gss_eap_saml_attr_provider::deleteAttribute(const gss_buffer_t value)
{
- int i;
-
- i = getAttributeIndex(attr);
- if (i >= 0)
- m_attributes.erase(m_attributes.begin() + i);
}
-OM_uint32
-samlReleaseAttrContext(OM_uint32 *minor,
- struct eap_gss_saml_attr_ctx **pCtx)
+const saml2::Attribute *
+gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr) const
{
- eap_gss_saml_attr_ctx *ctx = *pCtx;
-
- if (ctx != NULL) {
- delete ctx;
- *pCtx = NULL;
- }
+ const saml2::Assertion *assertion = getAssertion();
+ saml2::AttributeStatement *statement;
- *minor = 0;
- return GSS_S_COMPLETE;
-}
+ if (assertion == NULL)
+ return NULL;
-OM_uint32
-samlCreateAttrContext(OM_uint32 *minor,
- gss_buffer_t buffer,
- gss_name_t acceptorName,
- struct eap_gss_saml_attr_ctx **pCtx,
- time_t *pExpiryTime)
-{
- OM_uint32 major, tmpMinor;
- eap_gss_saml_attr_ctx *ctx = NULL;
- SPConfig &conf = SPConfig::getConfig();
- ServiceProvider *sp;
- const Application *app;
- MetadataProvider *m;
- gss_buffer_desc nameBuf;
- const XMLCh *issuer = NULL;
- saml2::NameID *subjectName = NULL;
- saml2::Assertion *assertion;
- ResolutionContext *resolverContext;
-
- nameBuf.length = 0;
- nameBuf.value = NULL;
-
- conf.setFeatures(SPConfig::Metadata |
- SPConfig::Trust |
- SPConfig::AttributeResolution |
- SPConfig::Credentials |
- SPConfig::OutOfProcess);
- if (!conf.init())
- return GSS_S_FAILURE;
- if (!conf.instantiate())
- return GSS_S_FAILURE;
-
- sp = conf.getServiceProvider();
- sp->lock();
-
- major = gss_display_name(minor, acceptorName, &nameBuf, NULL);
- if (GSS_ERROR(major))
- goto cleanup;
-
- app = sp->getApplication((const char *)nameBuf.value);
- if (app == NULL) {
- major = GSS_S_FAILURE;
- goto cleanup;
- }
+ if (assertion->getAttributeStatements().size() == 0)
+ return NULL;
- try {
- ctx = new eap_gss_saml_attr_ctx(buffer);
-
- if (assertion->getIssuer() != NULL)
- issuer = assertion->getIssuer()->getName();
- if (assertion->getSubject() != NULL)
- subjectName = assertion->getSubject()->getNameID();
- if (assertion->getConditions())
- *pExpiryTime = assertion->getConditions()->getNotOnOrAfter()->getEpoch();
-
- m = app->getMetadataProvider();
- xmltooling::Locker mlocker(m);
- MetadataProviderCriteria mc(*app, issuer,
- &IDPSSODescriptor::ELEMENT_QNAME,
- samlconstants::SAML20P_NS);
- pair<const EntityDescriptor *, const RoleDescriptor *> site =
- m->getEntityDescriptor(mc);
- if (!site.first) {
- auto_ptr_char temp(issuer);
- throw MetadataException("Unable to locate metadata for IdP ($1).",
- params(1,temp.get()));
- }
- vector<const Assertion*> tokens(1, assertion);
- GSSEAPResolver gssResolver(NULL, (const char *)nameBuf.value);
- resolverContext = gssResolver.resolveAttributes(*app, site.second,
- samlconstants::SAML20P_NS,
- NULL, subjectName, NULL,
- NULL, &tokens);
- ctx->setAttributes(resolverContext->getResolvedAttributes());
- } catch (exception &ex) {
- major = mapException(minor, ex);
- goto cleanup;
- }
+ statement = assertion->getAttributeStatements().front();
- major = GSS_S_COMPLETE;
- *pCtx = ctx;
+ auto_ptr_gss_buffer attrname(attr);
-cleanup:
- sp->unlock();
- conf.term();
+ const vector<saml2::Attribute*>& attrs2 =
+ const_cast<const saml2::AttributeStatement*>(statement)->getAttributes();
- if (GSS_ERROR(major))
- delete ctx;
- gss_release_buffer(&tmpMinor, &nameBuf);
+ for (vector<saml2::Attribute*>::const_iterator a = attrs2.begin();
+ a != attrs2.end();
+ ++a) {
+ if (XMLString::equals((*a)->getName(), attrname.get()))
+ return *a;
+ }
- return major;
+ return NULL;
}
-OM_uint32
-samlGetAttributeTypes(OM_uint32 *minor,
- const struct eap_gss_saml_attr_ctx *ctx,
- void *data,
- OM_uint32 (*addAttribute)(OM_uint32 *, void *, gss_buffer_t))
+bool
+gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr,
+ int *authenticated,
+ int *complete,
+ gss_buffer_t value,
+ gss_buffer_t display_value,
+ int *more) const
{
- OM_uint32 major = GSS_S_COMPLETE;
+ const saml2::Attribute *a;
+ const saml2::AttributeValue *av;
+ int nvalues, i = *more;
- if (ctx == NULL)
- return GSS_S_COMPLETE;
-
- for (vector<Attribute*>::const_iterator a = ctx->getAttributes().begin();
- a != ctx->getAttributes().end();
- ++a)
- {
- gss_buffer_desc attribute;
-
- attribute.value = (void *)((*a)->getId());
- attribute.length = strlen((char *)attribute.value);
+ *more = 0;
- major = addAttribute(minor, data, &attribute);
- if (GSS_ERROR(major))
- break;
- }
+ a = getAttribute(attr);
+ if (a == NULL)
+ return false;
- return major;
-}
+ nvalues = a->getAttributeValues().size();
-/*
- * SAML implementation of gss_get_name_attribute
- */
-OM_uint32
-samlGetAttribute(OM_uint32 *minor,
- struct eap_gss_saml_attr_ctx *ctx,
- gss_buffer_t attr,
- int *authenticated,
- int *complete,
- gss_buffer_t value,
- gss_buffer_t display_value,
- int *more)
-{
- if (ctx == NULL)
- return GSS_S_UNAVAILABLE;
+ if (i == -1)
+ i = 0;
+ else if (i >= nvalues)
+ return false;
+ av = dynamic_cast<const saml2::AttributeValue *>(a->getAttributeValues().at(i)
+);
+ if (av == NULL)
+ return false;
- if (!ctx->getAttribute(attr, authenticated, complete,
- value, display_value, more))
- return GSS_S_UNAVAILABLE;
+ *authenticated = TRUE;
+ *complete = FALSE;
- return GSS_S_COMPLETE;
-}
+ value->value = toUTF8(av->getTextContent(), true);
+ value->length = strlen((char *)value->value);
-OM_uint32
-samlSetAttribute(OM_uint32 *minor,
- struct eap_gss_saml_attr_ctx *ctx,
- int complete,
- gss_buffer_t attr,
- gss_buffer_t value)
-{
- try {
- ctx->setAttribute(complete, attr, value);
- } catch (exception &e) {
- return mapException(minor, e);
- }
+ if (nvalues > ++i)
+ *more = i;
- return GSS_S_COMPLETE;
+ return true;
}
-OM_uint32
-samlDeleteAttribute(OM_uint32 *minor,
- struct eap_gss_saml_attr_ctx *ctx,
- gss_buffer_t attr)
+gss_any_t
+gss_eap_saml_attr_provider::mapToAny(int authenticated,
+ gss_buffer_t type_id) const
{
- try {
- ctx->deleteAttribute(attr);
- } catch (exception &e) {
- return mapException(minor, e);
- }
-
- return GSS_S_COMPLETE;
+ return (gss_any_t)0;
}
-/*
- * In order to implement gss_export_name and gss_export_sec_context,
- * we need to serialise a resolved attribute context to a buffer.
- */
-OM_uint32
-samlExportAttrContext(OM_uint32 *minor,
- struct eap_gss_saml_attr_ctx *ctx,
- gss_buffer_t buffer)
+void
+gss_eap_saml_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id,
+ gss_any_t input) const
{
- try {
- ctx->marshall(buffer);
- } catch (exception &e) {
- return mapException(minor, e);
- }
-
- return GSS_S_COMPLETE;
}
-/*
- * In order to implement gss_import_name and gss_import_sec_context,
- * we need to deserialise a resolved attribute context from a buffer.
- */
-OM_uint32
-samlImportAttrContext(OM_uint32 *minor,
- gss_buffer_t buffer,
- struct eap_gss_saml_attr_ctx **pCtx)
+void
+gss_eap_saml_attr_provider::marshall(gss_buffer_t buffer) const
{
- try {
- *pCtx = eap_gss_saml_attr_ctx::unmarshall(buffer);
- } catch (exception &e) {
- return mapException(minor, e);
- }
-
- return GSS_S_COMPLETE;
}
-OM_uint32
-samlGetAssertion(OM_uint32 *minor,
- struct eap_gss_saml_attr_ctx *ctx,
- gss_buffer_t assertion)
+gss_eap_attr_provider *
+gss_eap_saml_attr_provider::unmarshall(const gss_eap_attr_ctx *ctx,
+ const gss_buffer_t buffer)
{
- try {
- ctx->getAssertion(assertion);
- } catch (exception &e) {
- return mapException(minor, e);
- }
-
- return GSS_S_COMPLETE;
+ return new gss_eap_saml_attr_provider(ctx);
}
-OM_uint32
-samlDuplicateAttrContext(OM_uint32 *minor,
- const struct eap_gss_saml_attr_ctx *in,
- struct eap_gss_saml_attr_ctx **out)
+bool
+gss_eap_saml_attr_provider::init(void)
{
- try {
- *out = new eap_gss_saml_attr_ctx(*in);
- } catch (exception &e) {
- return mapException(minor, e);
- }
-
- return GSS_S_COMPLETE;
+ return true;
}
-OM_uint32
-samlMapNameToAny(OM_uint32 *minor,
- const struct eap_gss_saml_attr_ctx *ctx,
- int authenticated,
- gss_buffer_t type_id,
- gss_any_t *output)
+void
+gss_eap_saml_attr_provider::finalize(void)
{
- if (bufferEqualString(type_id, "shibsp::Attribute")) {
- vector <Attribute *>v = duplicateAttributes(ctx->getAttributes());
-
- *output = (gss_any_t)new vector <Attribute *>(v);
- } else if (bufferEqualString(type_id, "opensaml::Assertion")) {
- *output = (gss_any_t)ctx->getAssertion()->clone();
- } else {
- *output = (gss_any_t)NULL;
- return GSS_S_UNAVAILABLE;
- }
-
- return GSS_S_COMPLETE;
}
-OM_uint32
-samlReleaseAnyNameMapping(OM_uint32 *minor,
- const struct eap_gss_saml_attr_ctx *ctx,
- gss_buffer_t type_id,
- gss_any_t *input)
+gss_eap_attr_provider *
+gss_eap_saml_attr_provider::createAttrContext(const gss_eap_attr_ctx *ctx,
+ gss_cred_id_t gssCred,
+ gss_ctx_id_t gssCtx)
{
- if (bufferEqualString(type_id, "vector<shibsp::Attribute>")) {
- vector <Attribute *> *v = ((vector <Attribute *> *)*input);
- delete v;
- } else if (bufferEqualString(type_id, "opensaml::Assertion")) {
- delete (Assertion *)*input;
- } else {
- return GSS_S_UNAVAILABLE;
- }
-
- *input = (gss_any_t)NULL;
- return GSS_S_COMPLETE;
+ return new gss_eap_saml_attr_provider(ctx, gssCred, gssCtx);
}