mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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:
@@ -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
|
||||
*
|
||||
|
Reference in New Issue
Block a user