Skip to content

Commit

Permalink
feat: Update calls to UserACL to avoid implicit usage of Conversation…
Browse files Browse the repository at this point in the history
… State in Service Layer - MEED-7555 - Meeds-io/MIPs#151 (#1146)

This change will update UserACL usage to not implicitly use the current
conversation state of authenticated user.
  • Loading branch information
boubaker authored and exo-swf committed Oct 7, 2024
1 parent c59c673 commit 4ddc922
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.portal.config.UserACL;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.mop.PageType;
import org.exoplatform.portal.mop.page.PageContext;
import org.exoplatform.portal.mop.page.PageKey;
import org.exoplatform.portal.mop.page.PageState;
import org.exoplatform.portal.mop.service.LayoutService;
import org.exoplatform.services.rest.impl.ContainerResponse;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import org.exoplatform.services.security.ConversationState;
import org.exoplatform.services.security.IdentityRegistry;
import org.exoplatform.services.security.MembershipEntry;
import org.exoplatform.social.rest.api.RestUtils;
Expand Down Expand Up @@ -112,14 +112,18 @@ public void testGetNotePageWithAnonim() throws ObjectAlreadyExistsException {
Page notePage = getNotePage(pageNoteName, null);
assertNull(notePage);

assertEquals(403, saveNotePage(pageNoteName, pageContent, null).getStatus());

resetRestUtils();
registerInternalUser(USERNAME);
assertEquals(401, saveNotePage(pageNoteName, pageContent, null).getStatus());
assertEquals(404, saveNotePage(pageNoteName + "22", pageContent, null).getStatus());

registerAdministratorUser(USERNAME);
saveNotePage(pageNoteName, pageContent, null);
assertEquals(204, saveNotePage(pageNoteName, pageContent, null).getStatus());
restartTransaction();

resetRestUtils();
registerInternalUser(USERNAME);
notePage = getNotePage(pageNoteName, null);
assertNotNull(notePage);
assertEquals(pageContent, notePage.getContent());
Expand Down Expand Up @@ -186,14 +190,9 @@ private String createPage(String pageName, String accessPermission, String editP
PageState pageState = new PageState(pageName,
null,
false,
false,
null,
Collections.singletonList(accessPermission),
editPermission,
Collections.singletonList(editPermission),
Collections.singletonList(editPermission),
PageType.PAGE.name(),
null);
editPermission);
layoutService.save(new PageContext(pageKey, pageState));
return pageKey.format();
}
Expand Down Expand Up @@ -254,8 +253,9 @@ private ContainerResponse saveNotePage(String name, String content, String lang)
private org.exoplatform.services.security.Identity registerAdministratorUser(String user) {
org.exoplatform.services.security.Identity identity =
new org.exoplatform.services.security.Identity(user,
Arrays.asList(MembershipEntry.parse(ADMINISTRATORS_GROUP)));
Arrays.asList(MembershipEntry.parse(ADMINISTRATORS_GROUP), MembershipEntry.parse(USERS_GROUP)));
identityRegistry.register(identity);
ConversationState.setCurrent(new ConversationState(identity));
resetRestUtils();
REST_UTILS.when(RestUtils::getCurrentUser).thenReturn(USERNAME);
REST_UTILS.when(RestUtils::getCurrentUserAclIdentity).thenReturn(identity);
Expand All @@ -267,6 +267,7 @@ private org.exoplatform.services.security.Identity registerInternalUser(String u
new org.exoplatform.services.security.Identity(username,
Arrays.asList(MembershipEntry.parse(USERS_GROUP)));
identityRegistry.register(identity);
ConversationState.setCurrent(new ConversationState(identity));
resetRestUtils();
REST_UTILS.when(RestUtils::getCurrentUser).thenReturn(USERNAME);
REST_UTILS.when(RestUtils::getCurrentUserAclIdentity).thenReturn(identity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.exoplatform.commons.exception.ObjectNotFoundException;
import org.exoplatform.portal.config.UserACL;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.mop.PageType;
import org.exoplatform.portal.mop.page.PageContext;
import org.exoplatform.portal.mop.page.PageKey;
import org.exoplatform.portal.mop.page.PageState;
Expand Down Expand Up @@ -161,14 +160,9 @@ private String createPage(String pageName, String accessPermission, String editP
PageState pageState = new PageState(pageName,
null,
false,
false,
null,
Collections.singletonList(accessPermission),
editPermission,
Collections.singletonList(editPermission),
Collections.singletonList(editPermission),
PageType.PAGE.name(),
null);
editPermission);
layoutService.save(new PageContext(pageKey, pageState));
return pageKey.format();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,9 @@

import org.exoplatform.container.xml.InitParams;
import org.exoplatform.portal.config.UserACL;
import org.exoplatform.portal.config.model.Page;

public class MockUserACL extends UserACL {

/* (non-Javadoc)
* @see org.exoplatform.portal.config.UserACL#hasPermission(org.exoplatform.portal.config.model.Page)
*/
@Override
public boolean hasPermission(Page page) {
return true;
}

/**
* @param params
*/
Expand Down

0 comments on commit 4ddc922

Please sign in to comment.