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:
David Caruana
2008-03-17 16:13:35 +00:00
parent e7a7290e8e
commit e18033179e
4 changed files with 150 additions and 53 deletions

View File

@@ -3,6 +3,7 @@
<description>Stream a content property from the Repository</description> <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/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/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> <authentication>guest</authentication>
<format default="">argument</format> <format default="">argument</format>
</webscript> </webscript>

View File

@@ -85,6 +85,7 @@
<property name="fileFolderService" ref="fileFolderService" /> <property name="fileFolderService" ref="fileFolderService" />
<property name="searchService" ref="searchService" /> <property name="searchService" ref="searchService" />
<property name="tenantDeployerService" ref="tenantAdminService" /> <property name="tenantDeployerService" ref="tenantAdminService" />
<property name="avmService" ref="AVMService" />
<property name="companyHomeStore"><value>${spaces.store}</value></property> <property name="companyHomeStore"><value>${spaces.store}</value></property>
<property name="companyHomePath"><value>/${spaces.company_home.childname}</value></property> <property name="companyHomePath"><value>/${spaces.company_home.childname}</value></property>
</bean> </bean>
@@ -139,7 +140,8 @@
<!-- JSR-168 Authenticator (Portal based) --> <!-- JSR-168 Authenticator (Portal based) -->
<bean id="webscripts.authenticator.jsr168" class="org.alfresco.repo.web.scripts.portlet.JSR168PortletAuthenticatorFactory"> <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>
<bean id="webscripts.authenticator.jsr168.webclient" class="org.alfresco.repo.web.scripts.portlet.WebClientPortletAuthenticatorFactory"> <bean id="webscripts.authenticator.jsr168.webclient" class="org.alfresco.repo.web.scripts.portlet.WebClientPortletAuthenticatorFactory">
<property name="repository" ref="webscripts.repo" /> <property name="repository" ref="webscripts.repo" />

View File

@@ -32,12 +32,15 @@ import java.util.Map;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.alfresco.model.ContentModel; 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;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.tenant.TenantDeployer; import org.alfresco.repo.tenant.TenantDeployer;
import org.alfresco.repo.tenant.TenantDeployerService; import org.alfresco.repo.tenant.TenantDeployerService;
import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; 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.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.model.FileNotFoundException; 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.service.namespace.NamespaceService;
import org.alfresco.util.AbstractLifecycleBean; import org.alfresco.util.AbstractLifecycleBean;
import org.alfresco.web.scripts.WebScriptException; 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.beans.BeansException;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
@@ -72,6 +77,7 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
private NodeService nodeService; private NodeService nodeService;
private FileFolderService fileFolderService; private FileFolderService fileFolderService;
private PersonService personService; private PersonService personService;
private AVMService avmService;
private TenantDeployerService tenantDeployerService; private TenantDeployerService tenantDeployerService;
// company home // company home
@@ -168,6 +174,16 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
this.tenantDeployerService = tenantDeployerService; this.tenantDeployerService = tenantDeployerService;
} }
/**
* Sets the AVM service
*
* @param avmService
*/
public void setAvmService(AVMService avmService)
{
this.avmService = avmService;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/ */
@@ -300,17 +316,41 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
* *
* Resolve to node via its display path. * 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. * 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) * @return reference array of reference segments (as described above for each reference type)
*/ */
public NodeRef findNodeRef(String referenceType, String[] reference) public NodeRef findNodeRef(String referenceType, String[] reference)
{ {
NodeRef nodeRef = null; NodeRef nodeRef = null;
if (referenceType.equals("avmpath"))
{
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);
}
}
else
{
// construct store reference // construct store reference
if (reference.length < 3) if (reference.length < 3)
{ {
@@ -329,9 +369,26 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
} }
else if (referenceType.equals("path")) else if (referenceType.equals("path"))
{
// NOTE: special case for avm based path
if (reference[0].equals(StoreRef.PROTOCOL_AVM))
{
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);
}
}
else
{ {
// TODO: Allow a root path to be specified - for now, hard-code to Company Home // TODO: Allow a root path to be specified - for now, hard-code to Company Home
// NodeRef rootNodeRef = nodeService.getRootNode(storeRef); // NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
NodeRef rootNodeRef = getCompanyHome(); NodeRef rootNodeRef = getCompanyHome();
if (reference.length == 3) if (reference.length == 3)
{ {
@@ -353,6 +410,7 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
} }
} }
} }
}
else else
{ {
@@ -360,6 +418,7 @@ public class Repository implements ApplicationContextAware, ApplicationListener,
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Web Script Node URL specified an invalid reference style of '" + referenceType + "'"); throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Web Script Node URL specified an invalid reference style of '" + referenceType + "'");
} }
} }
}
return nodeRef; return nodeRef;
} }

View File

@@ -27,9 +27,12 @@ package org.alfresco.repo.web.scripts.portlet;
import javax.portlet.RenderRequest; import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse; import javax.portlet.RenderResponse;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.transaction.UserTransaction;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.web.scripts.Authenticator; import org.alfresco.web.scripts.Authenticator;
import org.alfresco.web.scripts.WebScriptException; import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.Description.RequiredAuthentication; 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); private static final Log logger = LogFactory.getLog(JSR168PortletAuthenticatorFactory.class);
// dependencies // dependencies
private AuthenticationService authenticationService; private AuthenticationService unprotAuthenticationService;
private TransactionService txnService;
/** /**
* @param authenticationService * @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) /* (non-Javadoc)
@@ -78,7 +90,6 @@ public class JSR168PortletAuthenticatorFactory implements PortletAuthenticatorFa
{ {
// dependencies // dependencies
private RenderRequest req; private RenderRequest req;
private RenderResponse res;
/** /**
* Construct * Construct
@@ -90,7 +101,6 @@ public class JSR168PortletAuthenticatorFactory implements PortletAuthenticatorFa
public JSR168PortletAuthenticator(RenderRequest req, RenderResponse res) public JSR168PortletAuthenticator(RenderRequest req, RenderResponse res)
{ {
this.req = req; this.req = req;
this.res = res;
} }
/*(non-Javadoc) /*(non-Javadoc)
@@ -124,12 +134,37 @@ public class JSR168PortletAuthenticatorFactory implements PortletAuthenticatorFa
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Authenticating as user " + portalUser); logger.debug("Authenticating as user " + portalUser);
if (!authenticationService.authenticationExists(portalUser)) UserTransaction txn = null;
try
{
txn = txnService.getUserTransaction();
txn.begin();
if (!unprotAuthenticationService.authenticationExists(portalUser))
{ {
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "User " + portalUser + " is not a known Alfresco user"); throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "User " + portalUser + " is not a known Alfresco user");
} }
AuthenticationUtil.setCurrentUser(portalUser); 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
}
}
}
return true; return true;
} }