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.
20 * Interface to SAML protocol binding message encoders.
24 #include "binding/MessageEncoder.h"
25 #include "util/SAMLConstants.h"
27 #include <xmltooling/signature/KeyInfo.h>
28 #include <xmltooling/signature/Signature.h>
30 using namespace opensaml;
31 using namespace xmlsignature;
32 using namespace xmltooling;
37 SAML_DLLLOCAL PluginManager<MessageEncoder,const DOMElement*>::Factory SAML1ArtifactEncoderFactory;
38 SAML_DLLLOCAL PluginManager<MessageEncoder,const DOMElement*>::Factory SAML1POSTEncoderFactory;
42 SAML_DLLLOCAL PluginManager<MessageEncoder,const DOMElement*>::Factory SAML2ArtifactEncoderFactory;
43 SAML_DLLLOCAL PluginManager<MessageEncoder,const DOMElement*>::Factory SAML2POSTEncoderFactory;
47 void SAML_API opensaml::registerMessageEncoders()
49 SAMLConfig& conf=SAMLConfig::getConfig();
50 conf.MessageEncoderManager.registerFactory(SAMLConstants::SAML1_PROFILE_BROWSER_ARTIFACT, saml1p::SAML1ArtifactEncoderFactory);
51 conf.MessageEncoderManager.registerFactory(SAMLConstants::SAML1_PROFILE_BROWSER_POST, saml1p::SAML1POSTEncoderFactory);
52 conf.MessageEncoderManager.registerFactory(SAMLConstants::SAML20_BINDING_HTTP_ARTIFACT, saml2p::SAML2ArtifactEncoderFactory);
53 conf.MessageEncoderManager.registerFactory(SAMLConstants::SAML20_BINDING_HTTP_POST, saml2p::SAML2POSTEncoderFactory);
57 class SAML_DLLLOCAL _addcert : public binary_function<X509Data*,XSECCryptoX509*,void> {
59 void operator()(X509Data* bag, XSECCryptoX509* cert) const {
60 safeBuffer& buf=cert->getDEREncodingSB();
61 X509Certificate* x=X509CertificateBuilder::buildX509Certificate();
62 x->setValue(buf.sbStrToXMLCh());
63 bag->getX509Certificates().push_back(x);
68 Signature* MessageEncoder::buildSignature(const CredentialResolver* credResolver, const XMLCh* sigAlgorithm) const
71 Signature* sig = SignatureBuilder::buildSignature();
73 sig->setSignatureAlgorithm(sigAlgorithm);
74 sig->setSigningKey(credResolver->getKey());
77 const vector<XSECCryptoX509*>& certs = credResolver->getCertificates();
79 KeyInfo* keyInfo=KeyInfoBuilder::buildKeyInfo();
80 X509Data* x509Data=X509DataBuilder::buildX509Data();
81 keyInfo->getX509Datas().push_back(x509Data);
82 for_each(certs.begin(),certs.end(),bind1st(_addcert(),x509Data));
83 sig->setKeyInfo(keyInfo);