ClientCertAuthRule(const DOMElement* e) {}
virtual ~ClientCertAuthRule() {}
- void evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
+ bool evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
};
};
MessageFlowRule(const DOMElement* e);
virtual ~MessageFlowRule() {}
- void evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
+ bool evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
/**
* Controls whether rule executes replay checking.
virtual ~SecurityPolicyRule() {}
/**
- * Evaluates the rule against the given request and message. If an Issuer is
- * returned, the caller is responsible for freeing the Issuer object.
+ * Evaluates the rule against the given request and message.
+ *
+ * <p>Exceptions should be reserved for fatal request processing errors;
+ * otherwise rules should return false to indicate they were not applicable
+ * or unsuccessful.
*
* @param message the incoming message
* @param request the protocol request
* @param policy SecurityPolicy to provide various components and track message data
+ * @return true iff the rule ran successfully, false otherwise
*
- * @throws BindingException thrown if the request/message do not meet the requirements of this rule
+ * @throws BindingException thrown if the request/message is invalid in some way
*/
- virtual void evaluate(
+ virtual bool evaluate(
const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy
) const=0;
};
SimpleSigningRule(const DOMElement* e) {}
virtual ~SimpleSigningRule() {}
- void evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
+ bool evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
};
};
XMLSigningRule(const DOMElement* e) {}
virtual ~XMLSigningRule() {}
- void evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
+ bool evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
};
};
}
};
-void ClientCertAuthRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
+bool ClientCertAuthRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
{
Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.ClientCertAuth");
log.debug("evaluating client certificate authentication policy");
if (!request) {
log.debug("ignoring message, no protocol request available");
- return;
+ return false;
}
else if (!policy.getIssuerMetadata()) {
log.debug("ignoring message, no issuer metadata supplied");
- return;
+ return false;
}
const X509TrustEngine* x509trust;
if (!(x509trust=dynamic_cast<const X509TrustEngine*>(policy.getTrustEngine()))) {
log.debug("ignoring message, no X509TrustEngine supplied");
- return;
+ return false;
}
const std::vector<XSECCryptoX509*>& chain = request->getClientCertificates();
if (chain.empty()) {
log.debug("ignoring message, no client certificates in request");
- return;
+ return false;
}
if (!x509trust->validate(chain.front(), chain, *(policy.getIssuerMetadata()), true,
policy.getMetadataProvider()->getKeyResolver())) {
log.error("unable to verify certificate chain with supplied trust engine");
- return;
+ return false;
}
log.debug("client certificate verified against message issuer");
+ return true;
}
}
}
-void MessageFlowRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
+bool MessageFlowRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
{
Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.MessageFlow");
log.debug("evaluating message flow policy (replay checking %s, expiration %lu)", m_checkReplay ? "on" : "off", m_expires);
throw BindingException("Rejecting replayed message ID ($1).", params(1,temp.get()));
}
}
+
+ return true;
}
};
-void SimpleSigningRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
+bool SimpleSigningRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
{
Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.SimpleSigning");
log.debug("evaluating simple signing policy");
if (!policy.getIssuerMetadata()) {
log.debug("ignoring message, no issuer metadata supplied");
- return;
+ return false;
}
else if (!policy.getTrustEngine()) {
log.debug("ignoring message, no TrustEngine supplied");
- return;
+ return false;
}
const HTTPRequest* httpRequest = dynamic_cast<const HTTPRequest*>(request);
if (!request || !httpRequest) {
log.debug("ignoring message, no HTTP protocol request available");
- return;
+ return false;
}
const char* signature = request->getParameter("Signature");
if (!signature) {
log.debug("ignoring unsigned message");
- return;
+ return false;
}
const char* sigAlgorithm = request->getParameter("SigAlg");
if (!sigAlgorithm) {
log.error("SigAlg parameter not found, no way to verify the signature");
- return;
+ return false;
}
string input;
*(policy.getIssuerMetadata()), policy.getMetadataProvider()->getKeyResolver()
)) {
log.error("unable to verify message signature with supplied trust engine");
- return;
+ return false;
}
log.debug("signature verified against message issuer");
+ return true;
}
}
};
-void XMLSigningRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
+bool XMLSigningRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
{
Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.XMLSigning");
log.debug("evaluating message signing policy");
if (!policy.getIssuerMetadata()) {
log.debug("ignoring message, no issuer metadata supplied");
- return;
+ return false;
}
else if (!policy.getTrustEngine()) {
log.debug("ignoring message, no TrustEngine supplied");
- return;
+ return false;
}
const SignableObject* signable = dynamic_cast<const SignableObject*>(&message);
if (!signable || !signable->getSignature()) {
log.debug("ignoring unsigned or unrecognized message");
- return;
+ return false;
}
log.debug("validating signature profile");
}
catch (ValidationException& ve) {
log.error("signature profile failed to validate: %s", ve.what());
- return;
+ return false;
}
if (!policy.getTrustEngine()->validate(
*(signable->getSignature()), *(policy.getIssuerMetadata()), policy.getMetadataProvider()->getKeyResolver()
)) {
log.error("unable to verify message signature with supplied trust engine");
- return;
+ return false;
}
log.debug("signature verified against message issuer");
+ return true;
}
SAML1MessageRule(const DOMElement* e) {}
virtual ~SAML1MessageRule() {}
- void evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
+ bool evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
};
};
};
}
};
-void SAML1MessageRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
+bool SAML1MessageRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
{
Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.SAML1Message");
if (!protocol) {
log.warn("issuer identity not extracted");
- return;
+ return false;
}
if (log.isDebugEnabled()) {
if (!entity) {
auto_ptr_char temp(policy.getIssuer()->getName());
log.warn("no metadata found, can't establish identity of issuer (%s)", temp.get());
- return;
+ return false;
}
log.debug("matched message issuer against metadata, searching for applicable role...");
const RoleDescriptor* roledesc=entity->getRoleDescriptor(*policy.getRole(), protocol);
if (!roledesc) {
log.warn("unable to find compatible role (%s) in metadata", policy.getRole()->toString().c_str());
- return;
+ return false;
}
policy.setIssuerMetadata(roledesc);
+ return true;
}
}
catch (bad_cast&) {
// Just trap it.
log.warn("caught a bad_cast while examining message");
}
+
+ return false;
}
SAML2MessageRule(const DOMElement* e) {}
virtual ~SAML2MessageRule() {}
- void evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
+ bool evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
};
};
};
}
};
-void SAML2MessageRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
+bool SAML2MessageRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
{
Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.SAML2Message");
if (!policy.getIssuer()) {
log.warn("issuer identity not extracted");
- return;
+ return false;
}
if (log.isDebugEnabled()) {
if (policy.getMetadataProvider() && policy.getRole()) {
if (policy.getIssuer()->getFormat() && !XMLString::equals(policy.getIssuer()->getFormat(), saml2::NameIDType::ENTITY)) {
log.warn("non-system entity issuer, skipping metadata lookup");
- return;
+ return false;
}
log.debug("searching metadata for message issuer...");
if (!entity) {
auto_ptr_char temp(policy.getIssuer()->getName());
log.warn("no metadata found, can't establish identity of issuer (%s)", temp.get());
- return;
+ return false;
}
log.debug("matched message issuer against metadata, searching for applicable role...");
const RoleDescriptor* roledesc=entity->getRoleDescriptor(*policy.getRole(), samlconstants::SAML20P_NS);
if (!roledesc) {
log.warn("unable to find compatible role (%s) in metadata", policy.getRole()->toString().c_str());
- return;
+ return false;
}
policy.setIssuerMetadata(roledesc);
+ return true;
}
}
catch (bad_cast&) {
// Just trap it.
log.warn("caught a bad_cast while examining message");
}
+
+ return false;
}