mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
ALF-8574 runas not working as expected
Cause: Person object set within repo parameters was the runAs user. Fix: getFullyAuthenticatedPerson() added to Repository. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@41347 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -237,7 +237,7 @@ public class RepositoryContainer extends AbstractRuntimeContainer implements Ten
|
||||
{
|
||||
params.put("companyhome", companyHome);
|
||||
}
|
||||
NodeRef person = repository.getPerson();
|
||||
NodeRef person = repository.getFullyAuthenticatedPerson();
|
||||
if (person != null)
|
||||
{
|
||||
params.put("person", person);
|
||||
|
@@ -19,10 +19,14 @@
|
||||
package org.alfresco.repo.web.scripts;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
import static org.springframework.extensions.webscripts.Status.*;
|
||||
|
||||
/**
|
||||
* Unit test to test runas function
|
||||
@@ -33,22 +37,25 @@ public class RepositoryContainerTest extends BaseWebScriptTest
|
||||
{
|
||||
private MutableAuthenticationService authenticationService;
|
||||
private PersonService personService;
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
|
||||
private static final String USER_ONE = "RunAsOne";
|
||||
private static final String USER_TWO = "RunAsTwo";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean(
|
||||
"AuthenticationService");
|
||||
this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
|
||||
this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
|
||||
this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
|
||||
|
||||
// Create users
|
||||
createUser(USER_ONE);
|
||||
createUser(USER_TWO);
|
||||
}
|
||||
|
||||
private void createUser(String userName)
|
||||
@@ -57,7 +64,7 @@ public class RepositoryContainerTest extends BaseWebScriptTest
|
||||
{
|
||||
this.authenticationService.createAuthentication(userName, "PWD".toCharArray());
|
||||
|
||||
PropertyMap ppOne = new PropertyMap(4);
|
||||
PropertyMap ppOne = new PropertyMap(5);
|
||||
ppOne.put(ContentModel.PROP_USERNAME, userName);
|
||||
ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
|
||||
ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
|
||||
@@ -75,6 +82,27 @@ public class RepositoryContainerTest extends BaseWebScriptTest
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Person should be current user irrespective of runas user.
|
||||
*/
|
||||
public void testRunAsAdmin() throws Exception {
|
||||
authenticationComponent.setCurrentUser(USER_ONE);
|
||||
|
||||
// No runas specified within our webscript descriptor
|
||||
Response response = sendRequest(new GetRequest("/test/runas"), STATUS_OK);
|
||||
assertEquals(USER_ONE, response.getContentAsString());
|
||||
|
||||
authenticationComponent.setCurrentUser(USER_TWO);
|
||||
|
||||
// runas "Admin" specified within our webscript descriptor
|
||||
response = sendRequest(new GetRequest("/test/runasadmin"), STATUS_OK);
|
||||
assertEquals(USER_TWO, response.getContentAsString());
|
||||
|
||||
authenticationComponent.setSystemUserAsCurrentUser();
|
||||
}
|
||||
|
||||
|
||||
public void testReset() throws Exception
|
||||
{
|
||||
RepositoryContainer repoContainer = (RepositoryContainer) getServer().getApplicationContext().getBean("webscripts.container");
|
||||
|
@@ -0,0 +1,8 @@
|
||||
<webscript>
|
||||
<shortname>Runas Test</shortname>
|
||||
<description>Runas Test</description>
|
||||
<url>/test/runas</url>
|
||||
<format default="html">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1 @@
|
||||
${testPerson.properties['userName']}
|
@@ -0,0 +1 @@
|
||||
model.testPerson=person;
|
@@ -0,0 +1,8 @@
|
||||
<webscript>
|
||||
<shortname>Runas Admin Test</shortname>
|
||||
<description>Runas Admin Test</description>
|
||||
<url>/test/runasadmin</url>
|
||||
<format default="html">argument</format>
|
||||
<authentication runas="admin">user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1 @@
|
||||
${testPerson.properties['userName']}
|
@@ -0,0 +1 @@
|
||||
model.testPerson=person;
|
Reference in New Issue
Block a user