mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
REPO-1503: allow setting of password
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@131939 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -297,8 +297,8 @@ public class PeopleImpl implements People
|
|||||||
Map<QName, Serializable> props = person.toProperties();
|
Map<QName, Serializable> props = person.toProperties();
|
||||||
|
|
||||||
MutableAuthenticationService mas = (MutableAuthenticationService) authenticationService;
|
MutableAuthenticationService mas = (MutableAuthenticationService) authenticationService;
|
||||||
// TODO: very temporary code, until REPO-1503 (set password) implemented.
|
String password = person.getPassword() == null ? UUID.randomUUID().toString() : person.getPassword();
|
||||||
mas.createAuthentication(person.getUserName(), UUID.randomUUID().toString().toCharArray());
|
mas.createAuthentication(person.getUserName(), password.toCharArray());
|
||||||
mas.setAuthenticationEnabled(person.getUserName(), person.isEnabled());
|
mas.setAuthenticationEnabled(person.getUserName(), person.isEnabled());
|
||||||
NodeRef nodeRef = personService.createPerson(props);
|
NodeRef nodeRef = personService.createPerson(props);
|
||||||
|
|
||||||
|
@@ -65,6 +65,7 @@ public class Person
|
|||||||
protected Boolean emailNotificationsEnabled;
|
protected Boolean emailNotificationsEnabled;
|
||||||
protected String description;
|
protected String description;
|
||||||
protected Company company;
|
protected Company company;
|
||||||
|
protected String password;
|
||||||
|
|
||||||
public Person()
|
public Person()
|
||||||
{
|
{
|
||||||
@@ -201,6 +202,11 @@ public class Person
|
|||||||
{
|
{
|
||||||
this.avatarId = avatarId;
|
this.avatarId = avatarId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password)
|
||||||
|
{
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
public NodeRef getAvatarId()
|
public NodeRef getAvatarId()
|
||||||
{
|
{
|
||||||
@@ -272,6 +278,11 @@ public class Person
|
|||||||
return emailNotificationsEnabled;
|
return emailNotificationsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPassword()
|
||||||
|
{
|
||||||
|
return this.password;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
@@ -347,9 +358,6 @@ public class Person
|
|||||||
addToMap(properties, ContentModel.PROP_GOOGLEUSERNAME, getGoogleId());
|
addToMap(properties, ContentModel.PROP_GOOGLEUSERNAME, getGoogleId());
|
||||||
addToMap(properties, ContentModel.PROP_SIZE_QUOTA, getQuota());
|
addToMap(properties, ContentModel.PROP_SIZE_QUOTA, getQuota());
|
||||||
addToMap(properties, ContentModel.PROP_SIZE_CURRENT, getQuotaUsed());
|
addToMap(properties, ContentModel.PROP_SIZE_CURRENT, getQuotaUsed());
|
||||||
|
|
||||||
// What's the correct behaviour here? Store it as "content" somehow?
|
|
||||||
// so that it can be 'inlined' by the code in PeopleImpl.processPersonProperties ?
|
|
||||||
addToMap(properties, ContentModel.PROP_PERSONDESC, getDescription());
|
addToMap(properties, ContentModel.PROP_PERSONDESC, getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -57,7 +57,7 @@ public class PersonUpdate
|
|||||||
protected final String userStatus;
|
protected final String userStatus;
|
||||||
protected final Boolean enabled;
|
protected final Boolean enabled;
|
||||||
protected final Boolean emailNotificationsEnabled;
|
protected final Boolean emailNotificationsEnabled;
|
||||||
|
protected final String password;
|
||||||
|
|
||||||
private PersonUpdate(
|
private PersonUpdate(
|
||||||
String userName,
|
String userName,
|
||||||
@@ -75,7 +75,8 @@ public class PersonUpdate
|
|||||||
String telephone,
|
String telephone,
|
||||||
String userStatus,
|
String userStatus,
|
||||||
Boolean enabled,
|
Boolean enabled,
|
||||||
Boolean emailNotificationsEnabled)
|
Boolean emailNotificationsEnabled,
|
||||||
|
String password)
|
||||||
{
|
{
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
this.firstName = firstName;
|
this.firstName = firstName;
|
||||||
@@ -93,6 +94,7 @@ public class PersonUpdate
|
|||||||
this.userStatus = userStatus;
|
this.userStatus = userStatus;
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
this.emailNotificationsEnabled = emailNotificationsEnabled;
|
this.emailNotificationsEnabled = emailNotificationsEnabled;
|
||||||
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Company getCompany()
|
public Company getCompany()
|
||||||
@@ -176,6 +178,11 @@ public class PersonUpdate
|
|||||||
return emailNotificationsEnabled;
|
return emailNotificationsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPassword()
|
||||||
|
{
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
@@ -194,7 +201,9 @@ public class PersonUpdate
|
|||||||
+ ", googleId=" + googleId
|
+ ", googleId=" + googleId
|
||||||
+ ", emailNotificationsEnabled=" + emailNotificationsEnabled
|
+ ", emailNotificationsEnabled=" + emailNotificationsEnabled
|
||||||
+ ", description=" + description
|
+ ", description=" + description
|
||||||
+ ", company=" + company + "]";
|
+ ", company=" + company
|
||||||
|
+ ", password=(not shown)"
|
||||||
|
+ "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<QName, Serializable> toProperties()
|
public Map<QName, Serializable> toProperties()
|
||||||
@@ -275,6 +284,7 @@ public class PersonUpdate
|
|||||||
private String userStatus;
|
private String userStatus;
|
||||||
private Boolean enabled;
|
private Boolean enabled;
|
||||||
private Boolean emailNotificationsEnabled;
|
private Boolean emailNotificationsEnabled;
|
||||||
|
private String password;
|
||||||
|
|
||||||
public Builder id(String userId)
|
public Builder id(String userId)
|
||||||
{
|
{
|
||||||
@@ -371,6 +381,12 @@ public class PersonUpdate
|
|||||||
this.emailNotificationsEnabled = emailNotificationsEnabled;
|
this.emailNotificationsEnabled = emailNotificationsEnabled;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder password(String password)
|
||||||
|
{
|
||||||
|
this.password = password;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public PersonUpdate build()
|
public PersonUpdate build()
|
||||||
{
|
{
|
||||||
@@ -390,7 +406,8 @@ public class PersonUpdate
|
|||||||
telephone,
|
telephone,
|
||||||
userStatus,
|
userStatus,
|
||||||
enabled,
|
enabled,
|
||||||
emailNotificationsEnabled
|
emailNotificationsEnabled,
|
||||||
|
password
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -126,7 +126,9 @@ public class PeopleEntityResource implements EntityResourceAction.ReadById<Perso
|
|||||||
.telephone(p.getTelephone())
|
.telephone(p.getTelephone())
|
||||||
.userStatus(p.getUserStatus())
|
.userStatus(p.getUserStatus())
|
||||||
.enabled(p.isEnabled())
|
.enabled(p.isEnabled())
|
||||||
.emailNotificationsEnabled(p.isEmailNotificationsEnabled()).build();
|
.emailNotificationsEnabled(p.isEmailNotificationsEnabled())
|
||||||
|
.password(p.getPassword()).
|
||||||
|
build();
|
||||||
|
|
||||||
result.add(people.create(person));
|
result.add(people.create(person));
|
||||||
return result;
|
return result;
|
||||||
|
@@ -41,8 +41,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
public class TestPeople extends EnterpriseTestApi
|
public class TestPeople extends EnterpriseTestApi
|
||||||
{
|
{
|
||||||
@@ -180,38 +179,66 @@ public class TestPeople extends EnterpriseTestApi
|
|||||||
@Test
|
@Test
|
||||||
public void testCreatePerson_canCreateDisabledPerson() throws PublicApiException
|
public void testCreatePerson_canCreateDisabledPerson() throws PublicApiException
|
||||||
{
|
{
|
||||||
publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
|
|
||||||
|
|
||||||
// Person disabled
|
// Person disabled
|
||||||
{
|
{
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
|
||||||
|
|
||||||
PersonUpdate person = new PersonUpdate.Builder().
|
PersonUpdate person = new PersonUpdate.Builder().
|
||||||
id("myUserName04@"+account1.getId()).
|
id("myUserName04@"+account1.getId()).
|
||||||
firstName("Firstname").
|
firstName("Firstname").
|
||||||
email("myUserName04@"+account1.getId()).
|
email("myUserName04@"+account1.getId()).
|
||||||
enabled(false).
|
enabled(false).
|
||||||
|
password("hello").
|
||||||
build();
|
build();
|
||||||
|
|
||||||
Person p = people.create(person);
|
Person p = people.create(person);
|
||||||
assertEquals(false, p.isEnabled());
|
assertEquals(false, p.isEnabled());
|
||||||
|
// It's very important that the password isn't exposed over the REST API.
|
||||||
|
assertNull(p.getPassword());
|
||||||
// Check that a freshly retrieved person exhibits the same result
|
// Check that a freshly retrieved person exhibits the same result
|
||||||
p = people.getPerson(person.getUserName());
|
p = people.getPerson(person.getUserName());
|
||||||
assertEquals(false, p.isEnabled());
|
assertEquals(false, p.isEnabled());
|
||||||
|
assertNull(p.getPassword());
|
||||||
|
|
||||||
|
// Can the new user account be used?
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person.getUserName(), "hello"));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
people.getPerson(person.getUserName());
|
||||||
|
fail("It should not be possible to use a disabled account.");
|
||||||
|
}
|
||||||
|
catch (PublicApiException e)
|
||||||
|
{
|
||||||
|
assertEquals(401, e.getHttpResponse().getStatusCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Person enabled
|
// Person enabled
|
||||||
{
|
{
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
|
||||||
|
|
||||||
PersonUpdate person = new PersonUpdate.Builder().
|
PersonUpdate person = new PersonUpdate.Builder().
|
||||||
id("myUserName05@"+account1.getId()).
|
id("myUserName05@"+account1.getId()).
|
||||||
firstName("Firstname").
|
firstName("Firstname").
|
||||||
email("myUserName05@"+account1.getId()).
|
email("myUserName05@"+account1.getId()).
|
||||||
enabled(true).
|
enabled(true).
|
||||||
|
password("banana").
|
||||||
build();
|
build();
|
||||||
|
|
||||||
Person p = people.create(person);
|
Person p = people.create(person);
|
||||||
assertEquals(true, p.isEnabled());
|
assertEquals(true, p.isEnabled());
|
||||||
|
// It's very important that the password isn't exposed over the REST API.
|
||||||
|
assertNull(p.getPassword());
|
||||||
// Check that a freshly retrieved person exhibits the same result
|
// Check that a freshly retrieved person exhibits the same result
|
||||||
p = people.getPerson(person.getUserName());
|
p = people.getPerson(person.getUserName());
|
||||||
assertEquals(true, p.isEnabled());
|
assertEquals(true, p.isEnabled());
|
||||||
|
assertNull(p.getPassword());
|
||||||
|
|
||||||
|
// Can the new user account be used?
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person.getUserName(), "banana"));
|
||||||
|
p = people.getPerson(person.getUserName());
|
||||||
|
assertNotNull(p);
|
||||||
|
assertNull(p.getPassword());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,6 +432,7 @@ public class TestPeople extends EnterpriseTestApi
|
|||||||
personJson.put("userStatus", personUpdate.getUserStatus());
|
personJson.put("userStatus", personUpdate.getUserStatus());
|
||||||
personJson.put("enabled", personUpdate.isEnabled());
|
personJson.put("enabled", personUpdate.isEnabled());
|
||||||
personJson.put("emailNotificationsEnabled", personUpdate.isEmailNotificationsEnabled());
|
personJson.put("emailNotificationsEnabled", personUpdate.isEmailNotificationsEnabled());
|
||||||
|
personJson.put("password", personUpdate.getPassword());
|
||||||
|
|
||||||
return personJson;
|
return personJson;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user