2 * Copyright 2001-2006 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * ProtocolsSchemaValidators.cpp
20 * Schema-based validators for SAML 1.x Protocols classes
24 #include "exceptions.h"
25 #include "saml1/core/Protocols.h"
27 using namespace opensaml::saml1p;
28 using namespace opensaml::saml1;
29 using namespace opensaml;
30 using namespace xmltooling;
36 XMLOBJECTVALIDATOR_SIMPLE(SAML_DLLLOCAL,AssertionArtifact);
37 XMLOBJECTVALIDATOR_SIMPLE(SAML_DLLLOCAL,StatusMessage);
39 BEGIN_XMLOBJECTVALIDATOR(SAML_DLLLOCAL,RespondWith);
40 XMLOBJECTVALIDATOR_REQUIRE(RespondWith,QName);
41 END_XMLOBJECTVALIDATOR;
43 BEGIN_XMLOBJECTVALIDATOR(SAML_DLLLOCAL,AuthenticationQuery);
44 XMLOBJECTVALIDATOR_REQUIRE(AuthenticationQuery,AuthenticationMethod);
45 XMLOBJECTVALIDATOR_REQUIRE(AuthenticationQuery,Subject);
46 END_XMLOBJECTVALIDATOR;
48 BEGIN_XMLOBJECTVALIDATOR(SAML_DLLLOCAL,AttributeQuery);
49 XMLOBJECTVALIDATOR_REQUIRE(AttributeQuery,Subject);
50 END_XMLOBJECTVALIDATOR;
52 BEGIN_XMLOBJECTVALIDATOR(SAML_DLLLOCAL,AuthorizationDecisionQuery);
53 XMLOBJECTVALIDATOR_REQUIRE(AuthorizationDecisionQuery,Subject);
54 XMLOBJECTVALIDATOR_REQUIRE(AuthorizationDecisionQuery,Resource);
55 XMLOBJECTVALIDATOR_NONEMPTY(AuthorizationDecisionQuery,Action);
56 END_XMLOBJECTVALIDATOR;
58 BEGIN_XMLOBJECTVALIDATOR(SAML_DLLLOCAL,Request);
59 XMLOBJECTVALIDATOR_REQUIRE(Request,RequestID);
60 XMLOBJECTVALIDATOR_REQUIRE(Request,IssueInstant);
61 pair<bool,int> minor=ptr->getMinorVersion();
63 throw ValidationException("Request must have MinorVersion");
65 if (ptr->getQuery()!=NULL)
67 if (!ptr->getAssertionIDReferences().empty())
69 if (!ptr->getAssertionArtifacts().empty())
72 throw ValidationException("Request must have either a query, >0 assertion references, or >0 artifacts.");
73 END_XMLOBJECTVALIDATOR;
75 BEGIN_XMLOBJECTVALIDATOR(SAML_DLLLOCAL,StatusCode);
76 XMLOBJECTVALIDATOR_REQUIRE(StatusCode,Value);
77 END_XMLOBJECTVALIDATOR;
79 BEGIN_XMLOBJECTVALIDATOR(SAML_DLLLOCAL,Status);
80 XMLOBJECTVALIDATOR_REQUIRE(Status,StatusCode);
81 const QName* value=ptr->getStatusCode()->getValue();
82 if (!value || (*value!=StatusCode::SUCCESS && *value!=StatusCode::REQUESTER &&
83 *value!=StatusCode::RESPONDER && *value!=StatusCode::VERSIONMISMATCH))
84 throw ValidationException("Top-level status code not one of the allowable values.");
85 END_XMLOBJECTVALIDATOR;
87 BEGIN_XMLOBJECTVALIDATOR(SAML_DLLLOCAL,Response);
88 XMLOBJECTVALIDATOR_REQUIRE(Response,ResponseID);
89 XMLOBJECTVALIDATOR_REQUIRE(Response,IssueInstant);
90 XMLOBJECTVALIDATOR_REQUIRE(Response,Status);
91 pair<bool,int> minor=ptr->getMinorVersion();
93 throw ValidationException("Response must have MinorVersion");
94 END_XMLOBJECTVALIDATOR;
98 #define REGISTER_ELEMENT(cname) \
99 q=QName(SAMLConstants::SAML1P_NS,cname::LOCAL_NAME); \
100 XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \
101 SchemaValidators.registerValidator(q,new cname##SchemaValidator())
103 #define REGISTER_TYPE(cname) \
104 q=QName(SAMLConstants::SAML1P_NS,cname::TYPE_NAME); \
105 XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \
106 SchemaValidators.registerValidator(q,new cname##SchemaValidator())
108 #define REGISTER_ELEMENT_NOVAL(cname) \
109 q=QName(SAMLConstants::SAML1P_NS,cname::LOCAL_NAME); \
110 XMLObjectBuilder::registerBuilder(q,new cname##Builder());
112 #define REGISTER_TYPE_NOVAL(cname) \
113 q=QName(SAMLConstants::SAML1P_NS,cname::TYPE_NAME); \
114 XMLObjectBuilder::registerBuilder(q,new cname##Builder());
116 void opensaml::saml1p::registerProtocolClasses() {
118 REGISTER_ELEMENT(AssertionArtifact);
119 REGISTER_ELEMENT(AttributeQuery);
120 REGISTER_ELEMENT(AuthenticationQuery);
121 REGISTER_ELEMENT(AuthorizationDecisionQuery);
122 REGISTER_ELEMENT(Request);
123 REGISTER_ELEMENT(RespondWith);
124 REGISTER_ELEMENT(Response);
125 REGISTER_ELEMENT(Status);
126 REGISTER_ELEMENT(StatusCode);
127 REGISTER_ELEMENT_NOVAL(StatusDetail);
128 REGISTER_ELEMENT(StatusMessage);
129 REGISTER_TYPE(AttributeQuery);
130 REGISTER_TYPE(AuthenticationQuery);
131 REGISTER_TYPE(AuthorizationDecisionQuery);
132 REGISTER_TYPE(Request);
133 REGISTER_TYPE(Response);
134 REGISTER_TYPE(Status);
135 REGISTER_TYPE(StatusCode);
136 REGISTER_TYPE_NOVAL(StatusDetail);