]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-22: Clean up of current tenant determination code.
authorRay Lee <rhlee@berkeley.edu>
Wed, 20 Jul 2016 00:32:49 +0000 (17:32 -0700)
committerRay Lee <rhlee@berkeley.edu>
Fri, 22 Jul 2016 23:48:10 +0000 (16:48 -0700)
services/JaxRsServiceProvider/src/main/webapp/WEB-INF/applicationContext-security.xml
services/authentication/service/src/main/java/org/collectionspace/authentication/AuthN.java
services/authentication/service/src/main/java/org/collectionspace/authentication/CSpaceUser.java
services/authentication/service/src/main/java/org/collectionspace/authentication/spi/AuthNContext.java
services/authentication/service/src/main/java/org/collectionspace/authentication/spring/SpringAuthNContext.java

index 45837ed38630ee5db12017e90d708a97bc756d26..614ac2c3c0fe3ae8916408f7244de5b9df44faed 100644 (file)
@@ -72,8 +72,8 @@
                         <entry key="dsJndiName" value="CspaceDS" />
                         <entry key="principalsQuery" value="select passwd from users where username=?" />
                         <entry key="rolesQuery" value="select r.rolename from roles as r, accounts_roles as ar where ar.user_id=? and ar.role_id=r.csid" />
-                        <entry key="tenantsQueryWithDisabled" value="select t.id, t.name from accounts_common as a, accounts_tenants as at, tenants as t where a.userid=? and a.csid = at.TENANTS_ACCOUNTS_COMMON_CSID and at.tenant_id = t.id" />
-                        <entry key="tenantsQueryNoDisabled" value="select t.id, t.name from accounts_common as a, accounts_tenants as at, tenants as t where a.userid=? and a.csid = at.TENANTS_ACCOUNTS_COMMON_CSID and at.tenant_id = t.id and NOT t.disabled" />
+                        <entry key="tenantsQueryWithDisabled" value="select t.id, t.name from accounts_common as a, accounts_tenants as at, tenants as t where a.userid=? and a.csid = at.TENANTS_ACCOUNTS_COMMON_CSID and at.tenant_id = t.id order by t.id" />
+                        <entry key="tenantsQueryNoDisabled" value="select t.id, t.name from accounts_common as a, accounts_tenants as at, tenants as t where a.userid=? and a.csid = at.TENANTS_ACCOUNTS_COMMON_CSID and at.tenant_id = t.id and NOT t.disabled order by t.id" />
                         <entry key="maxRetrySeconds" value="5000" />
                         <entry key="delayBetweenAttemptsMillis" value="200" />
                     </util:map>
index d5e043f70d7ca52f7b878b3b5c6f8a4837a8212d..5cf351b12af3af859e88a6a45d04fe6a8c229ee3 100644 (file)
@@ -49,8 +49,6 @@
  */
 package org.collectionspace.authentication;
 
-import java.util.List;
-
 import javax.sql.DataSource;
 
 import org.collectionspace.authentication.spi.AuthNContext;
@@ -108,14 +106,6 @@ public class AuthN {
         return authnContext.getUserId();
     }
 
-    /**
-     * getTenantIds returns a list of tenant ids the user is associated with
-     * @return
-     */
-    public List<String> getTenantIds() {
-        return authnContext.getTenantIds();
-    }
-
     public String getCurrentTenantId() {
         return authnContext.getCurrentTenantId();
     }
@@ -123,13 +113,4 @@ public class AuthN {
     public String getCurrentTenantName() {
         return authnContext.getCurrentTenantName();
     }
-
-    /**
-     * getTenants returns tenants associated with user
-     * @see CSpaceTenant
-     * @return
-     */
-    public List<CSpaceTenant> getTenants() {
-        return authnContext.getTenants();
-    }
 }
index c7093402d9c807512129e57abc887ea82a9fd719..8cdd002c657cf8eabe114ea73abfd534badc9aca 100644 (file)
@@ -19,6 +19,7 @@ public class CSpaceUser extends User {
     private static final long serialVersionUID = 3326192720134327612L;
 
     private Set<CSpaceTenant> tenants;
+    private CSpaceTenant primaryTenant;
     
     /**
      * Creates a CSpaceUser with the given username, hashed password, associated
@@ -41,6 +42,10 @@ public class CSpaceUser extends User {
                 authorities);
 
         this.tenants = tenants;
+        
+        if (!tenants.isEmpty()) {
+            primaryTenant = tenants.iterator().next();
+        }
     }
 
     /**
@@ -51,4 +56,14 @@ public class CSpaceUser extends User {
     public Set<CSpaceTenant> getTenants() {
         return tenants;
     }
+    
+    /**
+     * Retrieves the primary tenant associated with the user.
+     * 
+     * @return the tenants
+     */
+    public CSpaceTenant getPrimaryTenant() {
+        return primaryTenant;
+    }
+    
 }
index 600aabcdc68a90d6f2cd07c764a5dd261d9df9c0..c8c911a11412c4977d89845e479844558bda25eb 100644 (file)
@@ -24,8 +24,6 @@
  */
 package org.collectionspace.authentication.spi;
 
-import java.util.List;
-
 import org.collectionspace.authentication.CSpaceTenant;
 import org.collectionspace.authentication.CSpaceUser;
 
@@ -76,17 +74,4 @@ public interface AuthNContext {
      */
     public CSpaceTenant getCurrentTenant();
 
-    /**
-     * Returns all tenants associated with the authenticated user.
-     * 
-     * @return a list of tenants
-     */
-    public List<CSpaceTenant> getTenants();
-
-    /**
-     * Returns the ids of all tenants associated with the authenticated user.
-     * 
-     * @return a list of tenant ids
-     */
-    public List<String> getTenantIds();
 }
index 36b50674eda812b79df984b52d8e6ea36605db66..11af775097df4a6cee68f1f4435f9adcfe13d46c 100644 (file)
@@ -23,9 +23,6 @@
  */
 package org.collectionspace.authentication.spring;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.collectionspace.authentication.CSpaceTenant;
 import org.collectionspace.authentication.CSpaceUser;
 import org.collectionspace.authentication.spi.AuthNContext;
@@ -43,15 +40,13 @@ public class SpringAuthNContext implements AuthNContext {
      * @return the username
      */
     public String getUserId() {
-        String result = ANONYMOUS_USER;
-        
         Authentication authToken = SecurityContextHolder.getContext().getAuthentication();
         
-        if (authToken != null) {
-            result = authToken.getName();
+        if (authToken == null) {
+            return ANONYMOUS_USER;
         }
         
-        return result;
+        return authToken.getName();
     }
 
     /**
@@ -101,37 +96,6 @@ public class SpringAuthNContext implements AuthNContext {
      * @return the tenant
      */
     public CSpaceTenant getCurrentTenant() {
-        List<CSpaceTenant> tenants = getTenants();
-        
-        if (tenants.size() < 1) {
-            throw new IllegalStateException("No tenant associated with user " + getUserId());
-        }
-        
-        return tenants.get(0);
-    }
-
-    /**
-     * Returns all tenants associated with the authenticated user.
-     * 
-     * @return a list of tenants
-     */
-    public List<CSpaceTenant> getTenants() {
-        return new ArrayList<CSpaceTenant>(getUser().getTenants());
-    }
-
-    /**
-     * Returns the ids of all tenants associated with the authenticated user.
-     * 
-     * @return a list of tenant ids
-     */
-    public List<String> getTenantIds() {
-        List<CSpaceTenant> tenants = getTenants();
-        List<String> tenantIds = new ArrayList<String>(tenants.size());
-        
-        for (CSpaceTenant tenant : tenants) {
-            tenantIds.add(tenant.getId());
-        }
-        
-        return tenantIds;
+        return getUser().getPrimaryTenant();
     }
 }