cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [3/8] git commit: updated refs/heads/saml2 to 24b43f8
Date Mon, 25 Aug 2014 00:00:31 GMT
saml: use values from config for user account, domain and redirected url

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/86dfe138
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/86dfe138
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/86dfe138

Branch: refs/heads/saml2
Commit: 86dfe13865e5af039b48afbc9809ebbaaf0f98f1
Parents: 2932e14
Author: Rohit Yadav <rohit.yadav@shapeblue.com>
Authored: Mon Aug 25 01:03:05 2014 +0200
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Mon Aug 25 01:03:05 2014 +0200

----------------------------------------------------------------------
 .../command/SAML2LoginAPIAuthenticatorCmd.java  | 29 ++++++++++++++++++--
 1 file changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/86dfe138/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java
b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java
index 88acfe1..e1d95ef 100644
--- a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java
+++ b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java
@@ -18,8 +18,11 @@
 package org.apache.cloudstack.api.command;
 
 import com.cloud.api.response.ApiResponseSerializer;
+import com.cloud.configuration.Config;
+import com.cloud.domain.Domain;
 import com.cloud.exception.CloudAuthenticationException;
 import com.cloud.user.Account;
+import com.cloud.user.DomainManager;
 import com.cloud.user.User;
 import com.cloud.utils.HttpUtils;
 import com.cloud.utils.db.EntityManager;
@@ -35,6 +38,7 @@ import org.apache.cloudstack.api.auth.APIAuthenticator;
 import org.apache.cloudstack.api.auth.PluggableAPIAuthenticator;
 import org.apache.cloudstack.api.response.LoginCmdResponse;
 import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.saml.SAML2AuthManager;
 import org.apache.cloudstack.utils.auth.SAMLUtils;
 import org.apache.log4j.Logger;
@@ -84,6 +88,10 @@ public class SAML2LoginAPIAuthenticatorCmd extends BaseCmd implements APIAuthent
     ApiServerService _apiServer;
     @Inject
     EntityManager _entityMgr;
+    @Inject
+    ConfigurationDao _configDao;
+    @Inject
+    private DomainManager _domainMgr;
 
     SAML2AuthManager _samlAuthManager;
 
@@ -186,8 +194,23 @@ public class SAML2LoginAPIAuthenticatorCmd extends BaseCmd implements
APIAuthent
                 }
 
                 String uniqueUserId = null;
-                String accountName = "admin"; //GET from config, try, fail
-                Long domainId = 1L; // GET from config, try, fail
+                String accountName = _configDao.getValue(Config.SAMLUserAccountName.key());
+                String domainString = _configDao.getValue(Config.SAMLUserDomain.key());
+
+                Long domainId = -1L;
+                Domain domain = _domainMgr.getDomain(domainString);
+                if (domain != null) {
+                    domainId = domain.getId();
+                } else {
+                    try {
+                        domainId = Long.parseLong(domainString);
+                    } catch (NumberFormatException ignore) {
+                    }
+                }
+                if (domainId == -1L) {
+                    s_logger.error("The default domain ID for SAML users is not set correct,
it should be a UUID");
+                }
+
                 String username = null;
                 String password = "";
                 String firstName = "";
@@ -246,7 +269,7 @@ public class SAML2LoginAPIAuthenticatorCmd extends BaseCmd implements
APIAuthent
                             resp.addCookie(new Cookie("account", URLEncoder.encode(loginResponse.getAccount(),
HttpUtils.UTF_8)));
                             resp.addCookie(new Cookie("timezone", URLEncoder.encode(loginResponse.getTimeZone(),
HttpUtils.UTF_8)));
                             resp.addCookie(new Cookie("userfullname", loginResponse.getFirstName()
+ "%20" + loginResponse.getLastName()));
-                            resp.sendRedirect("http://localhost:8080/client");
+                            resp.sendRedirect(_configDao.getValue(Config.SAMLCloudStackRedirectionUrl.key()));
                             return ApiResponseSerializer.toSerializedString(loginResponse,
responseType);
 
                         }


Mime
View raw message