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:
Harpritt Kalsi
2012-09-07 08:50:31 +00:00
parent 0b52712595
commit 70dadc3631
8 changed files with 54 additions and 6 deletions

View File

@@ -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);

View File

@@ -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");

View File

@@ -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>

View File

@@ -0,0 +1 @@
${testPerson.properties['userName']}

View File

@@ -0,0 +1 @@
model.testPerson=person;

View File

@@ -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>

View File

@@ -0,0 +1 @@
${testPerson.properties['userName']}

View File

@@ -0,0 +1 @@
model.testPerson=person;