mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
MOB-620 - Create User, enable/disable account and user quota setting.
Mandatory fields now checked on Create User page. Create and Create Another User button now working. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14102 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -120,6 +120,9 @@
|
|||||||
<property name="mutableAuthenticationDao">
|
<property name="mutableAuthenticationDao">
|
||||||
<ref bean="authenticationDao"/>
|
<ref bean="authenticationDao"/>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="contentUsageService">
|
||||||
|
<ref bean="ContentUsageService"/>
|
||||||
|
</property>
|
||||||
<property name="userNameGenerator">
|
<property name="userNameGenerator">
|
||||||
<ref bean="userNameGenerator"/>
|
<ref bean="userNameGenerator"/>
|
||||||
</property>
|
</property>
|
||||||
|
@@ -44,6 +44,7 @@ import org.alfresco.service.cmr.search.SearchService;
|
|||||||
import org.alfresco.service.cmr.security.AuthorityService;
|
import org.alfresco.service.cmr.security.AuthorityService;
|
||||||
import org.alfresco.service.cmr.security.AuthorityType;
|
import org.alfresco.service.cmr.security.AuthorityType;
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
|
import org.alfresco.service.cmr.usage.ContentUsageService;
|
||||||
import org.alfresco.service.namespace.NamespaceService;
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
import org.alfresco.util.ParameterCheck;
|
import org.alfresco.util.ParameterCheck;
|
||||||
import org.alfresco.util.PropertyMap;
|
import org.alfresco.util.PropertyMap;
|
||||||
@@ -64,6 +65,7 @@ public final class People extends BaseScopableProcessorExtension
|
|||||||
private AuthorityService authorityService;
|
private AuthorityService authorityService;
|
||||||
private PersonService personService;
|
private PersonService personService;
|
||||||
private MutableAuthenticationDao mutableAuthenticationDao;
|
private MutableAuthenticationDao mutableAuthenticationDao;
|
||||||
|
private ContentUsageService contentUsageService;
|
||||||
private UserNameGenerator usernameGenerator;
|
private UserNameGenerator usernameGenerator;
|
||||||
private PasswordGenerator passwordGenerator;
|
private PasswordGenerator passwordGenerator;
|
||||||
private StoreRef storeRef;
|
private StoreRef storeRef;
|
||||||
@@ -135,6 +137,14 @@ public final class People extends BaseScopableProcessorExtension
|
|||||||
this.personService = personService;
|
this.personService = personService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param contentUsageService the ContentUsageService to set
|
||||||
|
*/
|
||||||
|
public void setContentUsageService(ContentUsageService contentUsageService)
|
||||||
|
{
|
||||||
|
this.contentUsageService = contentUsageService;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the user name generator service
|
* Set the user name generator service
|
||||||
*
|
*
|
||||||
@@ -163,11 +173,13 @@ public final class People extends BaseScopableProcessorExtension
|
|||||||
public void deletePerson(String username)
|
public void deletePerson(String username)
|
||||||
{
|
{
|
||||||
personService.deletePerson(username);
|
personService.deletePerson(username);
|
||||||
|
mutableAuthenticationDao.deleteUser(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Person with a generated user name
|
* Create a Person with an optionally generated user name
|
||||||
*
|
*
|
||||||
|
* @param userName userName or null for a generated user name
|
||||||
* @param firstName firstName
|
* @param firstName firstName
|
||||||
* @param lastName lastName
|
* @param lastName lastName
|
||||||
* @param emailAddress emailAddress
|
* @param emailAddress emailAddress
|
||||||
@@ -181,38 +193,44 @@ public final class People extends BaseScopableProcessorExtension
|
|||||||
* @return the person node (type cm:person) created or null if the person
|
* @return the person node (type cm:person) created or null if the person
|
||||||
* could not be created
|
* could not be created
|
||||||
*/
|
*/
|
||||||
public ScriptNode createPerson(String firstName, String lastName, String emailAddress, boolean createUserAccount, boolean setAccountEnabled)
|
public ScriptNode createPerson(String userName, String firstName, String lastName, String emailAddress, boolean createUserAccount, boolean setAccountEnabled)
|
||||||
{
|
{
|
||||||
ParameterCheck.mandatory("firstName", firstName);
|
ParameterCheck.mandatory("firstName", firstName);
|
||||||
ParameterCheck.mandatory("lastName", lastName);
|
ParameterCheck.mandatory("lastName", lastName);
|
||||||
ParameterCheck.mandatory("createUserAccount", createUserAccount);
|
ParameterCheck.mandatory("emailAddress", emailAddress);
|
||||||
ParameterCheck.mandatory("setAccountEnabled", setAccountEnabled);
|
|
||||||
|
|
||||||
ScriptNode person = null;
|
ScriptNode person = null;
|
||||||
|
|
||||||
// generate user name
|
// generate user name if not supplied
|
||||||
for (int i=0; i < numRetries; i++)
|
if (userName == null)
|
||||||
{
|
{
|
||||||
String userName = usernameGenerator.generateUserName(firstName, lastName, emailAddress, i);
|
for (int i=0; i < numRetries; i++)
|
||||||
|
{
|
||||||
|
userName = usernameGenerator.generateUserName(firstName, lastName, emailAddress, i);
|
||||||
|
|
||||||
// create person if user name does not already exist
|
// create person if user name does not already exist
|
||||||
if (!personService.personExists(userName))
|
if (!personService.personExists(userName))
|
||||||
{
|
{
|
||||||
person = createPerson(userName, firstName, lastName, emailAddress);
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (createUserAccount)
|
if (userName != null)
|
||||||
{
|
{
|
||||||
// generate password
|
person = createPerson(userName, firstName, lastName, emailAddress);
|
||||||
char[] password = passwordGenerator.generatePassword().toCharArray();
|
|
||||||
|
|
||||||
// create account for person with generated userName and password
|
if (createUserAccount)
|
||||||
mutableAuthenticationDao.createUser(userName, password);
|
{
|
||||||
mutableAuthenticationDao.setEnabled(userName, setAccountEnabled);
|
// generate password
|
||||||
|
char[] password = passwordGenerator.generatePassword().toCharArray();
|
||||||
|
|
||||||
person.save();
|
// create account for person with the userName and password
|
||||||
}
|
mutableAuthenticationDao.createUser(userName, password);
|
||||||
break;
|
mutableAuthenticationDao.setEnabled(userName, setAccountEnabled);
|
||||||
}
|
|
||||||
|
person.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return person;
|
return person;
|
||||||
@@ -310,6 +328,33 @@ public final class People extends BaseScopableProcessorExtension
|
|||||||
return person;
|
return person;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the content quota in bytes for a person.
|
||||||
|
* Only the admin authority can set this value.
|
||||||
|
*
|
||||||
|
* @param person Person to set quota against.
|
||||||
|
* @param quota In bytes, a value of -1 means no quota is set
|
||||||
|
*/
|
||||||
|
public void setQuota(ScriptNode person, Integer quota)
|
||||||
|
{
|
||||||
|
setQuota(person, quota.longValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the content quota in bytes for a person.
|
||||||
|
* Only the admin authority can set this value.
|
||||||
|
*
|
||||||
|
* @param person Person to set quota against.
|
||||||
|
* @param quota In bytes, a value of -1 means no quota is set
|
||||||
|
*/
|
||||||
|
public void setQuota(ScriptNode person, Long quota)
|
||||||
|
{
|
||||||
|
if (this.authorityService.isAdminAuthority(AuthenticationUtil.getFullyAuthenticatedUser()))
|
||||||
|
{
|
||||||
|
this.contentUsageService.setUserQuota((String)person.getProperties().get(ContentModel.PROP_USERNAME), quota);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the collection of people stored in the repository.
|
* Get the collection of people stored in the repository.
|
||||||
* An optional filter query may be provided by which to filter the people collection.
|
* An optional filter query may be provided by which to filter the people collection.
|
||||||
|
Reference in New Issue
Block a user