Added optional user authentication to FileImporterTest

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2796 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-05-09 10:25:39 +00:00
parent 78aee1feb2
commit dcc4be56cb
2 changed files with 56 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ import java.io.Serializable;
import java.util.HashMap;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AuthenticationService;
@@ -89,6 +90,32 @@ public abstract class TestWithUserUtils extends BaseSpringTest
authenticationService.authenticate(userName, password.toCharArray());
}
/**
* Authenticate as the given user. If the user does not exist, then authenticate as the system user
* and create the authentication first.
*/
public static void authenticateUser(
String userName,
String password,
AuthenticationService authenticationService,
AuthenticationComponent authenticationComponent)
{
// go system
try
{
authenticationComponent.setSystemUserAsCurrentUser();
if (!authenticationService.authenticationExists(userName))
{
authenticationService.createAuthentication(userName, password.toCharArray());
}
}
finally
{
authenticationComponent.clearCurrentSecurityContext();
}
authenticationService.authenticate(userName, password.toCharArray());
}
/**
* Get the current user node reference
*