Add conditional remoting, remove nullptr reference.
[shibboleth/resolver.git] / shibresolver / resolver.cpp
1 /*
2  *  Copyright 2010 JANET(UK)
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  * resolver.cpp
19  *
20  * An embeddable component interface to Shibboleth SP attribute processing.
21  */
22
23 #include "internal.h"
24
25 #include <shibsp/ServiceProvider.h>
26 #include <shibsp/attribute/Attribute.h>
27 #include <shibsp/remoting/ListenerService.h>
28
29 using namespace shibresolver;
30 using namespace shibsp;
31 #ifndef SHIBSP_LITE
32 using namespace opensaml;
33 #endif
34 using namespace xmltooling;
35 using namespace std;
36
37 namespace shibresolver {
38     class SHIBRESOLVER_DLLLOCAL RemotedResolver : public Remoted {
39     public:
40         RemotedResolver() {}
41         ~RemotedResolver() {}
42
43         void receive(DDF& in, ostream& out);
44     };
45
46     static RemotedResolver g_Remoted;
47 };
48
49 ShibbolethResolver* ShibbolethResolver::create()
50 {
51     return new ShibbolethResolver();
52 }
53
54 ShibbolethResolver::ShibbolethResolver()
55 {
56 }
57
58 ShibbolethResolver::~ShibbolethResolver()
59 {
60     for_each(m_resolvedAttributes.begin(), m_resolvedAttributes.end(), xmltooling::cleanup<Attribute>());
61     if (m_mapper)
62         m_mapper->unlock();
63     if (m_sp)
64         m_sp->unlock();
65 }
66
67 void ShibbolethResolver::setServiceURI(const char* uri)
68 {
69     m_serviceURI.erase();
70     if (uri)
71         m_serviceURI = uri;
72 }
73
74 void ShibbolethResolver::setApplicationID(const char* appID)
75 {
76     m_appID.erase();
77     if (appID)
78         m_appID = appID;
79 }
80
81 void ShibbolethResolver::setIssuer(const char* issuer)
82 {
83     m_issuer.erase();
84     if (issuer)
85         m_issuer = issuer;
86 }
87
88 void ShibbolethResolver::addToken(
89 #ifdef SHIBSP_LITE
90         const XMLObject* token
91 #else
92         const saml2::Assertion* token
93 #endif
94     )
95 {
96     if (token)
97         m_tokens.push_back(token);
98 }
99
100 void ShibbolethResolver::addAttribute(Attribute* attr)
101 {
102     if (attr)
103         m_inputAttributes.push_back(attr);
104 }
105
106 vector<Attribute*>& ShibbolethResolver::getResolvedAttributes()
107 {
108     return m_resolvedAttributes;
109 }
110
111 RequestMapper::Settings ShibbolethResolver::getSettings() const
112 {
113     return m_settings;
114 }
115
116 void ShibbolethResolver::resolve()
117 {
118 }
119
120 void RemotedResolver::receive(DDF& in, ostream& out)
121 {
122 }
123
124 extern "C" int SHIBRESOLVER_EXPORTS xmltooling_extension_init(void*)
125 {
126 #ifdef SHIBRESOLVER_SHIBSP_HAS_REMOTING
127     SPConfig& conf = SPConfig::getConfig();
128     if (conf.isEnabled(SPConfig::OutOfProcess) && !conf.isEnabled(SPConfig::InProcess) && conf.isEnabled(SPConfig::Listener))
129         conf.getServiceProvider()->regListener("org.project-moonshot.shibresolver", &g_Remoted);
130 #endif
131     return 0;   // signal success
132 }
133
134 extern "C" void SHIBRESOLVER_EXPORTS xmltooling_extension_term()
135 {
136     // Factories normally get unregistered during library shutdown, so no work usually required here.
137 }