From 1b466e3f127025d67db9c964d12c30736f5143b0 Mon Sep 17 00:00:00 2001 From: Jan Vonka Date: Fri, 4 Jan 2008 11:59:02 +0000 Subject: [PATCH] MT - put back tenant username functionality MIA after dialog conversion (NewUserWizard -> CreateUserWizard) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7752 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../web/bean/users/CreateUserWizard.java | 55 +++++++++++++++++++ source/web/WEB-INF/faces-config-beans.xml | 10 +++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/source/java/org/alfresco/web/bean/users/CreateUserWizard.java b/source/java/org/alfresco/web/bean/users/CreateUserWizard.java index 0223c4cf31..9237ffa493 100644 --- a/source/java/org/alfresco/web/bean/users/CreateUserWizard.java +++ b/source/java/org/alfresco/web/bean/users/CreateUserWizard.java @@ -40,6 +40,8 @@ import javax.faces.validator.ValidatorException; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ApplicationModel; import org.alfresco.model.ContentModel; +import org.alfresco.repo.security.authentication.AuthenticationException; +import org.alfresco.repo.tenant.TenantService; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.AuthenticationService; @@ -95,6 +97,9 @@ public class CreateUserWizard extends BaseWizardBean /** PersonService bean reference */ private PersonService personService; + + /** TenantService bean reference */ + private TenantService tenantService; /** PermissionService bean reference */ private PermissionService permissionService; @@ -127,6 +132,14 @@ public class CreateUserWizard extends BaseWizardBean { this.personService = personService; } + + /** + * @param tenantService The tenantService to set. + */ + public void setTenantService(TenantService tenantService) + { + this.tenantService = tenantService; + } /** * @param permissionService The PermissionService to set. @@ -185,6 +198,18 @@ public class CreateUserWizard extends BaseWizardBean */ public String getSummary() { + if (tenantService.isEnabled()) + { + try + { + checkTenantUserName(); + } + catch (Exception e) + { + // TODO - ignore for now, but ideally should handle earlier + } + } + ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance()); String homeSpaceLabel = this.homeSpaceName; @@ -682,6 +707,11 @@ public class CreateUserWizard extends BaseWizardBean { if (this.password.equals(this.confirm)) { + if (tenantService.isEnabled()) + { + checkTenantUserName(); + } + // create properties for Person type from submitted Form data Map props = new HashMap(7, 1.0f); props.put(ContentModel.PROP_USERNAME, this.userName); @@ -814,4 +844,29 @@ public class CreateUserWizard extends BaseWizardBean } return new Pair(size, units); } + + protected void checkTenantUserName() + { + String currentDomain = tenantService.getCurrentUserDomain(); + if (currentDomain != null) + { + if (! tenantService.isTenantUser(this.userName)) + { + // force domain onto the end of the username + this.userName = tenantService.getDomainUser(this.userName, currentDomain); + logger.warn("Added domain to username: " + this.userName); + } + else + { + try + { + tenantService.checkDomainUser(this.userName); + } + catch (RuntimeException re) + { + throw new AuthenticationException("User must belong to same domain as admin: " + currentDomain); + } + } + } + } } diff --git a/source/web/WEB-INF/faces-config-beans.xml b/source/web/WEB-INF/faces-config-beans.xml index f8217cdd3a..3c0df3d285 100644 --- a/source/web/WEB-INF/faces-config-beans.xml +++ b/source/web/WEB-INF/faces-config-beans.xml @@ -4387,6 +4387,10 @@ personService #{PersonService} + + + tenantService + #{tenantService} ownableService @@ -4438,7 +4442,11 @@ personService #{PersonService} - + + + tenantService + #{tenantService} + ownableService #{OwnableService}