mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-09-17 14:21:39 +00:00
MNT-24146 -backport fix & precommit changes
This commit is contained in:
@@ -25,6 +25,20 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.api.impl;
|
package org.alfresco.rest.api.impl;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.AbstractList;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.query.PagingRequest;
|
import org.alfresco.query.PagingRequest;
|
||||||
import org.alfresco.query.PagingResults;
|
import org.alfresco.query.PagingResults;
|
||||||
@@ -75,19 +89,6 @@ import org.alfresco.service.cmr.usage.ContentUsageService;
|
|||||||
import org.alfresco.service.namespace.NamespaceService;
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.AbstractList;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Centralises access to people services and maps between representations.
|
* Centralises access to people services and maps between representations.
|
||||||
@@ -106,8 +107,7 @@ public class PeopleImpl implements People
|
|||||||
private static final List<QName> EXCLUDED_ASPECTS = Arrays.asList();
|
private static final List<QName> EXCLUDED_ASPECTS = Arrays.asList();
|
||||||
private static final List<QName> EXCLUDED_PROPS = Arrays.asList();
|
private static final List<QName> EXCLUDED_PROPS = Arrays.asList();
|
||||||
private static final int USERNAME_MAXLENGTH = 100;
|
private static final int USERNAME_MAXLENGTH = 100;
|
||||||
private static final String[] RESERVED_AUTHORITY_PREFIXES =
|
private static final String[] RESERVED_AUTHORITY_PREFIXES = {
|
||||||
{
|
|
||||||
PermissionService.GROUP_PREFIX,
|
PermissionService.GROUP_PREFIX,
|
||||||
PermissionService.ROLE_PREFIX
|
PermissionService.ROLE_PREFIX
|
||||||
};
|
};
|
||||||
@@ -223,27 +223,27 @@ public class PeopleImpl implements People
|
|||||||
public String validatePerson(final String requestedPersonId, boolean validateIsCurrentUser)
|
public String validatePerson(final String requestedPersonId, boolean validateIsCurrentUser)
|
||||||
{
|
{
|
||||||
String personId = requestedPersonId;
|
String personId = requestedPersonId;
|
||||||
if(personId == null)
|
if (personId == null)
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException("personId is null.");
|
throw new InvalidArgumentException("personId is null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(personId.equalsIgnoreCase(DEFAULT_USER))
|
if (personId.equalsIgnoreCase(DEFAULT_USER))
|
||||||
{
|
{
|
||||||
personId = AuthenticationUtil.getFullyAuthenticatedUser();
|
personId = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
personId = personService.getUserIdentifier(personId);
|
personId = personService.getUserIdentifier(personId);
|
||||||
if(personId == null)
|
if (personId == null)
|
||||||
{
|
{
|
||||||
// Could not find canonical user ID by case-sensitive ID.
|
// Could not find canonical user ID by case-sensitive ID.
|
||||||
throw new EntityNotFoundException(requestedPersonId);
|
throw new EntityNotFoundException(requestedPersonId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(validateIsCurrentUser)
|
if (validateIsCurrentUser)
|
||||||
{
|
{
|
||||||
String currentUserId = AuthenticationUtil.getFullyAuthenticatedUser();
|
String currentUserId = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||||
if(!currentUserId.equalsIgnoreCase(personId))
|
if (!currentUserId.equalsIgnoreCase(personId))
|
||||||
{
|
{
|
||||||
throw new EntityNotFoundException(personId);
|
throw new EntityNotFoundException(personId);
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,7 @@ public class PeopleImpl implements People
|
|||||||
|
|
||||||
protected void processPersonProperties(String userName, final Map<QName, Serializable> nodeProps)
|
protected void processPersonProperties(String userName, final Map<QName, Serializable> nodeProps)
|
||||||
{
|
{
|
||||||
if(!contentUsageService.getEnabled())
|
if (!contentUsageService.getEnabled())
|
||||||
{
|
{
|
||||||
// quota used will always be 0 in this case so remove from the person properties
|
// quota used will always be 0 in this case so remove from the person properties
|
||||||
nodeProps.remove(ContentModel.PROP_SIZE_QUOTA);
|
nodeProps.remove(ContentModel.PROP_SIZE_QUOTA);
|
||||||
@@ -264,18 +264,17 @@ public class PeopleImpl implements People
|
|||||||
// The person description is located in a separate content file located at cm:persondescription
|
// The person description is located in a separate content file located at cm:persondescription
|
||||||
// "Inline" this data, by removing the cm:persondescription property and adding a temporary property
|
// "Inline" this data, by removing the cm:persondescription property and adding a temporary property
|
||||||
// (Person.PROP_PERSON_DESCRIPTION) containing the actual content as a string.
|
// (Person.PROP_PERSON_DESCRIPTION) containing the actual content as a string.
|
||||||
final ContentData personDescription = (ContentData)nodeProps.get(ContentModel.PROP_PERSONDESC);
|
final ContentData personDescription = (ContentData) nodeProps.get(ContentModel.PROP_PERSONDESC);
|
||||||
if(personDescription != null)
|
if (personDescription != null)
|
||||||
{
|
{
|
||||||
nodeProps.remove(ContentModel.PROP_PERSONDESC);
|
nodeProps.remove(ContentModel.PROP_PERSONDESC);
|
||||||
|
|
||||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public Void doWork() throws Exception
|
public Void doWork() throws Exception
|
||||||
{
|
{
|
||||||
ContentReader reader = contentService.getRawReader(personDescription.getContentUrl());
|
ContentReader reader = contentService.getRawReader(personDescription.getContentUrl());
|
||||||
if(reader != null && reader.exists())
|
if (reader != null && reader.exists())
|
||||||
{
|
{
|
||||||
String description = reader.getContentString();
|
String description = reader.getContentString();
|
||||||
nodeProps.put(Person.PROP_PERSON_DESCRIPTION, description);
|
nodeProps.put(Person.PROP_PERSON_DESCRIPTION, description);
|
||||||
@@ -298,7 +297,7 @@ public class PeopleImpl implements People
|
|||||||
NodeRef avatar = null;
|
NodeRef avatar = null;
|
||||||
personId = validatePerson(personId);
|
personId = validatePerson(personId);
|
||||||
NodeRef personNode = personService.getPerson(personId);
|
NodeRef personNode = personService.getPerson(personId);
|
||||||
if(personNode != null)
|
if (personNode != null)
|
||||||
{
|
{
|
||||||
NodeRef avatarOrig = getAvatarOriginal(personNode);
|
NodeRef avatarOrig = getAvatarOriginal(personNode);
|
||||||
avatar = thumbnailService.getThumbnailByName(avatarOrig, ContentModel.PROP_CONTENT, "avatar");
|
avatar = thumbnailService.getThumbnailByName(avatarOrig, ContentModel.PROP_CONTENT, "avatar");
|
||||||
@@ -379,7 +378,7 @@ public class PeopleImpl implements People
|
|||||||
if (mimeType.indexOf("image/") != 0)
|
if (mimeType.indexOf("image/") != 0)
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
"Uploaded content must be an image (content type determined to be '"+mimeType+"')");
|
"Uploaded content must be an image (content type determined to be '" + mimeType + "')");
|
||||||
}
|
}
|
||||||
|
|
||||||
// create thumbnail synchronously
|
// create thumbnail synchronously
|
||||||
@@ -416,7 +415,6 @@ public class PeopleImpl implements People
|
|||||||
nodeService.deleteNode(avatarOrigNodeRef);
|
nodeService.deleteNode(avatarOrigNodeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a full representation of a person.
|
* Get a full representation of a person.
|
||||||
*
|
*
|
||||||
@@ -459,8 +457,7 @@ public class PeopleImpl implements People
|
|||||||
final List<PersonService.PersonInfo> page = pagingResult.getPage();
|
final List<PersonService.PersonInfo> page = pagingResult.getPage();
|
||||||
int totalItems = pagingResult.getTotalResultCount().getFirst();
|
int totalItems = pagingResult.getTotalResultCount().getFirst();
|
||||||
final String personId = AuthenticationUtil.getFullyAuthenticatedUser();
|
final String personId = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||||
List<Person> people = new AbstractList<Person>()
|
List<Person> people = new AbstractList<Person>() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public Person get(int index)
|
public Person get(int index)
|
||||||
{
|
{
|
||||||
@@ -513,8 +510,7 @@ public class PeopleImpl implements People
|
|||||||
processPersonProperties(personId, nodeProps);
|
processPersonProperties(personId, nodeProps);
|
||||||
// TODO this needs to be run as admin but should we do this here?
|
// TODO this needs to be run as admin but should we do this here?
|
||||||
final String pId = personId;
|
final String pId = personId;
|
||||||
Boolean enabled = AuthenticationUtil.runAsSystem(new RunAsWork<Boolean>()
|
Boolean enabled = AuthenticationUtil.runAsSystem(new RunAsWork<Boolean>() {
|
||||||
{
|
|
||||||
public Boolean doWork() throws Exception
|
public Boolean doWork() throws Exception
|
||||||
{
|
{
|
||||||
return authenticationService.getAuthenticationEnabled(pId);
|
return authenticationService.getAuthenticationEnabled(pId);
|
||||||
@@ -576,7 +572,7 @@ public class PeopleImpl implements People
|
|||||||
{
|
{
|
||||||
validateCreatePersonData(person);
|
validateCreatePersonData(person);
|
||||||
|
|
||||||
if (! isAdminAuthority())
|
if (!isAdminAuthority())
|
||||||
{
|
{
|
||||||
// note: do an explict check for admin here (since personExists does not throw 403 unlike createPerson,
|
// note: do an explict check for admin here (since personExists does not throw 403 unlike createPerson,
|
||||||
// hence next block would cause 409 to be returned)
|
// hence next block would cause 409 to be returned)
|
||||||
@@ -627,16 +623,14 @@ public class PeopleImpl implements People
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the description to a content file and store the content URL in
|
* Write the description to a content file and store the content URL in ContentModel.PROP_PERSONDESC
|
||||||
* ContentModel.PROP_PERSONDESC
|
|
||||||
*
|
*
|
||||||
* @param description
|
* @param description
|
||||||
* @param nodeRef
|
* @param nodeRef
|
||||||
*/
|
*/
|
||||||
private void savePersonDescription(final String description, final NodeRef nodeRef)
|
private void savePersonDescription(final String description, final NodeRef nodeRef)
|
||||||
{
|
{
|
||||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public Void doWork() throws Exception
|
public Void doWork() throws Exception
|
||||||
{
|
{
|
||||||
@@ -678,7 +672,7 @@ public class PeopleImpl implements People
|
|||||||
{
|
{
|
||||||
if (username.toUpperCase().startsWith(prefix))
|
if (username.toUpperCase().startsWith(prefix))
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Username cannot start with the reserved prefix '"+prefix+"'.");
|
throw new IllegalArgumentException("Username cannot start with the reserved prefix '" + prefix + "'.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -687,13 +681,13 @@ public class PeopleImpl implements People
|
|||||||
{
|
{
|
||||||
if (fieldValue == null)
|
if (fieldValue == null)
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException("Field '"+fieldName+"' is null, but is required.");
|
throw new InvalidArgumentException("Field '" + fieldName + "' is null, but is required.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// belts-and-braces - note: should not see empty string (since converted to null via custom json deserializer)
|
// belts-and-braces - note: should not see empty string (since converted to null via custom json deserializer)
|
||||||
if ((fieldValue instanceof String) && ((String)fieldValue).isEmpty())
|
if ((fieldValue instanceof String) && ((String) fieldValue).isEmpty())
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException("Field '"+fieldName+"' is empty, but is required.");
|
throw new InvalidArgumentException("Field '" + fieldName + "' is empty, but is required.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -766,11 +760,11 @@ public class PeopleImpl implements People
|
|||||||
});
|
});
|
||||||
|
|
||||||
// The person service only allows admin users to set the properties by default.
|
// The person service only allows admin users to set the properties by default.
|
||||||
if(!properties.isEmpty())
|
if (!properties.isEmpty())
|
||||||
{
|
{
|
||||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
|
||||||
{
|
@Override
|
||||||
@Override public Void doWork() throws Exception
|
public Void doWork() throws Exception
|
||||||
{
|
{
|
||||||
personService.setPersonProperties(personIdToUpdate, properties, false);
|
personService.setPersonProperties(personIdToUpdate, properties, false);
|
||||||
return null;
|
return null;
|
||||||
|
Reference in New Issue
Block a user