- static char DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
-
- auto_ptr<XSECCryptoHash> hasher(XSECPlatformUtils::g_cryptoProvider->hashSHA1());
- if (hasher.get()) {
- auto_ptr<char> dup(strdup(s));
- unsigned char buf[21];
- hasher->hash(reinterpret_cast<unsigned char*>(dup.get()),strlen(dup.get()));
- if (hasher->finish(buf,20)==20) {
- string ret;
- if (toHex) {
- for (unsigned int i=0; i<20; i++) {
- ret+=(DIGITS[((unsigned char)(0xF0 & buf[i])) >> 4 ]);
- ret+=(DIGITS[0x0F & buf[i]]);
- }
+ return SecurityHelper::doHash("SHA1", s, strlen(s), toHex);
+}
+
+void SAMLInternalConfig::setContactPriority(const XMLCh* contactTypes)
+{
+ const XMLCh* ctype;
+ m_contactPriority.clear();
+ XMLStringTokenizer tokens(contactTypes);
+ while (tokens.hasMoreTokens()) {
+ ctype = tokens.nextToken();
+ if (ctype && *ctype)
+ m_contactPriority.push_back(ctype);
+ }
+}
+
+using namespace saml2md;
+
+const ContactPerson* SAMLInternalConfig::getContactPerson(const EntityDescriptor& entity) const
+{
+ for (vector<xstring>::const_iterator ctype = m_contactPriority.begin(); ctype != m_contactPriority.end(); ++ctype) {
+ const ContactPerson* cp = find_if(entity.getContactPersons(), *ctype == lambda::bind(&ContactPerson::getContactType, _1));
+ if (cp)
+ return cp;
+ }
+ return nullptr;
+}
+
+const ContactPerson* SAMLInternalConfig::getContactPerson(const RoleDescriptor& role) const
+{
+ for (vector<xstring>::const_iterator ctype = m_contactPriority.begin(); ctype != m_contactPriority.end(); ++ctype) {
+ const ContactPerson* cp = find_if(role.getContactPersons(), *ctype == lambda::bind(&ContactPerson::getContactType, _1));
+ if (cp)
+ return cp;
+ }
+ return getContactPerson(*(dynamic_cast<const EntityDescriptor*>(role.getParent())));
+}
+
+SignableObject::SignableObject()
+{
+}
+
+SignableObject::~SignableObject()
+{
+}
+
+RootObject::RootObject()
+{
+}
+
+RootObject::~RootObject()
+{
+}
+
+Assertion::Assertion()
+{
+}
+
+Assertion::~Assertion()
+{
+}
+
+Status::Status()
+{
+}
+
+Status::~Status()
+{
+}
+
+void opensaml::annotateException(XMLToolingException* e, const EntityDescriptor* entity, const Status* status, bool rethrow)
+{
+ time_t now = time(nullptr);
+ const RoleDescriptor* role = nullptr;
+ static bool (TimeBoundSAMLObject::* isValid)(time_t) const = &TimeBoundSAMLObject::isValid;
+
+ if (entity) {
+ const XMLObject* r = find_if(
+ entity->getOrderedChildren(),
+ (ll_dynamic_cast<const RoleDescriptor*>(_1) != ((const RoleDescriptor*)nullptr) &&
+ lambda::bind(isValid, ll_dynamic_cast<const TimeBoundSAMLObject*>(_1), now))
+ );
+ if (r)
+ role = dynamic_cast<const RoleDescriptor*>(r);
+ }
+
+ annotateException(e, role, status, rethrow);
+}
+
+void opensaml::annotateException(XMLToolingException* e, const RoleDescriptor* role, const Status* status, bool rethrow)
+{
+ if (role) {
+ auto_ptr_char id(dynamic_cast<EntityDescriptor*>(role->getParent())->getEntityID());
+ e->addProperty("entityID",id.get());
+
+ const ContactPerson* cp = SAMLConfig::getConfig().getContactPerson(*role);
+ if (cp) {
+ GivenName* fname = cp->getGivenName();
+ SurName* lname = cp->getSurName();
+ auto_ptr_char first(fname ? fname->getName() : nullptr);
+ auto_ptr_char last(lname ? lname->getName() : nullptr);
+ if (first.get() && last.get()) {
+ string contact=string(first.get()) + ' ' + last.get();
+ e->addProperty("contactName", contact.c_str());