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