mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS 9185 implement rest api for reauthorizing a single user (#3190)
* ACS-9185 Reauthorize endpoint * ACS-9185 Add the reauthorization code endpoint * ACS-9185 Refactored model * ACS-9185 Fixed rest wrapper implementation --------- Co-authored-by: Damian Ujma <damian.ujma@hyland.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/*-
|
||||
* #%L
|
||||
* alfresco-tas-restapi
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2025 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.alfresco.utility.model.TestModel;
|
||||
|
||||
/**
|
||||
* Authorization code implementation
|
||||
*/
|
||||
public class RestAuthCodeModel extends TestModel
|
||||
{
|
||||
@JsonProperty
|
||||
private String authorizationCode;
|
||||
|
||||
public String getAuthorizationCode()
|
||||
{
|
||||
return authorizationCode;
|
||||
}
|
||||
|
||||
public void setAuthorizationCode(String authorizationCode)
|
||||
{
|
||||
this.authorizationCode = authorizationCode;
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
/*-
|
||||
* #%L
|
||||
* alfresco-tas-restapi
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2025 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.alfresco.utility.model.TestModel;
|
||||
|
||||
/**
|
||||
* Authorization key implementation
|
||||
*/
|
||||
public class RestAuthKeyModel extends TestModel
|
||||
{
|
||||
@JsonProperty(required = true)
|
||||
private String authorizationKey;
|
||||
|
||||
public String getAuthorizationKey()
|
||||
{
|
||||
return authorizationKey;
|
||||
}
|
||||
|
||||
public void setAuthorizationKey(String authorizationKey)
|
||||
{
|
||||
this.authorizationKey = authorizationKey;
|
||||
}
|
||||
}
|
@@ -42,6 +42,8 @@ import org.alfresco.rest.core.RestWrapper;
|
||||
import org.alfresco.rest.exception.EmptyJsonResponseException;
|
||||
import org.alfresco.rest.exception.JsonToModelConversionException;
|
||||
import org.alfresco.rest.model.RestActivityModelsCollection;
|
||||
import org.alfresco.rest.model.RestAuthCodeModel;
|
||||
import org.alfresco.rest.model.RestAuthKeyModel;
|
||||
import org.alfresco.rest.model.RestFavoriteSiteModel;
|
||||
import org.alfresco.rest.model.RestGroupsModelsCollection;
|
||||
import org.alfresco.rest.model.RestNetworkModel;
|
||||
@@ -446,6 +448,31 @@ public class People extends ModelRequest<People>
|
||||
restWrapper.processEmptyModel(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reauthorizes a user.
|
||||
*/
|
||||
public void reauthorizeUser(RestAuthKeyModel authKey)
|
||||
{
|
||||
var request = RestRequest.requestWithBody(HttpMethod.POST, authKey.toJson(), "people/{personId}/reauthorize", this.person.getUsername());
|
||||
restWrapper.processEmptyModel(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reauthorization code.
|
||||
*/
|
||||
public RestAuthCodeModel getReauthorizationCode()
|
||||
{
|
||||
var request = RestRequest.simpleRequest(HttpMethod.POST, "people/{personId}/reauthorization-code", this.person.getUsername());
|
||||
try
|
||||
{
|
||||
return restWrapper.processModel(RestAuthCodeModel.class, request);
|
||||
}
|
||||
catch (JsonToModelConversionException | EmptyJsonResponseException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update avatar image PUT call on 'people/{nodeId}/children
|
||||
*/
|
||||
|
@@ -0,0 +1,65 @@
|
||||
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.rest.model.RestAuthKeyModel;
|
||||
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 ReauthorizeSanityTests 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 reauthorization is not implemented in Community Edition")
|
||||
public void reauthorizationIsNotImplementedInCommunityEdition()
|
||||
{
|
||||
// given
|
||||
var key = new RestAuthKeyModel();
|
||||
key.setAuthorizationKey("am9obnRlc3RAMTIzNDU=");
|
||||
|
||||
// when admin invokes API
|
||||
restClient.authenticateUser(adminUser).withCoreAPI().usingUser(userModel).reauthorizeUser(key);
|
||||
// then
|
||||
restClient.assertStatusCodeIs(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
// when user invokes API
|
||||
restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).reauthorizeUser(key);
|
||||
// then
|
||||
restClient.assertStatusCodeIs(HttpStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
@Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.SANITY})
|
||||
@TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE}, executionType = ExecutionType.SANITY,
|
||||
description = "Check if the reauthorization code is not implemented in Community Edition")
|
||||
public void reauthorizationCodeIsNotImplementedInCommunityEdition()
|
||||
{
|
||||
// when admin invokes API
|
||||
restClient.authenticateUser(adminUser).withCoreAPI().usingUser(userModel).getReauthorizationCode();
|
||||
// then
|
||||
restClient.assertStatusCodeIs(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
// when user invokes API
|
||||
restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).getReauthorizationCode();
|
||||
// then
|
||||
restClient.assertStatusCodeIs(HttpStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2025 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
/**
|
||||
* An object representing user authorization code.
|
||||
*/
|
||||
public record AuthCode(String authorizationCode)
|
||||
{}
|
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2025 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.length;
|
||||
|
||||
/**
|
||||
* An object representing user authorization key request body.
|
||||
*/
|
||||
public record AuthKey(String authorizationKey)
|
||||
{
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
// for security reasons the key content should be never logged
|
||||
return "AuthKey[" +
|
||||
"authorizationKeyLength=" + length(authorizationKey) +
|
||||
']';
|
||||
}
|
||||
}
|
@@ -34,6 +34,8 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.rest.api.People;
|
||||
import org.alfresco.rest.api.model.AuthCode;
|
||||
import org.alfresco.rest.api.model.AuthKey;
|
||||
import org.alfresco.rest.api.model.Client;
|
||||
import org.alfresco.rest.api.model.PasswordReset;
|
||||
import org.alfresco.rest.api.model.Person;
|
||||
@@ -245,4 +247,29 @@ public class PeopleEntityResource implements EntityResourceAction.ReadById<Perso
|
||||
{
|
||||
// functionality is not implemented in community edition
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authorization code.
|
||||
*
|
||||
* Not supported in community edition.
|
||||
*/
|
||||
@Operation("reauthorization-code")
|
||||
@WebApiDescription(title = "Get the reauthorization code", description = "Get the reauthorization code", successStatus = HttpServletResponse.SC_NOT_IMPLEMENTED)
|
||||
public AuthCode getReauthorizationCode(String personId, Void body, Parameters parameters, WithResponse withResponse)
|
||||
{
|
||||
// functionality is not implemented in community edition
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reauthorize user.
|
||||
*
|
||||
* Not supported in community edition.
|
||||
*/
|
||||
@Operation("reauthorize")
|
||||
@WebApiDescription(title = "Reauthorize user", description = "Performs user reauthorization", successStatus = HttpServletResponse.SC_NOT_IMPLEMENTED)
|
||||
public void reauthorizeUser(String personId, AuthKey authKey, Parameters parameters, WithResponse withResponse)
|
||||
{
|
||||
// functionality is not implemented in community edition
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user