mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
- The size of the object and the nature in which it is read means that it does not really fit into the clustered cache model. We just notify the cluster if the cache entry it needs to be reloaded, serving stale data for a short while - ALF-19982: BM-0013: Reindex: WebScripts registry is repeatedly reset (DeclarativeRegistry) - ALF-19983 BM-0013: Reindex: Solr reindex works very slowly git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@55415 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
107 lines
4.0 KiB
Java
107 lines
4.0 KiB
Java
package org.alfresco.rest.api;
|
|
|
|
import java.io.IOException;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
|
import org.alfresco.repo.tenant.TenantService;
|
|
import org.alfresco.repo.tenant.TenantUtil;
|
|
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
|
import org.alfresco.repo.web.scripts.TenantRepositoryContainer;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.springframework.extensions.webscripts.Authenticator;
|
|
import org.springframework.extensions.webscripts.WebScript;
|
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
|
import org.springframework.extensions.webscripts.WebScriptResponse;
|
|
import org.springframework.extensions.webscripts.servlet.WebScriptServletRuntime;
|
|
|
|
/**
|
|
* Repository (server-tier) container for public api
|
|
*
|
|
* @author steveglover
|
|
* @author davidc
|
|
*/
|
|
public class PublicApiRepositoryContainer extends TenantRepositoryContainer
|
|
{
|
|
protected static final Log logger = LogFactory.getLog(PublicApiRepositoryContainer.class);
|
|
|
|
/**
|
|
* Execute script within required level of transaction
|
|
*/
|
|
@Override
|
|
protected void transactionedExecute(final WebScript script, final WebScriptRequest scriptReq, final WebScriptResponse scriptRes)
|
|
throws IOException
|
|
{
|
|
final HttpServletRequest httpServletRequest = WebScriptServletRuntime.getHttpServletRequest(scriptReq);
|
|
if(httpServletRequest instanceof PublicApiHttpServletRequest)
|
|
{
|
|
// reset the request input stream if it has been read e.g. by getParameter
|
|
PublicApiHttpServletRequest publicApiRequest = (PublicApiHttpServletRequest)httpServletRequest;
|
|
publicApiRequest.resetInputStream();
|
|
}
|
|
|
|
super.transactionedExecute(script, scriptReq, scriptRes);
|
|
}
|
|
|
|
@Override
|
|
public void executeScript(final WebScriptRequest scriptReq, final WebScriptResponse scriptRes, final Authenticator auth)
|
|
throws IOException
|
|
{
|
|
String tenant = ((PublicApiTenantWebScriptServletRequest)scriptReq).getTenant();
|
|
if (tenant != null)
|
|
{
|
|
// handle special tenant keys
|
|
// -super- => run as system tenant
|
|
// -default- => run as user's default tenant
|
|
String user = null;
|
|
if (tenant.equalsIgnoreCase(TenantUtil.DEFAULT_TENANT))
|
|
{
|
|
// switch from default to super tenant, if not authenticated
|
|
user = AuthenticationUtil.getFullyAuthenticatedUser();
|
|
if (user == null)
|
|
{
|
|
tenant = TenantUtil.SYSTEM_TENANT;
|
|
}
|
|
}
|
|
|
|
// run as super tenant
|
|
if (tenant.equalsIgnoreCase(TenantUtil.SYSTEM_TENANT))
|
|
{
|
|
if (logger.isDebugEnabled())
|
|
{
|
|
logger.debug("executeScript (-system-): ["+user+","+tenant+"] "+scriptReq.getServicePath());
|
|
}
|
|
|
|
TenantUtil.runAsTenant(new TenantRunAsWork<Object>()
|
|
{
|
|
public Object doWork() throws Exception
|
|
{
|
|
PublicApiRepositoryContainer.super.executeScript(scriptReq, scriptRes, auth);
|
|
return null;
|
|
|
|
}
|
|
}, TenantService.DEFAULT_DOMAIN);
|
|
}
|
|
else
|
|
{
|
|
if (tenant.equalsIgnoreCase(TenantUtil.DEFAULT_TENANT))
|
|
{
|
|
tenant = tenantAdminService.getUserDomain(user);
|
|
}
|
|
|
|
// run as explicit tenant
|
|
TenantUtil.runAsTenant(new TenantRunAsWork<Object>()
|
|
{
|
|
public Object doWork() throws Exception
|
|
{
|
|
PublicApiRepositoryContainer.super.executeScript(scriptReq, scriptRes, auth);
|
|
return null;
|
|
}
|
|
}, tenant);
|
|
}
|
|
}
|
|
}
|
|
}
|