Merged V3.0 to HEAD

12145: Merged V2.2 to V3.0 (AuthenticationUtil)
    12109: AuthenticationUtil and AuthenticationComponent refactor
  12152: Removed Lucene usage from lookup of 'sites' root folder
  12153: Fix InviteServiceTest by cleaning up leaking authentications
  12159: Fix for broken usage pattern of the Threadlocal values in recent AuthenticationUtil refactor.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12508 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2008-12-19 12:15:59 +00:00
parent 21bb599e20
commit cd09266213
74 changed files with 870 additions and 997 deletions

View File

@@ -52,6 +52,7 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.authentication.InMemoryTicketComponentImpl.ExpiryMode;
import org.alfresco.repo.security.authentication.InMemoryTicketComponentImpl.Ticket;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -211,19 +212,16 @@ public class AuthenticationTest extends TestCase
public void testSystemTicket() throws Exception
{
assertNull(AuthenticationUtil.getCurrentRealAuthentication());
assertNull(AuthenticationUtil.getCurrentEffectiveAuthentication());
assertNull(AuthenticationUtil.getCurrentStoredAuthentication());
assertNull(AuthenticationUtil.getFullAuthentication());
assertNull(AuthenticationUtil.getRunAsAuthentication());
authenticationComponent.setSystemUserAsCurrentUser();
pubAuthenticationService.createAuthentication("andy", "andy".toCharArray());
pubAuthenticationService.clearCurrentSecurityContext();
assertNull(AuthenticationUtil.getCurrentRealAuthentication());
assertNull(AuthenticationUtil.getCurrentEffectiveAuthentication());
assertNull(AuthenticationUtil.getCurrentStoredAuthentication());
assertNull(AuthenticationUtil.getFullAuthentication());
assertNull(AuthenticationUtil.getRunAsAuthentication());
// Authenticate
pubAuthenticationService.authenticate("andy", "andy".toCharArray());
@@ -542,6 +540,56 @@ public class AuthenticationTest extends TestCase
// assertNull(dao.getUserOrNull("Andy"));
}
public void testCreateAuthenticationWhileRunningAsSystem() throws Exception
{
RunAsWork<Object> authWorkAsMuppet = new RunAsWork<Object>()
{
public Object doWork() throws Exception
{
RunAsWork<Object> authWorkAsSystem = new RunAsWork<Object>()
{
public Object doWork() throws Exception
{
RetryingTransactionCallback<Object> txnWork = new RetryingTransactionCallback<Object>()
{
public Object execute() throws Throwable
{
pubAuthenticationService.createAuthentication("blah", "pwd".toCharArray());
pubAuthenticationService.deleteAuthentication("blah");
return null;
}
};
return transactionService.getRetryingTransactionHelper().doInTransaction(txnWork, false, true);
}
};
return AuthenticationUtil.runAs(authWorkAsSystem, AuthenticationUtil.getSystemUserName());
}
};
AuthenticationUtil.runAs(authWorkAsMuppet, "muppet");
}
public void testPushAndPopAuthentication() throws Exception
{
AuthenticationUtil.setFullyAuthenticatedUser("user1");
assertEquals("user1", AuthenticationUtil.getFullyAuthenticatedUser());
assertEquals("user1", AuthenticationUtil.getRunAsUser());
AuthenticationUtil.setRunAsUser("user2");
assertEquals("user1", AuthenticationUtil.getFullyAuthenticatedUser());
assertEquals("user2", AuthenticationUtil.getRunAsUser());
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser("user3");
AuthenticationUtil.setRunAsUser("user4");
assertEquals("user3", AuthenticationUtil.getFullyAuthenticatedUser());
assertEquals("user4", AuthenticationUtil.getRunAsUser());
AuthenticationUtil.popAuthentication();
assertEquals("user1", AuthenticationUtil.getFullyAuthenticatedUser());
assertEquals("user2", AuthenticationUtil.getRunAsUser());
}
public void testAuthenticationFailure()
{
dao.createUser("Andy", "squash".toCharArray());