samlbindinclude_HEADERS = \
binding/ArtifactMap.h \
binding/MessageEncoder.h \
- binding/SAMLArtifact.h
+ binding/SAMLArtifact.h \
+ binding/URLEncoder.h
encinclude_HEADERS = \
encryption/EncryptedKeyResolver.h
SAMLConfig.cpp \
binding/impl/ArtifactMap.cpp \
binding/impl/SAMLArtifact.cpp \
+ binding/impl/URLEncoder.cpp \
saml1/core/impl/AssertionsImpl.cpp \
saml1/core/impl/AssertionsSchemaValidators.cpp \
saml1/core/impl/ProtocolsImpl.cpp \
#include "internal.h"
#include "exceptions.h"
#include "SAMLConfig.h"
+#include "binding/ArtifactMap.h"
#include "binding/MessageEncoder.h"
#include "binding/SAMLArtifact.h"
+#include "binding/URLEncoder.h"
#include "saml1/core/Assertions.h"
#include "saml1/core/Protocols.h"
#include "saml2/core/Protocols.h"
return g_config;
}
+void SAMLConfig::setArtifactMap(ArtifactMap* artifactMap)
+{
+ delete m_artifactMap;
+ m_artifactMap = artifactMap;
+}
+
+void SAMLConfig::setURLEncoder(URLEncoder* urlEncoder)
+{
+ delete m_urlEncoder;
+ m_urlEncoder = urlEncoder;
+}
+
bool SAMLInternalConfig::init(bool initXMLTooling)
{
#ifdef _DEBUG
saml2md::registerMetadataProviders();
saml2md::registerMetadataFilters();
registerTrustEngines();
+
+ m_urlEncoder = new URLEncoder();
log.info("library initialization complete");
return true;
delete m_artifactMap;
m_artifactMap = NULL;
+ delete m_urlEncoder;
+ m_urlEncoder = NULL;
if (termXMLTooling) {
XMLToolingConfig::getConfig().term();
#define __saml_config_h__\r
\r
#include <saml/base.h>\r
-#include <saml/binding/ArtifactMap.h>\r
\r
#include <xmltooling/PluginManager.h>\r
#include <xmltooling/XMLToolingConfig.h>\r
*/\r
namespace opensaml {\r
\r
+ class SAML_API ArtifactMap;\r
class SAML_API MessageEncoder;\r
class SAML_API MessageDecoder;\r
class SAML_API SAMLArtifact;\r
class SAML_API TrustEngine;\r
+ class SAML_API URLEncoder;\r
\r
namespace saml2md {\r
class SAML_API MetadataProvider;\r
* \r
* @param artifactMap new ArtifactMap instance to store\r
*/\r
- void setArtifactMap(ArtifactMap* artifactMap) {\r
- delete m_artifactMap;\r
- m_artifactMap = artifactMap;\r
- }\r
+ void setArtifactMap(ArtifactMap* artifactMap);\r
\r
/**\r
* Returns the global ArtifactMap instance.\r
ArtifactMap* getArtifactMap() const {\r
return m_artifactMap;\r
}\r
+\r
+ /**\r
+ * Sets the global URLEncoder instance.\r
+ * This method must be externally synchronized with any code that uses the object.\r
+ * Any previously set object is destroyed.\r
+ * \r
+ * @param urlEncoder new URLEncoder instance to store\r
+ */\r
+ void setURLEncoder(URLEncoder* urlEncoder);\r
+ \r
+ /**\r
+ * Returns the global URLEncoder instance.\r
+ * \r
+ * @return global URLEncoder\r
+ */\r
+ URLEncoder* getURLEncoder() const {\r
+ return m_urlEncoder;\r
+ }\r
\r
/**\r
* Generate random information using the underlying security library\r
xmltooling::PluginManager<saml2md::MetadataFilter,const DOMElement*> MetadataFilterManager;\r
\r
protected:\r
- SAMLConfig() : m_artifactMap(NULL) {}\r
+ SAMLConfig() : m_artifactMap(NULL), m_urlEncoder(NULL) {}\r
\r
/** Global ArtifactMap instance for use by artifact-related functions. */\r
ArtifactMap* m_artifactMap;\r
+\r
+ /** Global URLEncoder instance for use by URL-related functions. */\r
+ URLEncoder* m_urlEncoder;\r
};\r
\r
#if defined (_MSC_VER)\r
virtual ~MessageEncoder() {}\r
\r
/**\r
- * Interface to caller-supplied URL-encoding mechanism.\r
- * \r
- * Since URL-encoding is not canonical, it's important that the same\r
- * encoder is used during some binding-specific signature operations.\r
- */\r
- class SAML_API URLEncoder {\r
- MAKE_NONCOPYABLE(URLEncoder);\r
- protected:\r
- URLEncoder() {}\r
- public:\r
- virtual ~URLEncoder() {}\r
- \r
- /**\r
- * Produce a URL-safe but equivalent version of the input string.\r
- * \r
- * @param s input string to encode\r
- * @return a string object containing the result of encoding the input\r
- */\r
- virtual std::string encode(const char* s) const=0;\r
- };\r
- \r
- /**\r
- * Provides a URLEncoder implementation for the MessageEncoder to use.\r
- * The implementation's lifetime must be longer than the lifetime of this object.\r
- * This method must be externally synchronized. \r
- * \r
- * @param urlEncoder a URLEncoder implementation to use\r
- */\r
- void setURLEncoder(const URLEncoder* urlEncoder) {\r
- m_urlEncoder = urlEncoder;\r
- }\r
-\r
- /**\r
* Interface to caller-supplied artifact generation mechanism.\r
* \r
* Generating an artifact for storage and retrieval requires knowledge of\r
) const=0;\r
\r
protected:\r
- MessageEncoder() : m_urlEncoder(NULL), m_artifactGenerator(NULL) {}\r
+ MessageEncoder() : m_artifactGenerator(NULL) {}\r
\r
/**\r
* Helper function to build a new XML Signature with KeyInfo, based\r
const XMLCh* sigAlgorithm=NULL\r
) const;\r
\r
- /** Pointer to a URLEncoder implementation. */\r
- const URLEncoder* m_urlEncoder;\r
- \r
/** Pointer to an ArtifactGenerator implementation. */\r
const ArtifactGenerator* m_artifactGenerator;\r
};\r
--- /dev/null
+/*\r
+ * Copyright 2001-2006 Internet2\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/**\r
+ * @file saml/binding/URLEncoder.h\r
+ * \r
+ * Interface to a URL-encoding mechanism along with a\r
+ * default implementation.\r
+ */\r
+\r
+#ifndef __saml_urlenc_h__\r
+#define __saml_urlenc_h__\r
+\r
+#include <saml/base.h>\r
+\r
+namespace opensaml {\r
+ /**\r
+ * Interface to a URL-encoding mechanism along with a default implementation.\r
+ * \r
+ * Since URL-encoding is not canonical, it's important that the same\r
+ * encoder is used during some library operations and the calling code.\r
+ * Applications can supply an alternative implementation to the library\r
+ * if required.\r
+ */\r
+ class SAML_API URLEncoder {\r
+ MAKE_NONCOPYABLE(URLEncoder);\r
+ public:\r
+ URLEncoder() {}\r
+ virtual ~URLEncoder() {}\r
+ \r
+ /**\r
+ * Produce a URL-safe but equivalent version of the input string.\r
+ * \r
+ * @param s input string to encode\r
+ * @return a string object containing the result of encoding the input\r
+ */\r
+ virtual std::string encode(const char* s) const;\r
+ \r
+ /**\r
+ * Perform an in-place decoding operation on the input string.\r
+ * The resulting string will be NULL-terminated.\r
+ * \r
+ * @param s input string to decode in a writable buffer\r
+ */\r
+ virtual void decode(char* s) const;\r
+ \r
+ protected:\r
+ /**\r
+ * Returns true iff the input character requires encoding.\r
+ * \r
+ * @param ch the character to check\r
+ * @return true iff the character should be encoded \r
+ */\r
+ virtual bool isBad(char ch) const {\r
+ static char badchars[]="=&/?:\"\\+<>#%{}|^~[]`;@";\r
+ return (strchr(badchars,ch) || ch<=0x20 || ch>=0x7F);\r
+ }\r
+ };\r
+};\r
+\r
+#endif /* __saml_urlenc_h__ */\r
--- /dev/null
+/*
+ * Copyright 2001-2006 Internet2
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * URLEncoder.cpp
+ *
+ * Interface to a URL-encoding mechanism along with a
+ * default implementation.
+ */
+
+#include "internal.h"
+#include "binding/URLEncoder.h"
+
+using namespace opensaml;
+using namespace std;
+
+static char x2c(char *what)
+{
+ register char digit;
+
+ digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
+ digit *= 16;
+ digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
+ return(digit);
+}
+
+void URLEncoder::decode(char* s) const
+{
+ register int x,y;
+
+ for(x=0,y=0;s[y];++x,++y)
+ {
+ if((s[x] = s[y]) == '%')
+ {
+ s[x] = x2c(&s[y+1]);
+ y+=2;
+ }
+ else if (s[x] == '+')
+ {
+ s[x] = ' ';
+ }
+ }
+ s[x] = '\0';
+}
+
+static inline char hexchar(unsigned short s)
+{
+ return (s<=9) ? ('0' + s) : ('A' + s - 10);
+}
+
+string URLEncoder::encode(const char* s) const
+{
+ string ret;
+ for (; *s; s++) {
+ if (isBad(*s)) {
+ ret+='%';
+ ret+=hexchar(*s >> 4);
+ ret+=hexchar(*s & 0x0F);
+ }
+ else
+ ret+=*s;
+ }
+ return ret;
+}
RelativePath=".\binding\impl\SAMLArtifact.cpp"\r
>\r
</File>\r
+ <File\r
+ RelativePath=".\binding\impl\URLEncoder.cpp"\r
+ >\r
+ </File>\r
</Filter>\r
</Filter>\r
</Filter>\r
RelativePath=".\binding\SAMLArtifact.h"\r
>\r
</File>\r
+ <File\r
+ RelativePath=".\binding\URLEncoder.h"\r
+ >\r
+ </File>\r
</Filter>\r
</Filter>\r
<Filter\r
#include "internal.h"
#include "exceptions.h"
+#include "saml/binding/ArtifactMap.h"
#include "saml/binding/SAMLArtifact.h"
#include "saml1/binding/SAML1ArtifactEncoder.h"
#include "saml1/core/Assertions.h"
#include "internal.h"
#include "exceptions.h"
+#include "saml/binding/ArtifactMap.h"
#include "saml2/binding/SAML2Artifact.h"
#include "saml2/binding/SAML2ArtifactEncoder.h"
#include "saml2/core/Protocols.h"