@Test public final void shouldMarkTransitionFromAdminToSuperadminAsInvalid() { stubSecurityContextWithAuthentication(); stubRoleTransition(ROLE_ADMIN, ROLE_SUPERADMIN); final boolean isValid = userRoleValidationService.checkUserCreatingSuperadmin(userDataDefMock, userEntityMock); assertFalse(isValid); verify(userEntityMock).addError(Mockito.eq(userRoleFieldDefMock), Mockito.anyString()); }
public boolean checkUserCreatingSuperadmin(final DataDefinition dataDefinition, final Entity entity) { Boolean isRoleSuperadminInNewGroup = securityService.hasRole(entity, QcadooSecurityConstants.ROLE_SUPERADMIN); Boolean isRoleSuperadminInOldGroup = entity.getId() == null ? false : securityService.hasRole( dataDefinition.get(entity.getId()), QcadooSecurityConstants.ROLE_SUPERADMIN); if (Objects.equal(isRoleSuperadminInOldGroup, isRoleSuperadminInNewGroup) || isCurrentUserShopOrSuperAdmin(dataDefinition)) { return true; } entity.addError(dataDefinition.getField(UserFields.GROUP), "qcadooUsers.validate.global.error.forbiddenRole"); return false; }
UserRoleValidationService { public boolean checkUserCreatingSuperadmin(final DataDefinition dataDefinition, final Entity entity) { Boolean isRoleSuperadminInNewGroup = securityService.hasRole(entity, QcadooSecurityConstants.ROLE_SUPERADMIN); Boolean isRoleSuperadminInOldGroup = entity.getId() == null ? false : securityService.hasRole( dataDefinition.get(entity.getId()), QcadooSecurityConstants.ROLE_SUPERADMIN); if (Objects.equal(isRoleSuperadminInOldGroup, isRoleSuperadminInNewGroup) || isCurrentUserShopOrSuperAdmin(dataDefinition)) { return true; } entity.addError(dataDefinition.getField(UserFields.GROUP), "qcadooUsers.validate.global.error.forbiddenRole"); return false; } }
UserRoleValidationService { public boolean checkUserCreatingSuperadmin(final DataDefinition dataDefinition, final Entity entity) { Boolean isRoleSuperadminInNewGroup = securityService.hasRole(entity, QcadooSecurityConstants.ROLE_SUPERADMIN); Boolean isRoleSuperadminInOldGroup = entity.getId() == null ? false : securityService.hasRole( dataDefinition.get(entity.getId()), QcadooSecurityConstants.ROLE_SUPERADMIN); if (Objects.equal(isRoleSuperadminInOldGroup, isRoleSuperadminInNewGroup) || isCurrentUserShopOrSuperAdmin(dataDefinition)) { return true; } entity.addError(dataDefinition.getField(UserFields.GROUP), "qcadooUsers.validate.global.error.forbiddenRole"); return false; }  }
UserRoleValidationService { public boolean checkUserCreatingSuperadmin(final DataDefinition dataDefinition, final Entity entity) { Boolean isRoleSuperadminInNewGroup = securityService.hasRole(entity, QcadooSecurityConstants.ROLE_SUPERADMIN); Boolean isRoleSuperadminInOldGroup = entity.getId() == null ? false : securityService.hasRole( dataDefinition.get(entity.getId()), QcadooSecurityConstants.ROLE_SUPERADMIN); if (Objects.equal(isRoleSuperadminInOldGroup, isRoleSuperadminInNewGroup) || isCurrentUserShopOrSuperAdmin(dataDefinition)) { return true; } entity.addError(dataDefinition.getField(UserFields.GROUP), "qcadooUsers.validate.global.error.forbiddenRole"); return false; }  boolean checkUserCreatingSuperadmin(final DataDefinition dataDefinition, final Entity entity); }
UserRoleValidationService { public boolean checkUserCreatingSuperadmin(final DataDefinition dataDefinition, final Entity entity) { Boolean isRoleSuperadminInNewGroup = securityService.hasRole(entity, QcadooSecurityConstants.ROLE_SUPERADMIN); Boolean isRoleSuperadminInOldGroup = entity.getId() == null ? false : securityService.hasRole( dataDefinition.get(entity.getId()), QcadooSecurityConstants.ROLE_SUPERADMIN); if (Objects.equal(isRoleSuperadminInOldGroup, isRoleSuperadminInNewGroup) || isCurrentUserShopOrSuperAdmin(dataDefinition)) { return true; } entity.addError(dataDefinition.getField(UserFields.GROUP), "qcadooUsers.validate.global.error.forbiddenRole"); return false; }  boolean checkUserCreatingSuperadmin(final DataDefinition dataDefinition, final Entity entity);  }