mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
77158: Merged PLATFORM1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 74123: ACE-1802 "MT / Cloud Restrict namespace URI of dynamic models." ACE-955 "Custom Content Models in Cloud" More build fixes: enforce tenant in model namespace restriction on Cloud only, remove unused test class, ensure correct initialisation of CMIS dictionary, make new Cloud dictionary tests run in a separate VM git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@78016 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -723,12 +723,13 @@
|
|||||||
<property name="tenantService" ref="tenantService"/>
|
<property name="tenantService" ref="tenantService"/>
|
||||||
<property name="tenantAdminService" ref="tenantAdminService"/>
|
<property name="tenantAdminService" ref="tenantAdminService"/>
|
||||||
<property name="searchService" ref="searchService"/>
|
<property name="searchService" ref="searchService"/>
|
||||||
<property name="storeUrls">
|
<property name="storeUrls">
|
||||||
<list>
|
<list>
|
||||||
<value>${spaces.store}</value>
|
<value>${spaces.store}</value>
|
||||||
<value>${spaces.archive.store}</value>
|
<value>${spaces.archive.store}</value>
|
||||||
</list>
|
</list>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="enforceTenantInNamespace" value="${models.enforceTenantInNamespace}"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="dictionaryDAO" class="org.alfresco.repo.dictionary.DictionaryDAOImpl">
|
<bean id="dictionaryDAO" class="org.alfresco.repo.dictionary.DictionaryDAOImpl">
|
||||||
|
@@ -48,10 +48,16 @@ public class ModelValidatorImpl implements ModelValidator
|
|||||||
private TenantService tenantService;
|
private TenantService tenantService;
|
||||||
private TenantAdminService tenantAdminService;
|
private TenantAdminService tenantAdminService;
|
||||||
private SearchService searchService;
|
private SearchService searchService;
|
||||||
|
private boolean enforceTenantInNamespace = false;
|
||||||
|
|
||||||
private List<String> storeUrls; // stores against which model deletes should be validated
|
private List<String> storeUrls; // stores against which model deletes should be validated
|
||||||
|
|
||||||
public void setStoreUrls(List<String> storeUrls)
|
public void setEnforceTenantInNamespace(boolean enforceTenantInNamespace)
|
||||||
|
{
|
||||||
|
this.enforceTenantInNamespace = enforceTenantInNamespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoreUrls(List<String> storeUrls)
|
||||||
{
|
{
|
||||||
this.storeUrls = storeUrls;
|
this.storeUrls = storeUrls;
|
||||||
}
|
}
|
||||||
@@ -88,7 +94,7 @@ public class ModelValidatorImpl implements ModelValidator
|
|||||||
|
|
||||||
private void checkCustomModelNamespace(M2Model model, String tenantDomain)
|
private void checkCustomModelNamespace(M2Model model, String tenantDomain)
|
||||||
{
|
{
|
||||||
if(tenantDomain != null && !tenantDomain.equals(""))
|
if(tenantDomain != null && !tenantDomain.equals("") && enforceTenantInNamespace)
|
||||||
{
|
{
|
||||||
// check only for "real" tenants
|
// check only for "real" tenants
|
||||||
for(M2Namespace namespace : model.getNamespaces())
|
for(M2Namespace namespace : model.getNamespaces())
|
||||||
|
@@ -1,191 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
|
||||||
*
|
|
||||||
* This file is part of Alfresco
|
|
||||||
*
|
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package org.alfresco.repo.dictionary;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
|
||||||
import org.alfresco.opencmis.AlfrescoCmisServiceFactory;
|
|
||||||
import org.alfresco.opencmis.CMISTest.SimpleCallContext;
|
|
||||||
import org.alfresco.opencmis.dictionary.CMISDictionaryService;
|
|
||||||
import org.alfresco.repo.tenant.TenantUtil;
|
|
||||||
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
|
||||||
import org.alfresco.service.cmr.model.FileFolderService;
|
|
||||||
import org.alfresco.service.cmr.model.FileInfo;
|
|
||||||
import org.alfresco.service.cmr.model.FileNotFoundException;
|
|
||||||
import org.alfresco.service.cmr.repository.ContentService;
|
|
||||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
|
||||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
|
||||||
import org.alfresco.service.namespace.QName;
|
|
||||||
import org.alfresco.util.PropertyMap;
|
|
||||||
import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
|
|
||||||
import org.apache.chemistry.opencmis.commons.server.CallContext;
|
|
||||||
import org.apache.chemistry.opencmis.commons.server.CmisService;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author sglover
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration(locations={"classpath:alfresco/application-context.xml"})
|
|
||||||
public class DictionaryDAOIntegrationTest
|
|
||||||
{
|
|
||||||
public static final String TEST_RESOURCE_MESSAGES = "alfresco/messages/dictionary-messages";
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private DictionaryService service;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private DictionaryDAOImpl dictionaryDAO;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CMISDictionaryService cmisDictionaryService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ApplicationContext applicationContext;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private AlfrescoCmisServiceFactory factory;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NodeService nodeService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FileFolderService fileFolderService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ContentService contentService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PersonService personService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MutableAuthenticationService authenticationService;
|
|
||||||
|
|
||||||
private String tenant1;
|
|
||||||
private String tenant1Username1;
|
|
||||||
|
|
||||||
private void createUser(final String tenant, final String userName,
|
|
||||||
final String firstName, final String lastName)
|
|
||||||
{
|
|
||||||
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public Void doWork() throws Exception
|
|
||||||
{
|
|
||||||
if(!authenticationService.authenticationExists(userName))
|
|
||||||
{
|
|
||||||
authenticationService.createAuthentication(userName, "password".toCharArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!personService.personExists(userName))
|
|
||||||
{
|
|
||||||
PropertyMap ppOne = new PropertyMap(5);
|
|
||||||
ppOne.put(ContentModel.PROP_USERNAME, userName);
|
|
||||||
ppOne.put(ContentModel.PROP_FIRSTNAME, firstName);
|
|
||||||
ppOne.put(ContentModel.PROP_LASTNAME, lastName);
|
|
||||||
ppOne.put(ContentModel.PROP_EMAIL, "email@email.com");
|
|
||||||
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
|
|
||||||
|
|
||||||
personService.createPerson(ppOne);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, tenant);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void before()
|
|
||||||
{
|
|
||||||
this.tenant1 = "tenant1";
|
|
||||||
this.tenant1Username1 = "user" + System.currentTimeMillis();
|
|
||||||
|
|
||||||
createUser(tenant1, tenant1Username1, tenant1Username1, tenant1Username1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addCustomModelToRepository(M2Model customModel)
|
|
||||||
throws UnsupportedEncodingException, FileNotFoundException
|
|
||||||
{
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
customModel.toXML(out);
|
|
||||||
String modelContent = out.toString("UTF-8");
|
|
||||||
NodeRef rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
|
|
||||||
FileInfo info = fileFolderService.resolveNamePath(rootNodeRef, Arrays.asList(""));
|
|
||||||
NodeRef modelsNodeRef = info.getNodeRef();
|
|
||||||
FileInfo fileInfo = fileFolderService.create(
|
|
||||||
modelsNodeRef, "contentModel" + System.currentTimeMillis() + ".xml",
|
|
||||||
ContentModel.TYPE_DICTIONARY_MODEL);
|
|
||||||
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
|
|
||||||
properties.put(ContentModel.PROP_MODEL_ACTIVE, Boolean.TRUE);
|
|
||||||
nodeService.setProperties(fileInfo.getNodeRef(), properties);
|
|
||||||
ContentWriter writer = contentService.getWriter(fileInfo.getNodeRef(), ContentModel.PROP_CONTENT, true);
|
|
||||||
writer.putContent(modelContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test1()
|
|
||||||
{
|
|
||||||
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public Void doWork() throws Exception
|
|
||||||
{
|
|
||||||
M2Model customModel = M2Model.createModel(
|
|
||||||
Thread.currentThread().getContextClassLoader().
|
|
||||||
getResourceAsStream("dictionary/dictionarytest_model1.xml"));
|
|
||||||
addCustomModelToRepository(customModel);
|
|
||||||
|
|
||||||
CallContext context = new SimpleCallContext("user1", "admin", CmisVersion.CMIS_1_1);
|
|
||||||
|
|
||||||
CmisService cmisService = factory.getService(context);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
assertNotNull(cmisService.getTypeDefinition(tenant1, "D:cm:type1", null));
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
cmisService.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, tenant1Username1, tenant1);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user