mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD-QA to HEAD (4.2) (including moving test classes into separate folders)
51903 to 54309 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
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
|
||||
*
|
||||
* @param scriptReq
|
||||
* @param scriptRes
|
||||
* @throws IOException
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.RuntimeContainer#executeScript(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse, org.alfresco.web.scripts.Authenticator)
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user