REPO-3280: clearCurrentSecurityContext after admin authentication.

This commit is contained in:
Andreea Nechifor
2018-04-05 14:35:45 +03:00
parent 4ade4ddb20
commit 3b5168aa9d
4 changed files with 24 additions and 9 deletions

View File

@@ -55,6 +55,7 @@ import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.testing.category.LuceneTests;
import org.junit.After;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
@@ -194,5 +195,7 @@ public abstract class BaseCMISTest extends TestCase
testTX.rollback();
}
super.tearDown();
AuthenticationUtil.clearCurrentSecurityContext();
}
}

View File

@@ -394,7 +394,7 @@ public class DictionaryModelTypeTest extends BaseSpringTest
this.actionService = (ActionService)this.applicationContext.getBean("actionService");
this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");
// Authenticate as the admin user
// Authenticate as the admin user for dictionaryModelType
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
@@ -448,7 +448,7 @@ public class DictionaryModelTypeTest extends BaseSpringTest
@After
public void after() throws Exception
{
authenticationService.clearCurrentSecurityContext();
AuthenticationUtil.clearCurrentSecurityContext();
}
/**

View File

@@ -200,7 +200,6 @@ public class ScriptNodeTest
@Before public void createTestContent()
{
excludedOnUpdateProps = VERSIONABLE_ASPECT.getExcludedOnUpdateProps();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// Create the store and get the root node
storeRef = NODE_SERVICE.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
@@ -510,13 +509,14 @@ public class ScriptNodeTest
{
setUpBootstrap();
// Authenticate as the system user
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
// Authenticate as the system user
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
log.debug("Adding new model.");
// Create a model node
@@ -534,6 +534,8 @@ public class ScriptNodeTest
InputStream cmStream = getClass().getClassLoader().getResourceAsStream(TEST_CONTENT_MODEL);
contentWriter.putContent(IOUtils.toString(cmStream));
cmStream.close();
AuthenticationUtil.popAuthentication();
return null;
}
});

View File

@@ -64,6 +64,7 @@ import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
@@ -132,6 +133,7 @@ public class UserUsageTest extends TestCase
testTX = transactionService.getUserTransaction();
testTX.begin();
//Authenticate as the admin user
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
// get default store (as configured for content usage service)
@@ -234,6 +236,8 @@ public class UserUsageTest extends TestCase
return null;
}
}, true, true);
AuthenticationUtil.clearCurrentSecurityContext();
}
protected void runAs(String userName)
@@ -1054,4 +1058,10 @@ public class UserUsageTest extends TestCase
{
ownableService.takeOwnership(nodeRef);
}
@After
public void after() throws Exception
{
AuthenticationUtil.popAuthentication();
}
}