<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>
*/
package org.collectionspace.authentication;
-import java.util.List;
-
import javax.sql.DataSource;
import org.collectionspace.authentication.spi.AuthNContext;
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();
}
public String getCurrentTenantName() {
return authnContext.getCurrentTenantName();
}
-
- /**
- * getTenants returns tenants associated with user
- * @see CSpaceTenant
- * @return
- */
- public List<CSpaceTenant> getTenants() {
- return authnContext.getTenants();
- }
}
private static final long serialVersionUID = 3326192720134327612L;
private Set<CSpaceTenant> tenants;
+ private CSpaceTenant primaryTenant;
/**
* Creates a CSpaceUser with the given username, hashed password, associated
authorities);
this.tenants = tenants;
+
+ if (!tenants.isEmpty()) {
+ primaryTenant = tenants.iterator().next();
+ }
}
/**
public Set<CSpaceTenant> getTenants() {
return tenants;
}
+
+ /**
+ * Retrieves the primary tenant associated with the user.
+ *
+ * @return the tenants
+ */
+ public CSpaceTenant getPrimaryTenant() {
+ return primaryTenant;
+ }
+
}
*/
package org.collectionspace.authentication.spi;
-import java.util.List;
-
import org.collectionspace.authentication.CSpaceTenant;
import org.collectionspace.authentication.CSpaceUser;
*/
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();
}
*/
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;
* @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();
}
/**
* @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();
}
}