Implement basic methods, add subclass for the guts.
[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 ResolverImpl : public ShibbolethResolver, public Remoted {
39     public:
40         ResolverImpl() {}
41         ~ResolverImpl() {}
42
43         void resolve();
44         void receive(DDF& in, ostream& out);
45     };
46 };
47
48 ShibbolethResolver* ShibbolethResolver::create()
49 {
50     return new ResolverImpl();
51 }
52
53 ShibbolethResolver::ShibbolethResolver()
54 {
55 }
56
57 ShibbolethResolver::~ShibbolethResolver()
58 {
59     for_each(m_resolvedAttributes.begin(), m_resolvedAttributes.end(), xmltooling::cleanup<Attribute>());
60     if (m_mapper)
61         m_mapper->unlock();
62     if (m_sp)
63         m_sp->unlock();
64 }
65
66 void ShibbolethResolver::setServiceURI(const char* uri)
67 {
68     m_serviceURI.erase();
69     if (uri)
70         m_serviceURI = uri;
71 }
72
73 void ShibbolethResolver::setApplicationID(const char* appID)
74 {
75     m_appID.erase();
76     if (appID)
77         m_appID = appID;
78 }
79
80 void ShibbolethResolver::setIssuer(const char* issuer)
81 {
82     m_issuer.erase();
83     if (issuer)
84         m_issuer = issuer;
85 }
86
87 void ShibbolethResolver::addToken(
88 #ifdef SHIBSP_LITE
89         const XMLObject* token
90 #else
91         const saml2::Assertion* token
92 #endif
93     )
94 {
95     if (token)
96         m_tokens.push_back(token);
97 }
98
99 void ShibbolethResolver::addAttribute(Attribute* attr)
100 {
101     if (attr)
102         m_inputAttributes.push_back(attr);
103 }
104
105 vector<Attribute*>& ShibbolethResolver::getResolvedAttributes()
106 {
107     return m_resolvedAttributes;
108 }
109
110 RequestMapper::Settings ShibbolethResolver::getSettings() const
111 {
112     return m_settings;
113 }
114
115 void ResolverImpl::resolve()
116 {
117 }
118
119 void ResolverImpl::receive(DDF& in, ostream& out)
120 {
121 }
122
123 extern "C" int SHIBRESOLVER_EXPORTS xmltooling_extension_init(void*)
124 {
125     // Register factory functions with appropriate plugin managers in the XMLTooling/SAML/SPConfig objects.
126     return 0;   // signal success
127 }
128
129 extern "C" void SHIBRESOLVER_EXPORTS xmltooling_extension_term()
130 {
131     // Factories normally get unregistered during library shutdown, so no work usually required here.
132 }