mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fixed ALF-11201: CMIS ignores user login and runs as 'admin' sometimes
- Change the way the CMIS implementation interacts with authentication, logging and transactions by constructing a service layered in three interceptors: <property name="cmisTransactions" ref="CMISService_Transactions" /> <property name="cmisExceptions" ref="CMISService_Exceptions" /> <property name="cmisControl" ref="CMISService_Control" /> - CMISService_Transactions: Retrying transactions are initiated for all operations and we no longer attempt to hold transactions open across method calls. This optimization is secondary to having full retrying behaviour, without which the server could throw avoidable exceptions in concurrent environments. - CMISService_Exceptions: Performs translation from typical repo exceptions into CMIS exceptions - CMISService_Control: Provides details logging of inbound authentication states, arguments, exceptions and return values To get logging without method arguments (can be verbose): log4j.logger.org.alfresco.opencmis.AlfrescoCmisServiceInterceptor=DEBUG To include method call arguments: log4j.logger.org.alfresco.opencmis.AlfrescoCmisServiceInterceptor=TRACE Logging will include details of inbound, method-call and outbound thread authentication credentials. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32331 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -20,26 +20,30 @@ package org.alfresco.opencmis;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionInterceptor;
|
||||
import org.apache.chemistry.opencmis.commons.impl.server.AbstractServiceFactory;
|
||||
import org.apache.chemistry.opencmis.commons.server.CallContext;
|
||||
import org.apache.chemistry.opencmis.commons.server.CmisService;
|
||||
import org.apache.chemistry.opencmis.server.support.CmisServiceWrapper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
|
||||
/**
|
||||
* Factory for OpenCMIS service objects.
|
||||
*
|
||||
* @author florian.mueller
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class AlfrescoCmisServiceFactory extends AbstractServiceFactory
|
||||
{
|
||||
private ThreadLocal<CmisServiceWrapper<AlfrescoCmisService>> threadLocalService = new ThreadLocal<CmisServiceWrapper<AlfrescoCmisService>>();
|
||||
|
||||
private static final Log logger = LogFactory.getLog(AlfrescoCmisServiceFactory.class);
|
||||
|
||||
private CMISConnector connector;
|
||||
|
||||
@Override
|
||||
public void init(Map<String, String> parameters)
|
||||
{
|
||||
}
|
||||
private RetryingTransactionInterceptor cmisTransactions;
|
||||
private AlfrescoCmisExceptionInterceptor cmisExceptions;
|
||||
private AlfrescoCmisServiceInterceptor cmisControl;
|
||||
|
||||
/**
|
||||
* Sets the CMIS connector.
|
||||
@@ -49,26 +53,75 @@ public class AlfrescoCmisServiceFactory extends AbstractServiceFactory
|
||||
this.connector = connector;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cmisTransactions the interceptor that applies appropriate transactions
|
||||
*/
|
||||
public void setCmisTransactions(RetryingTransactionInterceptor cmisTransactions)
|
||||
{
|
||||
this.cmisTransactions = cmisTransactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cmisExceptions interceptor to translate exceptions
|
||||
*/
|
||||
public void setCmisExceptions(AlfrescoCmisExceptionInterceptor cmisExceptions)
|
||||
{
|
||||
this.cmisExceptions = cmisExceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cmisControl interceptor that provides logging and authentication checks
|
||||
*/
|
||||
public void setCmisControl(AlfrescoCmisServiceInterceptor cmisControl)
|
||||
{
|
||||
this.cmisControl = cmisControl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Map<String, String> parameters)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
threadLocalService = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
* We are producing new instances each time.
|
||||
*/
|
||||
@Override
|
||||
public CmisService getService(CallContext context)
|
||||
{
|
||||
CmisServiceWrapper<AlfrescoCmisService> wrapperService = threadLocalService.get();
|
||||
if (wrapperService == null)
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
wrapperService = new CmisServiceWrapper<AlfrescoCmisService>(new AlfrescoCmisService(connector),
|
||||
connector.getTypesDefaultMaxItems(), connector.getTypesDefaultDepth(),
|
||||
connector.getObjectsDefaultMaxItems(), connector.getObjectsDefaultDepth());
|
||||
threadLocalService.set(wrapperService);
|
||||
logger.debug("\n" +
|
||||
"CMIS getService(): \n" +
|
||||
" Authenticated as: " + AuthenticationUtil.getFullyAuthenticatedUser() + "\n" +
|
||||
" Running as: " + AuthenticationUtil.getRunAsUser() + "\n" +
|
||||
" User: " + context.getUsername() + "\n" +
|
||||
" Repo: " + context.getRepositoryId());
|
||||
}
|
||||
|
||||
AlfrescoCmisService cmisServiceTarget = new AlfrescoCmisServiceImpl(connector);
|
||||
|
||||
// Wrap it
|
||||
ProxyFactory proxyFactory = new ProxyFactory(cmisServiceTarget);
|
||||
proxyFactory.addInterface(AlfrescoCmisService.class);
|
||||
proxyFactory.addAdvice(cmisExceptions);
|
||||
proxyFactory.addAdvice(cmisControl);
|
||||
proxyFactory.addAdvice(cmisTransactions);
|
||||
AlfrescoCmisService cmisService = (AlfrescoCmisService) proxyFactory.getProxy();
|
||||
|
||||
CmisServiceWrapper<CmisService> wrapperService = new CmisServiceWrapper<CmisService>(
|
||||
cmisService,
|
||||
connector.getTypesDefaultMaxItems(), connector.getTypesDefaultDepth(),
|
||||
connector.getObjectsDefaultMaxItems(), connector.getObjectsDefaultDepth());
|
||||
|
||||
wrapperService.getWrappedService().beginCall(context);
|
||||
|
||||
// We use our specific open method here because only we know about it
|
||||
cmisService.open(context);
|
||||
|
||||
return wrapperService;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user