2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * RequireValidUntilMetadataFilter.cpp
24 * MetadataFilter that enforces expiration requirements.
28 #include "saml2/metadata/Metadata.h"
29 #include "saml2/metadata/MetadataFilter.h"
31 #include <xmltooling/logging.h>
32 #include <xmltooling/util/NDC.h>
34 using namespace opensaml::saml2md;
35 using namespace xmltooling::logging;
36 using namespace xmltooling;
42 class SAML_DLLLOCAL RequireValidUntilMetadataFilter : public MetadataFilter
45 RequireValidUntilMetadataFilter(const DOMElement* e);
46 ~RequireValidUntilMetadataFilter() {}
48 const char* getId() const { return REQUIREVALIDUNTIL_METADATA_FILTER; }
49 void doFilter(XMLObject& xmlObject) const;
52 time_t m_maxValidityInterval;
55 MetadataFilter* SAML_DLLLOCAL RequireValidUntilMetadataFilterFactory(const DOMElement* const & e)
57 return new RequireValidUntilMetadataFilter(e);
63 static const XMLCh maxValidityInterval[] = UNICODE_LITERAL_19(m,a,x,V,a,l,i,d,i,t,y,I,n,t,e,r,v,a,l);
65 RequireValidUntilMetadataFilter::RequireValidUntilMetadataFilter(const DOMElement* e)
66 : m_maxValidityInterval(XMLHelper::getAttrInt(e, 60 * 60 * 24 * 7, maxValidityInterval))
70 void RequireValidUntilMetadataFilter::doFilter(XMLObject& xmlObject) const
72 const TimeBoundSAMLObject* tbo = dynamic_cast<const TimeBoundSAMLObject*>(&xmlObject);
74 throw MetadataFilterException("Metadata root element was invalid.");
76 if (!tbo->getValidUntil())
77 throw MetadataFilterException("Metadata did not include a validUntil attribute.");
79 if (tbo->getValidUntilEpoch() - time(nullptr) > m_maxValidityInterval)
80 throw MetadataFilterException("Metadata validity interval is larger than permitted.");