mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -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;
|
||||
@@ -313,6 +314,8 @@ public class Application
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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,9 +680,14 @@ public class NavigationBean
|
||||
{
|
||||
if (this.companyHomeNode == null)
|
||||
{
|
||||
NodeRef companyRootRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -42,6 +42,9 @@ import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.encoding.ContentCharsetFinder;
|
||||
import org.alfresco.repo.content.metadata.MetadataExtracter;
|
||||
import org.alfresco.repo.content.metadata.MetadataExtracterRegistry;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.lock.LockService;
|
||||
@@ -123,6 +126,67 @@ public final class Repository
|
||||
return storeRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a company root node reference object.
|
||||
*
|
||||
* @return The NodeRef object
|
||||
*/
|
||||
public static NodeRef getCompanyRoot(final FacesContext context)
|
||||
{
|
||||
// note: run in context of System user using tenant-specific store
|
||||
// so that Company Root can be returned, even if the user does not have
|
||||
// permission to access the Company Root (including, for example, the Guest user)
|
||||
return AuthenticationUtil.runAs(new RunAsWork<NodeRef>()
|
||||
{
|
||||
public NodeRef doWork() throws Exception
|
||||
{
|
||||
ServiceRegistry sr = getServiceRegistry(context);
|
||||
|
||||
TenantService tenantService = (TenantService)FacesContextUtils.getRequiredWebApplicationContext(context).getBean("tenantService");
|
||||
|
||||
// get store ref (from config)
|
||||
StoreRef storeRef = tenantService.getName(Repository.getStoreRef());
|
||||
|
||||
// get root path (from config)
|
||||
String rootPath = Application.getRootPath(context);
|
||||
|
||||
return getCompanyRoot(sr.getNodeService(), sr.getSearchService(), sr.getNamespaceService(), storeRef, rootPath);
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a company root node reference object.
|
||||
*
|
||||
* @return The NodeRef object
|
||||
*/
|
||||
public static NodeRef getCompanyRoot(NodeService nodeService, SearchService searchService, NamespaceService namespaceService, StoreRef storeRef, String rootPath)
|
||||
{
|
||||
// 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
|
||||
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);
|
||||
}
|
||||
|
||||
// return company root
|
||||
return nodes.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get the display name for a Node.
|
||||
* The method will attempt to use the "name" attribute, if not found it will revert to using
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
@@ -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;
|
||||
@@ -102,6 +104,9 @@ public class NewUserWizard extends AbstractWizardBean
|
||||
/** PersonService bean reference */
|
||||
private PersonService personService;
|
||||
|
||||
/** TenantService bean reference */
|
||||
private TenantService tenantService;
|
||||
|
||||
/** OwnableService bean reference */
|
||||
private OwnableService ownableService;
|
||||
|
||||
@@ -155,6 +160,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;
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user