mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ACS-9178 Add REST API for deauthorizing (#3169)
* ACS-9178 Set peopleEntityResource bean id * ACS-9178 Add the 'deauthorizeUser' operation * ACS-9178 Add 'deauthorizeUser' to Rest API * ACS-9178 Add test * ACS-9178 Fix PMD * ACS-9178 Fix deauthorize API tests --------- Co-authored-by: Gerard Olenski <gerard.olenski@hyland.com>
This commit is contained in:
@@ -437,6 +437,15 @@ public class People extends ModelRequest<People>
|
|||||||
restWrapper.processEmptyModel(request);
|
restWrapper.processEmptyModel(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deauthorize a user
|
||||||
|
*/
|
||||||
|
public void deauthorizeUser()
|
||||||
|
{
|
||||||
|
RestRequest request = RestRequest.simpleRequest(HttpMethod.POST, "people/{personId}/deauthorize", this.person.getUsername(), restWrapper.getParameters());
|
||||||
|
restWrapper.processEmptyModel(request);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update avatar image PUT call on 'people/{nodeId}/children
|
* Update avatar image PUT call on 'people/{nodeId}/children
|
||||||
*/
|
*/
|
||||||
|
@@ -0,0 +1,40 @@
|
|||||||
|
package org.alfresco.rest.people.deauthorization.community;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import org.alfresco.rest.RestTest;
|
||||||
|
import org.alfresco.utility.model.TestGroup;
|
||||||
|
import org.alfresco.utility.model.UserModel;
|
||||||
|
import org.alfresco.utility.testrail.ExecutionType;
|
||||||
|
import org.alfresco.utility.testrail.annotation.TestRail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies API behavior in community edition. Should be excluded in enterprise edition.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public class DeauthorizeSanityTests extends RestTest
|
||||||
|
{
|
||||||
|
private UserModel userModel;
|
||||||
|
private UserModel adminUser;
|
||||||
|
|
||||||
|
@BeforeClass(alwaysRun = true)
|
||||||
|
public void dataPreparation()
|
||||||
|
{
|
||||||
|
adminUser = dataUser.getAdminUser();
|
||||||
|
userModel = dataUser.createRandomTestUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY})
|
||||||
|
@TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE}, executionType = ExecutionType.SANITY,
|
||||||
|
description = "Check if de-authorization is not implemented in Community Edition")
|
||||||
|
public void deauthorizationIsNotImplementedInCommunityEdition()
|
||||||
|
{
|
||||||
|
restClient.authenticateUser(adminUser).withCoreAPI().usingUser(userModel).deauthorizeUser();
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.NOT_IMPLEMENTED);
|
||||||
|
|
||||||
|
restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).deauthorizeUser();
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.NOT_IMPLEMENTED);
|
||||||
|
}
|
||||||
|
}
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Remote API
|
* Alfresco Remote API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2023 Alfresco Software Limited
|
* Copyright (C) 2005 - 2025 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -28,9 +28,10 @@ package org.alfresco.rest.api.people;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.rest.api.People;
|
import org.alfresco.rest.api.People;
|
||||||
import org.alfresco.rest.api.model.Client;
|
import org.alfresco.rest.api.model.Client;
|
||||||
@@ -53,9 +54,6 @@ import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
|||||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||||
import org.alfresco.rest.framework.webscripts.WithResponse;
|
import org.alfresco.rest.framework.webscripts.WithResponse;
|
||||||
import org.alfresco.util.PropertyCheck;
|
import org.alfresco.util.PropertyCheck;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of an Entity Resource for a Person
|
* An implementation of an Entity Resource for a Person
|
||||||
@@ -63,14 +61,12 @@ import org.springframework.beans.factory.InitializingBean;
|
|||||||
* @author sglover
|
* @author sglover
|
||||||
* @author Gethin James
|
* @author Gethin James
|
||||||
*/
|
*/
|
||||||
@EntityResource(name="people", title = "People")
|
@EntityResource(name = "people", title = "People")
|
||||||
public class PeopleEntityResource implements EntityResourceAction.ReadById<Person>, EntityResourceAction.Create<Person>,
|
public class PeopleEntityResource implements EntityResourceAction.ReadById<Person>, EntityResourceAction.Create<Person>,
|
||||||
EntityResourceAction.Update<Person>,EntityResourceAction.Read<Person>,
|
EntityResourceAction.Update<Person>, EntityResourceAction.Read<Person>,
|
||||||
|
|
||||||
BinaryResourceAction.Read, BinaryResourceAction.Update<Person>, BinaryResourceAction.Delete, InitializingBean
|
BinaryResourceAction.Read, BinaryResourceAction.Update<Person>, BinaryResourceAction.Delete, InitializingBean
|
||||||
{
|
{
|
||||||
private static Log logger = LogFactory.getLog(PeopleEntityResource.class);
|
|
||||||
|
|
||||||
private People people;
|
private People people;
|
||||||
|
|
||||||
public void setPeople(People people)
|
public void setPeople(People people)
|
||||||
@@ -99,9 +95,9 @@ public class PeopleEntityResource implements EntityResourceAction.ReadById<Perso
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@WebApiDescription(title="Create person", description="Create a person")
|
@WebApiDescription(title = "Create person", description = "Create a person")
|
||||||
@WebApiParam(name="persons", title="A single person", description="A single person, multiple people are not supported.",
|
@WebApiParam(name = "persons", title = "A single person", description = "A single person, multiple people are not supported.",
|
||||||
kind= ResourceParameter.KIND.HTTP_BODY_OBJECT, allowMultiple=false, required = true)
|
kind = ResourceParameter.KIND.HTTP_BODY_OBJECT, allowMultiple = false, required = true)
|
||||||
public List<Person> create(List<Person> persons, Parameters parameters)
|
public List<Person> create(List<Person> persons, Parameters parameters)
|
||||||
{
|
{
|
||||||
Person p = persons.get(0);
|
Person p = persons.get(0);
|
||||||
@@ -114,7 +110,7 @@ public class PeopleEntityResource implements EntityResourceAction.ReadById<Perso
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@WebApiDescription(title="Update person", description="Update the given person's details")
|
@WebApiDescription(title = "Update person", description = "Update the given person's details")
|
||||||
public Person update(String personId, Person person, Parameters parameters)
|
public Person update(String personId, Person person, Parameters parameters)
|
||||||
{
|
{
|
||||||
if (person.wasSet(ContentModel.PROP_USERNAME))
|
if (person.wasSet(ContentModel.PROP_USERNAME))
|
||||||
@@ -166,7 +162,7 @@ public class PeopleEntityResource implements EntityResourceAction.ReadById<Perso
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
@Operation("request-password-reset")
|
@Operation("request-password-reset")
|
||||||
@WebApiDescription(title = "Request Password Reset", description = "Request password reset",
|
@WebApiDescription(title = "Request Password Reset", description = "Request password reset",
|
||||||
successStatus = HttpServletResponse.SC_ACCEPTED)
|
successStatus = HttpServletResponse.SC_ACCEPTED)
|
||||||
@WebApiNoAuth
|
@WebApiNoAuth
|
||||||
public void requestPasswordReset(String personId, Client client, Parameters parameters, WithResponse withResponse)
|
public void requestPasswordReset(String personId, Client client, Parameters parameters, WithResponse withResponse)
|
||||||
{
|
{
|
||||||
@@ -186,7 +182,8 @@ public class PeopleEntityResource implements EntityResourceAction.ReadById<Perso
|
|||||||
* Download avatar image content
|
* Download avatar image content
|
||||||
*
|
*
|
||||||
* @param personId
|
* @param personId
|
||||||
* @param parameters {@link Parameters}
|
* @param parameters
|
||||||
|
* {@link Parameters}
|
||||||
* @return
|
* @return
|
||||||
* @throws EntityNotFoundException
|
* @throws EntityNotFoundException
|
||||||
*/
|
*/
|
||||||
@@ -202,8 +199,10 @@ public class PeopleEntityResource implements EntityResourceAction.ReadById<Perso
|
|||||||
* Upload avatar image content
|
* Upload avatar image content
|
||||||
*
|
*
|
||||||
* @param personId
|
* @param personId
|
||||||
* @param contentInfo Basic information about the content stream
|
* @param contentInfo
|
||||||
* @param stream An inputstream
|
* Basic information about the content stream
|
||||||
|
* @param stream
|
||||||
|
* An inputstream
|
||||||
* @param parameters
|
* @param parameters
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -224,11 +223,26 @@ public class PeopleEntityResource implements EntityResourceAction.ReadById<Perso
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@WebApiDescription(title = "Delete avatar image", description = "Delete avatar image")
|
@WebApiDescription(title = "Delete avatar image", description = "Delete avatar image")
|
||||||
@BinaryProperties({ "avatar" })
|
@BinaryProperties({"avatar"})
|
||||||
public void deleteProperty(String personId, Parameters parameters)
|
public void deleteProperty(String personId, Parameters parameters)
|
||||||
{
|
{
|
||||||
people.deleteAvatarContent(personId);
|
people.deleteAvatarContent(personId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* De-authorize user
|
||||||
|
*
|
||||||
|
* Not currently supported in community edition.
|
||||||
|
*
|
||||||
|
* @param personId
|
||||||
|
* @param body
|
||||||
|
* @param parameters
|
||||||
|
* @param withResponse
|
||||||
|
*/
|
||||||
|
@Operation("deauthorize")
|
||||||
|
@WebApiDescription(title = "De-authorize user", description = "Performs user de-authorization", successStatus = HttpServletResponse.SC_NOT_IMPLEMENTED)
|
||||||
|
public void deauthorizeUser(String personId, Void body, Parameters parameters, WithResponse withResponse)
|
||||||
|
{
|
||||||
|
// functionality is not implemented in community edition
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1116,7 +1116,7 @@
|
|||||||
<property name="siteMembershipRequests" ref="SiteMembershipRequests" />
|
<property name="siteMembershipRequests" ref="SiteMembershipRequests" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean class="org.alfresco.rest.api.people.PeopleEntityResource">
|
<bean id="peopleEntityResource" class="org.alfresco.rest.api.people.PeopleEntityResource">
|
||||||
<property name="people" ref="People" />
|
<property name="people" ref="People" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user