MT - fixes for new MT interceptor (create/login tenant admin, get stores)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10995 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2008-09-23 22:48:08 +00:00
parent f65ad654b2
commit 40e706f14f
7 changed files with 154 additions and 33 deletions

View File

@@ -44,6 +44,7 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
@@ -213,6 +214,35 @@ public class MultiTDemoTest extends TestCase
}
}
public void testLoginUsers() throws Throwable
{
logger.info("Login demo users");
try
{
AuthenticationUtil.clearCurrentSecurityContext();
for (final String tenantDomain : tenants)
{
loginLogoutUser(tenantService.getDomainUser(TEST_USER1, tenantDomain), "welcome");
loginLogoutUser(tenantService.getDomainUser(TEST_USER2, tenantDomain), "welcome");
if (tenantDomain.equals(TEST_TENANT_DOMAIN2))
{
loginLogoutUser(tenantService.getDomainUser(TEST_USER3, tenantDomain), "welcome");
}
}
}
catch (Throwable t)
{
StringWriter stackTrace = new StringWriter();
t.printStackTrace(new PrintWriter(stackTrace));
System.err.println(stackTrace.toString());
throw t;
}
}
public void testCreateGroups()
{
logger.info("Create demo groups");
@@ -355,6 +385,28 @@ public class MultiTDemoTest extends TestCase
}
}
public void testGetStores()
{
logger.info("Get tenant stores");
// super tenant
assertTrue("Super tenant: ", (nodeService.getStores().size() >= 5));
for (final String tenantDomain : tenants)
{
String tenantAdminName = tenantService.getDomainUser(TenantService.ADMIN_BASENAME, tenantDomain);
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
public Object doWork() throws Exception
{
assertEquals("Tenant: "+tenantDomain, 5, nodeService.getStores().size());
return null;
}
}, tenantAdminName);
}
}
private void createGroup(String shortName, String parentShortName)
{
@@ -417,6 +469,26 @@ public class MultiTDemoTest extends TestCase
}
}
private void loginLogoutUser(String username, String password)
{
// authenticate via the authentication service
authenticationService.authenticate(username, password.toCharArray());
// set the user name as stored by the back end
username = authenticationService.getCurrentUserName();
NodeRef homeSpaceRef = (NodeRef)nodeService.getProperty(personService.getPerson(username), ContentModel.PROP_HOMEFOLDER);
// check that the home space node exists - else user cannot login
if (nodeService.exists(homeSpaceRef) == false)
{
throw new InvalidNodeRefException(homeSpaceRef);
}
// logout
authenticationService.clearCurrentSecurityContext();
}
private NodeRef getUserHomesNodeRef(StoreRef storeRef)
{
// get the users' home location

View File

@@ -108,9 +108,11 @@ public class MultiTNodeServiceInterceptor extends DelegatingIntroductionIntercep
return invocation.proceed();
}
String methodName = invocation.getMethod().getName();
if (logger.isDebugEnabled())
{
logger.debug("Intercepting method " + invocation.getMethod().getName());
logger.debug("Intercepting method " + methodName);
}
Object[] args = invocation.getArguments();
@@ -162,8 +164,49 @@ public class MultiTNodeServiceInterceptor extends DelegatingIntroductionIntercep
// Make the call
Object ret = invocation.proceed();
// Convert the outbound value
ret = convertOutboundValue(ret);
if (methodName.equals("getStores"))
{
if ((ret == null) || (! (ret instanceof List)))
{
return null;
}
List<StoreRef> rawValues = (List<StoreRef>)ret;
final List<StoreRef> convertedValues = new ArrayList<StoreRef>(rawValues.size());
for (StoreRef ref : rawValues)
{
StoreRef storeRef = ref;
try
{
if (tenantService.isEnabled())
{
String currentUser = AuthenticationUtil.getCurrentUserName();
// MT: return tenant stores only (although for super System return all stores - as used by
// ConfigurationChecker, IndexRecovery, IndexBackup etc)
if ((currentUser == null) || (!currentUser.equals(AuthenticationUtil.getSystemUserName())))
{
tenantService.checkDomain(storeRef.getIdentifier());
storeRef = tenantService.getBaseName(storeRef);
}
}
convertedValues.add(storeRef);
}
catch (RuntimeException re)
{
// deliberately ignore - stores in different domain will not be listed
}
}
return convertedValues;
}
else
{
// Convert the outbound value
ret = convertOutboundValue(ret);
}
// done
return ret;

View File

@@ -60,20 +60,17 @@ public class MultiTServiceImpl implements TenantService
{
this.tenantsCache = tenantsCache;
}
public NodeRef getName(NodeRef nodeRef)
{
// Check that all the passed values are not null
ParameterCheck.mandatory("NodeRef", nodeRef);
if (nodeRef == null) { return null; }
return new NodeRef(nodeRef.getStoreRef().getProtocol(), getName(nodeRef.getStoreRef().getIdentifier()), nodeRef.getId());
}
public NodeRef getName(NodeRef inNodeRef, NodeRef nodeRef)
{
// Check that all the passed values are not null
ParameterCheck.mandatory("InNodeRef", inNodeRef);
ParameterCheck.mandatory("NodeRef", nodeRef);
if (inNodeRef == null || nodeRef == null) { return null; }
int idx = inNodeRef.getStoreRef().getIdentifier().lastIndexOf(SEPARATOR);
if (idx != -1)
@@ -87,16 +84,14 @@ public class MultiTServiceImpl implements TenantService
public StoreRef getName(StoreRef storeRef)
{
// Check that all the passed values are not null
ParameterCheck.mandatory("StoreRef", storeRef);
if (storeRef == null) { return null; }
return new StoreRef(storeRef.getProtocol(), getName(storeRef.getIdentifier()));
}
public ChildAssociationRef getName(ChildAssociationRef childAssocRef)
{
// Check that all the passed values are not null
ParameterCheck.mandatory("ChildAssocRef", childAssocRef);
if (childAssocRef == null) { return null; }
return new ChildAssociationRef(
childAssocRef.getTypeQName(),
@@ -109,8 +104,7 @@ public class MultiTServiceImpl implements TenantService
public AssociationRef getName(AssociationRef assocRef)
{
// Check that all the passed values are not null
ParameterCheck.mandatory("assocRef", assocRef);
if (assocRef == null) { return null; }
return new AssociationRef(
getName(assocRef.getSourceRef()),
@@ -121,10 +115,10 @@ public class MultiTServiceImpl implements TenantService
public StoreRef getName(String username, StoreRef storeRef)
{
// Check that all the passed values are not null
ParameterCheck.mandatory("StoreRef", storeRef);
if (storeRef == null) { return null; }
if (username != null) {
if (username != null)
{
int idx = username.lastIndexOf(SEPARATOR);
if ((idx > 0) && (idx < (username.length()-1)))
{
@@ -241,24 +235,21 @@ public class MultiTServiceImpl implements TenantService
public NodeRef getBaseName(NodeRef nodeRef)
{
// Check that all the passed values are not null
ParameterCheck.mandatory("NodeRef", nodeRef);
if (nodeRef == null) { return null; }
return new NodeRef(nodeRef.getStoreRef().getProtocol(), getBaseName(nodeRef.getStoreRef().getIdentifier()), nodeRef.getId());
}
public StoreRef getBaseName(StoreRef storeRef)
{
// Check that all the passed values are not null
ParameterCheck.mandatory("StoreRef", storeRef);
if (storeRef == null) { return null; }
return new StoreRef(storeRef.getProtocol(), getBaseName(storeRef.getIdentifier()));
}
public ChildAssociationRef getBaseName(ChildAssociationRef childAssocRef)
{
// Check that all the passed values are not null
ParameterCheck.mandatory("ChildAssocRef", childAssocRef);
if (childAssocRef == null) { return null; }
return new ChildAssociationRef(childAssocRef.getTypeQName(),
getBaseName(childAssocRef.getParentRef()),