@Test public final void shouldMarkAddingRoleSuperadminAsInvalidWhenPerformedByNonSuperadmin() { stubSecurityContextWithAuthentication(); stubCurrentUserRole(QcadooSecurityConstants.ROLE_USER); stubGroupRoles(existingUserGroupMock, QcadooSecurityConstants.ROLE_ADMIN); stubGroupRoles(userGroupMock, QcadooSecurityConstants.ROLE_ADMIN, QcadooSecurityConstants.ROLE_SUPERADMIN); final boolean isValid = groupRolesValidationService.checkUserAddingRoleSuperadmin(groupDataDefMock, userGroupMock); assertFalse(isValid); verify(userGroupMock).addError(Mockito.eq(groupRolesFieldDefMock), Mockito.anyString()); }
public boolean checkUserAddingRoleSuperadmin(final DataDefinition dataDefinition, final Entity entity) { Boolean isRoleSuperadminInNewGroup = hasRoleSuperAdmin(entity); Boolean isRoleSuperadminInOldGroup = entity.getId() == null ? false : hasRoleSuperAdmin(dataDefinition.get(entity.getId())); if (Objects.equal(isRoleSuperadminInNewGroup, isRoleSuperadminInOldGroup) || isCurrentUserShopOrSuperAdmin(dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_USER))) { return true; } entity.addError(dataDefinition.getField(GroupFields.ROLES), "qcadooUsers.validate.global.error.forbiddenRole"); return false; }
GroupRolesValidationService { public boolean checkUserAddingRoleSuperadmin(final DataDefinition dataDefinition, final Entity entity) { Boolean isRoleSuperadminInNewGroup = hasRoleSuperAdmin(entity); Boolean isRoleSuperadminInOldGroup = entity.getId() == null ? false : hasRoleSuperAdmin(dataDefinition.get(entity.getId())); if (Objects.equal(isRoleSuperadminInNewGroup, isRoleSuperadminInOldGroup) || isCurrentUserShopOrSuperAdmin(dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_USER))) { return true; } entity.addError(dataDefinition.getField(GroupFields.ROLES), "qcadooUsers.validate.global.error.forbiddenRole"); return false; } }
GroupRolesValidationService { public boolean checkUserAddingRoleSuperadmin(final DataDefinition dataDefinition, final Entity entity) { Boolean isRoleSuperadminInNewGroup = hasRoleSuperAdmin(entity); Boolean isRoleSuperadminInOldGroup = entity.getId() == null ? false : hasRoleSuperAdmin(dataDefinition.get(entity.getId())); if (Objects.equal(isRoleSuperadminInNewGroup, isRoleSuperadminInOldGroup) || isCurrentUserShopOrSuperAdmin(dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_USER))) { return true; } entity.addError(dataDefinition.getField(GroupFields.ROLES), "qcadooUsers.validate.global.error.forbiddenRole"); return false; }  }
GroupRolesValidationService { public boolean checkUserAddingRoleSuperadmin(final DataDefinition dataDefinition, final Entity entity) { Boolean isRoleSuperadminInNewGroup = hasRoleSuperAdmin(entity); Boolean isRoleSuperadminInOldGroup = entity.getId() == null ? false : hasRoleSuperAdmin(dataDefinition.get(entity.getId())); if (Objects.equal(isRoleSuperadminInNewGroup, isRoleSuperadminInOldGroup) || isCurrentUserShopOrSuperAdmin(dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_USER))) { return true; } entity.addError(dataDefinition.getField(GroupFields.ROLES), "qcadooUsers.validate.global.error.forbiddenRole"); return false; }  boolean checkUserAddingRoleSuperadmin(final DataDefinition dataDefinition, final Entity entity); }
GroupRolesValidationService { public boolean checkUserAddingRoleSuperadmin(final DataDefinition dataDefinition, final Entity entity) { Boolean isRoleSuperadminInNewGroup = hasRoleSuperAdmin(entity); Boolean isRoleSuperadminInOldGroup = entity.getId() == null ? false : hasRoleSuperAdmin(dataDefinition.get(entity.getId())); if (Objects.equal(isRoleSuperadminInNewGroup, isRoleSuperadminInOldGroup) || isCurrentUserShopOrSuperAdmin(dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_USER))) { return true; } entity.addError(dataDefinition.getField(GroupFields.ROLES), "qcadooUsers.validate.global.error.forbiddenRole"); return false; }  boolean checkUserAddingRoleSuperadmin(final DataDefinition dataDefinition, final Entity entity);  }