Add short name to encoders/decoders for endpoint generation.
[shibboleth/cpp-opensaml.git] / saml / binding / impl / MessageDecoder.cpp
1 /*
2  *  Copyright 2001-2010 Internet2
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * MessageDecoder.cpp
19  *
20  * Interface to SAML protocol binding message decoders.
21  */
22
23 #include "internal.h"
24 #include "binding/MessageDecoder.h"
25 #include "saml2/metadata/EndpointManager.h"
26 #include "saml2/metadata/Metadata.h"
27 #include "util/SAMLConstants.h"
28
29 #include <xmltooling/impl/AnyElement.h>
30
31 using namespace opensaml::saml2md;
32 using namespace opensaml;
33 using namespace xmltooling;
34 using namespace std;
35
36 namespace opensaml {
37     namespace saml1p {
38         SAML_DLLLOCAL PluginManager< MessageDecoder,string,pair<const DOMElement*,const XMLCh*> >::Factory SAML1ArtifactDecoderFactory;
39         SAML_DLLLOCAL PluginManager< MessageDecoder,string,pair<const DOMElement*,const XMLCh*> >::Factory SAML1POSTDecoderFactory;
40         SAML_DLLLOCAL PluginManager< MessageDecoder,string,pair<const DOMElement*,const XMLCh*> >::Factory SAML1SOAPDecoderFactory;
41     };
42
43     namespace saml2p {
44         SAML_DLLLOCAL PluginManager< MessageDecoder,string,pair<const DOMElement*,const XMLCh*> >::Factory SAML2ArtifactDecoderFactory;
45         SAML_DLLLOCAL PluginManager< MessageDecoder,string,pair<const DOMElement*,const XMLCh*> >::Factory SAML2POSTDecoderFactory;
46         SAML_DLLLOCAL PluginManager< MessageDecoder,string,pair<const DOMElement*,const XMLCh*> >::Factory SAML2POSTSimpleSignDecoderFactory;
47         SAML_DLLLOCAL PluginManager< MessageDecoder,string,pair<const DOMElement*,const XMLCh*> >::Factory SAML2RedirectDecoderFactory;
48         SAML_DLLLOCAL PluginManager< MessageDecoder,string,pair<const DOMElement*,const XMLCh*> >::Factory SAML2SOAPDecoderFactory;
49         SAML_DLLLOCAL PluginManager< MessageDecoder,string,pair<const DOMElement*,const XMLCh*> >::Factory SAML2ECPDecoderFactory;
50     };
51 };
52
53 void SAML_API opensaml::registerMessageDecoders()
54 {
55     SAMLConfig& conf=SAMLConfig::getConfig();
56     conf.MessageDecoderManager.registerFactory(samlconstants::SAML1_PROFILE_BROWSER_ARTIFACT, saml1p::SAML1ArtifactDecoderFactory);
57     conf.MessageDecoderManager.registerFactory(samlconstants::SAML1_PROFILE_BROWSER_POST, saml1p::SAML1POSTDecoderFactory);
58     conf.MessageDecoderManager.registerFactory(samlconstants::SAML1_BINDING_SOAP, saml1p::SAML1SOAPDecoderFactory);
59     conf.MessageDecoderManager.registerFactory(samlconstants::SAML20_BINDING_HTTP_ARTIFACT, saml2p::SAML2ArtifactDecoderFactory);
60     conf.MessageDecoderManager.registerFactory(samlconstants::SAML20_BINDING_HTTP_POST, saml2p::SAML2POSTDecoderFactory);
61     conf.MessageDecoderManager.registerFactory(samlconstants::SAML20_BINDING_HTTP_POST_SIMPLESIGN, saml2p::SAML2POSTSimpleSignDecoderFactory);
62     conf.MessageDecoderManager.registerFactory(samlconstants::SAML20_BINDING_HTTP_REDIRECT, saml2p::SAML2RedirectDecoderFactory);
63     conf.MessageDecoderManager.registerFactory(samlconstants::SAML20_BINDING_SOAP, saml2p::SAML2SOAPDecoderFactory);
64     conf.MessageDecoderManager.registerFactory(samlconstants::SAML20_BINDING_PAOS, saml2p::SAML2ECPDecoderFactory);
65
66     static const XMLCh RelayState[] = UNICODE_LITERAL_10(R,e,l,a,y,S,t,a,t,e);
67     XMLObjectBuilder::registerBuilder(xmltooling::QName(samlconstants::SAML20ECP_NS, RelayState), new AnyElementBuilder());
68 }
69
70 MessageDecoder::MessageDecoder() : m_artifactResolver(nullptr)
71 {
72 }
73
74 MessageDecoder::~MessageDecoder()
75 {
76 }
77
78 const XMLCh* MessageDecoder::getProtocolFamily() const
79 {
80     return nullptr;
81 }
82
83 const char* MessageDecoder::getShortName() const
84 {
85     return nullptr;
86 }
87
88 bool MessageDecoder::isUserAgentPresent() const
89 {
90     return true;
91 }
92
93 void MessageDecoder::setArtifactResolver(const ArtifactResolver* artifactResolver)
94 {
95     m_artifactResolver = artifactResolver;
96 }
97
98 MessageDecoder::ArtifactResolver::ArtifactResolver()
99 {
100 }
101
102 MessageDecoder::ArtifactResolver::~ArtifactResolver()
103 {
104 }
105
106 bool MessageDecoder::ArtifactResolver::isSupported(const SSODescriptorType& ssoDescriptor) const
107 {
108     EndpointManager<ArtifactResolutionService> mgr(ssoDescriptor.getArtifactResolutionServices());
109     if (ssoDescriptor.hasSupport(samlconstants::SAML20P_NS)) {
110         auto_ptr_XMLCh binding(samlconstants::SAML20_BINDING_SOAP);
111         return (mgr.getByBinding(binding.get()) != nullptr);
112     }
113     else if (ssoDescriptor.hasSupport(samlconstants::SAML11_PROTOCOL_ENUM) || ssoDescriptor.hasSupport(samlconstants::SAML10_PROTOCOL_ENUM)) {
114         auto_ptr_XMLCh binding(samlconstants::SAML1_BINDING_SOAP);
115         return (mgr.getByBinding(binding.get()) != nullptr);
116     }
117
118     return false;
119 }