https://issues.shibboleth.net/jira/browse/SSPCPP-624
[shibboleth/cpp-sp.git] / shibsp / handler / impl / SAMLDSSessionInitiator.cpp
index 4903de4..b9e1b82 100644 (file)
@@ -1,17 +1,21 @@
-/*
- *  Copyright 2001-2010 Internet2
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
  *
- * 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
+ * UCAID licenses this file to you 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
+ * 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.
+ * 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.
  */
 
 /**
 #include "handler/AbstractHandler.h"
 #include "handler/SessionInitiator.h"
 
+#include <boost/algorithm/string.hpp>
 #include <xmltooling/XMLToolingConfig.h>
 #include <xmltooling/util/URLEncoder.h>
 
 using namespace shibsp;
 using namespace opensaml;
 using namespace xmltooling;
+using namespace boost;
 using namespace std;
 
 #ifndef SHIBSP_LITE
@@ -128,15 +134,9 @@ SAMLDSSessionInitiator::SAMLDSSessionInitiator(const DOMElement* e, const char*
 
     pair<bool,const char*> options = getString("preservedOptions");
     if (options.first) {
-        int j = 0;
         string opt = options.second;
-        for (unsigned int i = 0;  i < opt.length();  i++) {
-            if (opt.at(i) == ' ') {
-                m_preservedOptions.push_back(opt.substr(j, i-j));
-                j = i+1;
-            }
-        }
-        m_preservedOptions.push_back(opt.substr(j, opt.length()-j));
+        trim(opt);
+        split(m_preservedOptions, opt, is_space(), algorithm::token_compress_on);
     }
     else {
         m_preservedOptions.push_back("isPassive");
@@ -160,8 +160,8 @@ pair<bool,long> SAMLDSSessionInitiator::run(SPRequest& request, string& entityID
 
     string target;
     pair<bool,const char*> prop;
-    bool isPassive=false;
-    const Application& app=request.getApplication();
+    bool isPassive = false;
+    const Application& app = request.getApplication();
     pair<bool,const char*> discoveryURL = pair<bool,const char*>(true, m_url);
 
     if (isHandler) {
@@ -278,6 +278,9 @@ pair<bool,long> SAMLDSSessionInitiator::run(SPRequest& request, string& entityID
         req = req + "&returnIDParam=" + m_returnParam;
     if (isPassive)
         req += "&isPassive=true";
+    prop = getString("discoveryPolicy");
+    if (prop.first)
+        req += "&policy=" + urlenc->encode(prop.second);
 
     return make_pair(true, request.sendRedirect(req.c_str()));
 }