NameID decoder.
[shibboleth/cpp-sp.git] / shibsp / attribute / Attribute.cpp
1 /*
2  *  Copyright 2001-2007 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  * shibsp/attribute/Attribute.cpp
19  * 
20  * A resolved attribute.
21  */
22
23 #include "internal.h"
24 #include "attribute/AttributeDecoder.h"
25 #include "attribute/SimpleAttribute.h"
26 #include "attribute/ScopedAttribute.h"
27 #include "attribute/NameIDAttribute.h"
28
29 #include <shibsp/SPConfig.h>
30
31 using namespace shibsp;
32 using namespace xmltooling;
33 using namespace std;
34
35 namespace shibsp {
36
37     SHIBSP_DLLLOCAL Attribute* SimpleAttributeFactory(DDF& in) {
38         return new SimpleAttribute(in);
39     }
40     
41     SHIBSP_DLLLOCAL Attribute* ScopedAttributeFactory(DDF& in) {
42         return new ScopedAttribute(in);
43     }
44     
45     SHIBSP_DLLLOCAL Attribute* NameIDAttributeFactory(DDF& in) {
46         return new NameIDAttribute(in);
47     }
48     
49     SHIBSP_DLLLOCAL PluginManager<AttributeDecoder,const DOMElement*>::Factory SimpleAttributeDecoderFactory;
50     SHIBSP_DLLLOCAL PluginManager<AttributeDecoder,const DOMElement*>::Factory ScopedAttributeDecoderFactory;
51     SHIBSP_DLLLOCAL PluginManager<AttributeDecoder,const DOMElement*>::Factory NameIDAttributeDecoderFactory;
52 };
53
54 void shibsp::registerAttributeDecoders()
55 {
56     SPConfig& conf = SPConfig::getConfig();
57     conf.AttributeDecoderManager.registerFactory(SIMPLE_ATTRIBUTE_DECODER, SimpleAttributeDecoderFactory);
58     conf.AttributeDecoderManager.registerFactory(SCOPED_ATTRIBUTE_DECODER, ScopedAttributeDecoderFactory);
59     conf.AttributeDecoderManager.registerFactory(NAMEID_ATTRIBUTE_DECODER, NameIDAttributeDecoderFactory);
60 }
61
62 void shibsp::registerAttributeFactories()
63 {
64     Attribute::registerFactory("", SimpleAttributeFactory);
65     Attribute::registerFactory("Simple", SimpleAttributeFactory);
66     Attribute::registerFactory("Scoped", ScopedAttributeFactory);
67     Attribute::registerFactory("NameID", NameIDAttributeFactory);
68 }
69
70 std::map<std::string,Attribute::AttributeFactory*> Attribute::m_factoryMap;
71
72 Attribute* Attribute::unmarshall(DDF& in)
73 {
74     map<string,AttributeFactory*>::const_iterator i = m_factoryMap.find(in.name() ? in.name() : "");
75     if (i == m_factoryMap.end())
76         throw AttributeException("No registered factory for Attribute of type ($1).", xmltooling::params(1,in.name()));
77     return (i->second)(in);
78 }