mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V2.2 to HEAD
8077: Merged V2.1 to V2.2 8021: Fix for AWC-1799 see ACT 959 8023: Fix AR-1977 - /api/path/content web script doesn't work with AVM stores 8024: Fix for AWC-1799 (now using TXN wrapper) see ACT 959 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8545 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
<description>Stream a content property from the Repository</description>
|
||||
<url>/api/node/content{property}/{store_type}/{store_id}/{node_id}?a={attach?}</url>
|
||||
<url>/api/path/content{property}/{store_type}/{store_id}/{path}?a={attach?}</url>
|
||||
<url>/api/avmpath/content{property}/{store_id}/{path}?a={attach?}</url>
|
||||
<authentication>guest</authentication>
|
||||
<format default="">argument</format>
|
||||
</webscript>
|
@@ -85,6 +85,7 @@
|
||||
<property name="fileFolderService" ref="fileFolderService" />
|
||||
<property name="searchService" ref="searchService" />
|
||||
<property name="tenantDeployerService" ref="tenantAdminService" />
|
||||
<property name="avmService" ref="AVMService" />
|
||||
<property name="companyHomeStore"><value>${spaces.store}</value></property>
|
||||
<property name="companyHomePath"><value>/${spaces.company_home.childname}</value></property>
|
||||
</bean>
|
||||
@@ -139,7 +140,8 @@
|
||||
|
||||
<!-- JSR-168 Authenticator (Portal based) -->
|
||||
<bean id="webscripts.authenticator.jsr168" class="org.alfresco.repo.web.scripts.portlet.JSR168PortletAuthenticatorFactory">
|
||||
<property name="authenticationService" ref="AuthenticationService" />
|
||||
<property name="unprotAuthenticationService" ref="authenticationService" />
|
||||
<property name="transactionService" ref="TransactionService" />
|
||||
</bean>
|
||||
<bean id="webscripts.authenticator.jsr168.webclient" class="org.alfresco.repo.web.scripts.portlet.WebClientPortletAuthenticatorFactory">
|
||||
<property name="repository" ref="webscripts.repo" />
|
||||
|
@@ -32,12 +32,15 @@ import java.util.Map;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.tenant.TenantDeployer;
|
||||
import org.alfresco.repo.tenant.TenantDeployerService;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
||||
import org.alfresco.service.cmr.avm.AVMService;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.model.FileNotFoundException;
|
||||
@@ -49,6 +52,8 @@ import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.util.AbstractLifecycleBean;
|
||||
import org.alfresco.web.scripts.WebScriptException;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
@@ -72,6 +77,7 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
|
||||
private NodeService nodeService;
|
||||
private FileFolderService fileFolderService;
|
||||
private PersonService personService;
|
||||
private AVMService avmService;
|
||||
private TenantDeployerService tenantDeployerService;
|
||||
|
||||
// company home
|
||||
@@ -168,6 +174,16 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
|
||||
this.tenantDeployerService = tenantDeployerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the AVM service
|
||||
*
|
||||
* @param avmService
|
||||
*/
|
||||
public void setAvmService(AVMService avmService)
|
||||
{
|
||||
this.avmService = avmService;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
|
||||
*/
|
||||
@@ -300,65 +316,108 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
|
||||
*
|
||||
* Resolve to node via its display path.
|
||||
*
|
||||
* 3) QName - {store_type}/{store_id}/{child_qname_path} TODO: Implement
|
||||
* 3) AVM Path - {store_id}/{path}
|
||||
*
|
||||
* Resolve to AVM node via its display path
|
||||
*
|
||||
* 4) QName - {store_type}/{store_id}/{child_qname_path} TODO: Implement
|
||||
*
|
||||
* Resolve to node via its child qname path.
|
||||
*
|
||||
* @param referenceType one of node, path or qname
|
||||
* @param referenceType one of node, path, avmpath or qname
|
||||
* @return reference array of reference segments (as described above for each reference type)
|
||||
*/
|
||||
public NodeRef findNodeRef(String referenceType, String[] reference)
|
||||
{
|
||||
NodeRef nodeRef = null;
|
||||
|
||||
// construct store reference
|
||||
if (reference.length < 3)
|
||||
if (referenceType.equals("avmpath"))
|
||||
{
|
||||
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Reference " + Arrays.toString(reference) + " is not properly formed");
|
||||
if (reference.length == 0)
|
||||
{
|
||||
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Reference " + Arrays.toString(reference) + " is not properly formed");
|
||||
}
|
||||
String path = reference[0] + ":/";
|
||||
if (reference.length > 1)
|
||||
{
|
||||
Object[] pathElements = ArrayUtils.subarray(reference, 1, reference.length);
|
||||
path += StringUtils.join(pathElements, "/");
|
||||
}
|
||||
AVMNodeDescriptor nodeDesc = avmService.lookup(-1, path);
|
||||
if (nodeDesc != null)
|
||||
{
|
||||
nodeRef = AVMNodeConverter.ToNodeRef(-1, path);
|
||||
}
|
||||
}
|
||||
StoreRef storeRef = new StoreRef(reference[0], reference[1]);
|
||||
if (nodeService.exists(storeRef))
|
||||
else
|
||||
{
|
||||
if (referenceType.equals("node"))
|
||||
{
|
||||
NodeRef urlRef = new NodeRef(storeRef, reference[2]);
|
||||
if (nodeService.exists(urlRef))
|
||||
{
|
||||
nodeRef = urlRef;
|
||||
}
|
||||
}
|
||||
// construct store reference
|
||||
if (reference.length < 3)
|
||||
{
|
||||
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Reference " + Arrays.toString(reference) + " is not properly formed");
|
||||
}
|
||||
StoreRef storeRef = new StoreRef(reference[0], reference[1]);
|
||||
if (nodeService.exists(storeRef))
|
||||
{
|
||||
if (referenceType.equals("node"))
|
||||
{
|
||||
NodeRef urlRef = new NodeRef(storeRef, reference[2]);
|
||||
if (nodeService.exists(urlRef))
|
||||
{
|
||||
nodeRef = urlRef;
|
||||
}
|
||||
}
|
||||
|
||||
else if (referenceType.equals("path"))
|
||||
{
|
||||
// TODO: Allow a root path to be specified - for now, hard-code to Company Home
|
||||
// NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
|
||||
NodeRef rootNodeRef = getCompanyHome();
|
||||
if (reference.length == 3)
|
||||
{
|
||||
nodeRef = rootNodeRef;
|
||||
}
|
||||
else
|
||||
{
|
||||
String[] path = new String[reference.length - /*2*/3];
|
||||
System.arraycopy(reference, /*2*/3, path, 0, path.length);
|
||||
|
||||
try
|
||||
else if (referenceType.equals("path"))
|
||||
{
|
||||
// NOTE: special case for avm based path
|
||||
if (reference[0].equals(StoreRef.PROTOCOL_AVM))
|
||||
{
|
||||
FileInfo fileInfo = fileFolderService.resolveNamePath(rootNodeRef, Arrays.asList(path));
|
||||
nodeRef = fileInfo.getNodeRef();
|
||||
String path = reference[1] + ":/";
|
||||
if (reference.length > 2)
|
||||
{
|
||||
Object[] pathElements = ArrayUtils.subarray(reference, 2, reference.length);
|
||||
path += StringUtils.join(pathElements, "/");
|
||||
}
|
||||
AVMNodeDescriptor nodeDesc = avmService.lookup(-1, path);
|
||||
if (nodeDesc != null)
|
||||
{
|
||||
nodeRef = AVMNodeConverter.ToNodeRef(-1, path);
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
else
|
||||
{
|
||||
// NOTE: return null node ref
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: Allow a root path to be specified - for now, hard-code to Company Home
|
||||
// NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
|
||||
NodeRef rootNodeRef = getCompanyHome();
|
||||
if (reference.length == 3)
|
||||
{
|
||||
nodeRef = rootNodeRef;
|
||||
}
|
||||
else
|
||||
{
|
||||
String[] path = new String[reference.length - /*2*/3];
|
||||
System.arraycopy(reference, /*2*/3, path, 0, path.length);
|
||||
|
||||
else
|
||||
{
|
||||
// TODO: Implement 'qname' style
|
||||
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Web Script Node URL specified an invalid reference style of '" + referenceType + "'");
|
||||
}
|
||||
try
|
||||
{
|
||||
FileInfo fileInfo = fileFolderService.resolveNamePath(rootNodeRef, Arrays.asList(path));
|
||||
nodeRef = fileInfo.getNodeRef();
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
// NOTE: return null node ref
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// TODO: Implement 'qname' style
|
||||
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Web Script Node URL specified an invalid reference style of '" + referenceType + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nodeRef;
|
||||
|
@@ -27,9 +27,12 @@ package org.alfresco.repo.web.scripts.portlet;
|
||||
import javax.portlet.RenderRequest;
|
||||
import javax.portlet.RenderResponse;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.web.scripts.Authenticator;
|
||||
import org.alfresco.web.scripts.WebScriptException;
|
||||
import org.alfresco.web.scripts.Description.RequiredAuthentication;
|
||||
@@ -50,14 +53,23 @@ public class JSR168PortletAuthenticatorFactory implements PortletAuthenticatorFa
|
||||
private static final Log logger = LogFactory.getLog(JSR168PortletAuthenticatorFactory.class);
|
||||
|
||||
// dependencies
|
||||
private AuthenticationService authenticationService;
|
||||
private AuthenticationService unprotAuthenticationService;
|
||||
private TransactionService txnService;
|
||||
|
||||
/**
|
||||
* @param authenticationService
|
||||
*/
|
||||
public void setAuthenticationService(AuthenticationService authenticationService)
|
||||
public void setUnprotAuthenticationService(AuthenticationService authenticationService)
|
||||
{
|
||||
this.authenticationService = authenticationService;
|
||||
this.unprotAuthenticationService = authenticationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param transactionService
|
||||
*/
|
||||
public void setTransactionService(TransactionService transactionService)
|
||||
{
|
||||
this.txnService = transactionService;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -78,7 +90,6 @@ public class JSR168PortletAuthenticatorFactory implements PortletAuthenticatorFa
|
||||
{
|
||||
// dependencies
|
||||
private RenderRequest req;
|
||||
private RenderResponse res;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
@@ -90,7 +101,6 @@ public class JSR168PortletAuthenticatorFactory implements PortletAuthenticatorFa
|
||||
public JSR168PortletAuthenticator(RenderRequest req, RenderResponse res)
|
||||
{
|
||||
this.req = req;
|
||||
this.res = res;
|
||||
}
|
||||
|
||||
/*(non-Javadoc)
|
||||
@@ -124,11 +134,36 @@ public class JSR168PortletAuthenticatorFactory implements PortletAuthenticatorFa
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Authenticating as user " + portalUser);
|
||||
|
||||
if (!authenticationService.authenticationExists(portalUser))
|
||||
UserTransaction txn = null;
|
||||
try
|
||||
{
|
||||
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "User " + portalUser + " is not a known Alfresco user");
|
||||
txn = txnService.getUserTransaction();
|
||||
txn.begin();
|
||||
|
||||
if (!unprotAuthenticationService.authenticationExists(portalUser))
|
||||
{
|
||||
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "User " + portalUser + " is not a known Alfresco user");
|
||||
}
|
||||
AuthenticationUtil.setCurrentUser(portalUser);
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Error authenticating user: " + portalUser, err);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (txn != null)
|
||||
{
|
||||
txn.rollback();
|
||||
}
|
||||
}
|
||||
catch (Exception tex)
|
||||
{
|
||||
// nothing useful we can do with this
|
||||
}
|
||||
}
|
||||
AuthenticationUtil.setCurrentUser(portalUser);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user