Fix backslashes in SHIBSP_PREFIX variable by manually creating it during the script...
[shibboleth/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 "SPConfig.h"
25 #ifndef SHIBSP_LITE
26 # include "attribute/AttributeDecoder.h"
27 #endif
28 #include "attribute/SimpleAttribute.h"
29 #include "attribute/ScopedAttribute.h"
30 #include "attribute/NameIDAttribute.h"
31 #include "util/SPConstants.h"
32
33 #include <xercesc/util/XMLUniDefs.hpp>
34
35 using namespace shibsp;
36 using namespace xmltooling;
37 using namespace std;
38
39 namespace shibsp {
40
41     SHIBSP_DLLLOCAL Attribute* SimpleAttributeFactory(DDF& in) {
42         return new SimpleAttribute(in);
43     }
44     
45     SHIBSP_DLLLOCAL Attribute* ScopedAttributeFactory(DDF& in) {
46         return new ScopedAttribute(in);
47     }
48     
49     SHIBSP_DLLLOCAL Attribute* NameIDAttributeFactory(DDF& in) {
50         return new NameIDAttribute(in);
51     }
52     
53 #ifndef SHIBSP_LITE
54     SHIBSP_DLLLOCAL PluginManager<AttributeDecoder,QName,const DOMElement*>::Factory StringAttributeDecoderFactory;
55     SHIBSP_DLLLOCAL PluginManager<AttributeDecoder,QName,const DOMElement*>::Factory ScopedAttributeDecoderFactory;
56     SHIBSP_DLLLOCAL PluginManager<AttributeDecoder,QName,const DOMElement*>::Factory NameIDAttributeDecoderFactory;
57
58     static const XMLCh _StringAttributeDecoder[] = UNICODE_LITERAL_22(S,t,r,i,n,g,A,t,t,r,i,b,u,t,e,D,e,c,o,d,e,r);
59     static const XMLCh _ScopedAttributeDecoder[] = UNICODE_LITERAL_22(S,c,o,p,e,d,A,t,t,r,i,b,u,t,e,D,e,c,o,d,e,r);
60     static const XMLCh _NameIDAttributeDecoder[] = UNICODE_LITERAL_22(N,a,m,e,I,D,A,t,t,r,i,b,u,t,e,D,e,c,o,d,e,r);
61
62     static const XMLCh caseSensitive[] =           UNICODE_LITERAL_13(c,a,s,e,S,e,n,s,i,t,i,v,e);
63 #endif
64 };
65
66 #ifndef SHIBSP_LITE
67 QName shibsp::StringAttributeDecoderType(shibspconstants::SHIB2ATTRIBUTEMAP_NS, _StringAttributeDecoder);
68 QName shibsp::ScopedAttributeDecoderType(shibspconstants::SHIB2ATTRIBUTEMAP_NS, _ScopedAttributeDecoder);
69 QName shibsp::NameIDAttributeDecoderType(shibspconstants::SHIB2ATTRIBUTEMAP_NS, _NameIDAttributeDecoder);
70
71 void shibsp::registerAttributeDecoders()
72 {
73     SPConfig& conf = SPConfig::getConfig();
74     conf.AttributeDecoderManager.registerFactory(StringAttributeDecoderType, StringAttributeDecoderFactory);
75     conf.AttributeDecoderManager.registerFactory(ScopedAttributeDecoderType, ScopedAttributeDecoderFactory);
76     conf.AttributeDecoderManager.registerFactory(NameIDAttributeDecoderType, NameIDAttributeDecoderFactory);
77 }
78
79 AttributeDecoder::AttributeDecoder(const DOMElement *e) : m_caseSensitive(true)
80 {
81     if (e) {
82         const XMLCh* flag = e->getAttributeNS(NULL,caseSensitive);
83         if (flag && (*flag == chLatin_f || *flag == chDigit_0))
84             m_caseSensitive = false;
85     }
86 }
87 #endif
88
89 void shibsp::registerAttributeFactories()
90 {
91     Attribute::registerFactory("", SimpleAttributeFactory);
92     Attribute::registerFactory("Simple", SimpleAttributeFactory);
93     Attribute::registerFactory("Scoped", ScopedAttributeFactory);
94     Attribute::registerFactory("NameID", NameIDAttributeFactory);
95 }
96
97 std::map<std::string,Attribute::AttributeFactory*> Attribute::m_factoryMap;
98
99 Attribute* Attribute::unmarshall(DDF& in)
100 {
101     map<string,AttributeFactory*>::const_iterator i = m_factoryMap.find(in.name() ? in.name() : "");
102     if (i == m_factoryMap.end())
103         throw AttributeException("No registered factory for Attribute of type ($1).", xmltooling::params(1,in.name()));
104     return (i->second)(in);
105 }