Tenant Services hooks for WebClient - for getting tenant-specific company home/root space [not guest*servlets yet]

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6645 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2007-08-30 15:59:07 +00:00
parent 7c238af116
commit 4c657db443
9 changed files with 848 additions and 719 deletions

View File

@@ -49,6 +49,7 @@ import org.alfresco.web.bean.ErrorBean;
import org.alfresco.web.bean.SidebarBean;
import org.alfresco.web.bean.dashboard.DashboardManager;
import org.alfresco.web.bean.dialog.DialogManager;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.User;
import org.alfresco.web.bean.wizard.WizardManager;
import org.alfresco.web.config.ClientConfigElement;
@@ -312,7 +313,9 @@ public class Application
}
/**
* @return Returns id of the company root
* @return Returns id of the company root
*
* @deprecated Replace with user-context-specific getCompanyRootId (e.g. could be tenant-specific)
*/
public static String getCompanyRootId()
{
@@ -323,12 +326,37 @@ public class Application
* Sets the company root id. This is setup by the ContextListener.
*
* @param id The company root id
*
* @deprecated Replace with user-context-specific getCompanyRootId (e.g. could be tenant-specific)
*/
public static void setCompanyRootId(String id)
{
companyRootId = id;
}
/**
* @return Returns id of the company root
*/
public static String getCompanyRootId(FacesContext context)
{
User user = Application.getCurrentUser(context);
if (user != null)
{
String userCompanyRootId = user.getCompanyRootId();
if (userCompanyRootId == null)
{
userCompanyRootId = Repository.getCompanyRoot(context).getId();
user.setCompanyRootId(userCompanyRootId);
}
return userCompanyRootId;
}
else
{
return null;
}
}
/**
* @return Returns the root path for the application
*/

View File

@@ -25,7 +25,6 @@
package org.alfresco.web.app;
import java.util.Enumeration;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
@@ -49,8 +48,6 @@ import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.User;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
@@ -93,33 +90,14 @@ public class ContextListener implements ServletContextListener, HttpSessionListe
tx.begin();
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
// get and setup the initial store ref from config
// get and setup the initial store ref and root path from config
StoreRef storeRef = Repository.getStoreRef(servletContext);
// check the repository exists, create if it doesn't
if (nodeService.exists(storeRef) == false)
{
throw new AlfrescoRuntimeException("Store not created prior to application startup: " + storeRef);
}
// get hold of the root node
NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
// see if the company home space is present
// get root path
String rootPath = Application.getRootPath(servletContext);
if (rootPath == null)
{
throw new AlfrescoRuntimeException("Root path has not been configured");
}
List<NodeRef> nodes = searchService.selectNodes(rootNodeRef, rootPath, null, namespaceService, false);
if (nodes.size() == 0)
{
throw new AlfrescoRuntimeException("Root path not created prior to application startup: " + rootPath);
}
// Extract company space id and store it in the Application object
companySpaceNodeRef = nodes.get(0);
companySpaceNodeRef = Repository.getCompanyRoot(nodeService, searchService, namespaceService, storeRef, rootPath);
Application.setCompanyRootId(companySpaceNodeRef.getId());
// commit the transaction

View File

@@ -1371,10 +1371,11 @@ public class BrowseBean implements IContextListener
Node node = getActionSpace();
if (node != null)
{
NodeRef companyRootRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId());
FacesContext fc = FacesContext.getCurrentInstance();
NodeRef companyRootRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc));
if (node.getNodeRef().equals(companyRootRef))
{
message = Application.getMessage(FacesContext.getCurrentInstance(), MSG_DELETE_COMPANYROOT);
message = Application.getMessage(fc, MSG_DELETE_COMPANYROOT);
}
}

View File

@@ -574,10 +574,11 @@ public class NavigationBean
}
catch (InvalidNodeRefException refErr)
{
FacesContext fc = FacesContext.getCurrentInstance();
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), ERROR_DELETED_FOLDER), new Object[] {this.currentNodeId}) );
fc, ERROR_DELETED_FOLDER), new Object[] {this.currentNodeId}) );
nodeRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId());
nodeRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc));
node = new Node(nodeRef);
props = node.getProperties();
}
@@ -679,8 +680,13 @@ public class NavigationBean
{
if (this.companyHomeNode == null)
{
NodeRef companyRootRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId());
this.companyHomeNode = new Node(companyRootRef);
FacesContext fc = FacesContext.getCurrentInstance();
String companyRootId = Application.getCompanyRootId(fc);
if (companyRootId != null)
{
NodeRef companyRootRef = new NodeRef(Repository.getStoreRef(), companyRootId);
this.companyHomeNode = new Node(companyRootRef);
}
}
return this.companyHomeNode;
}
@@ -721,7 +727,15 @@ public class NavigationBean
*/
public boolean getCompanyHomeVisible()
{
return getCompanyHomeNode().hasPermission(PermissionService.READ);
Node companyHomeNode = getCompanyHomeNode();
if (companyHomeNode != null)
{
return companyHomeNode.hasPermission(PermissionService.READ);
}
else
{
return false;
}
}
/**

View File

@@ -321,12 +321,12 @@ public class NavigatorPluginBean implements IContextListener
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
FacesContext fc = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(fc, true);
tx.begin();
// query for the child nodes of company home
NodeRef root = new NodeRef(Repository.getStoreRef(),
Application.getCompanyRootId());
NodeRef root = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc));
List<ChildAssociationRef> childRefs = this.nodeService.getChildAssocs(root,
ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);

File diff suppressed because it is too large Load Diff

View File

@@ -49,6 +49,7 @@ import org.alfresco.web.app.Application;
*/
public final class User
{
private String companyRootId;
private String homeSpaceId;
private String userName;
private String ticket;
@@ -128,6 +129,22 @@ public final class User
this.homeSpaceId = homeSpaceId;
}
/**
* @return Retrieves the company home space
*/
public String getCompanyRootId()
{
return this.companyRootId;
}
/**
* @param companyRootId Sets the id of the company home space
*/
public void setCompanyRootId(String companyRootId)
{
this.companyRootId = companyRootId;
}
/**
* @return Returns the ticket.
*/

View File

@@ -41,6 +41,8 @@ import javax.transaction.UserTransaction;
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.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -101,6 +103,9 @@ public class NewUserWizard extends AbstractWizardBean
/** PersonService bean reference */
private PersonService personService;
/** TenantService bean reference */
private TenantService tenantService;
/** OwnableService bean reference */
private OwnableService ownableService;
@@ -154,6 +159,14 @@ public class NewUserWizard extends AbstractWizardBean
{
this.ownableService = ownableService;
}
/**
* @param tenantService The tenantService to set.
*/
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
/**
* Initialises the wizard
@@ -474,6 +487,31 @@ public class NewUserWizard extends AbstractWizardBean
}
else
{
if (tenantService.isEnabled())
{
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);
}
}
}
}
if (this.password.equals(this.confirm))
{
// create properties for Person type from submitted Form data
@@ -840,18 +878,7 @@ public class NewUserWizard extends AbstractWizardBean
{
if (this.companyHomeSpaceRef == null)
{
String companyXPath = Application.getRootPath(FacesContext.getCurrentInstance());
NodeRef rootNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
List<NodeRef> nodes = this.searchService.selectNodes(rootNodeRef, companyXPath, null, this.namespaceService,
false);
if (nodes.size() == 0)
{
throw new IllegalStateException("Unable to find company home space path: " + companyXPath);
}
this.companyHomeSpaceRef = nodes.get(0);
this.companyHomeSpaceRef = Repository.getCompanyRoot(FacesContext.getCurrentInstance());
}
return this.companyHomeSpaceRef;

View File

@@ -66,7 +66,7 @@ public class UISpaceSelector extends AbstractItemSelector
{
String id = null;
if (this.navigationId != null && this.navigationId.equals(Application.getCompanyRootId()) == false)
if (this.navigationId != null && this.navigationId.equals(Application.getCompanyRootId(context)) == false)
{
try
{
@@ -107,7 +107,7 @@ public class UISpaceSelector extends AbstractItemSelector
public Collection<NodeRef> getRootChildren(FacesContext context)
{
NodeRef rootRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId());
NodeRef rootRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(context));
// get a child association reference back from the parent node to satisfy
// the generic API we have in the abstract super class