@Test public void testValidUpdate() { setRealms(REALM_ID); EntityBody body = getValidRoleDoc(); mockGetRealmId(); String id = "old-id"; Mockito.when(service.get(id)).thenReturn((EntityBody) body.clone()); body.put("roles", new ArrayList<Map<String, List<String>>>()); Mockito.when(service.update(id, body, false)).thenReturn(true); Response res = resource.updateCustomRole(id, body, uriInfo); Assert.assertEquals(204, res.getStatus()); }
@PUT @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) public Response updateCustomRole(@PathParam("id") String id, EntityBody updated, @Context final UriInfo uriInfo) { Response res = validateRights(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role rights validation failed.",null); return res; } res = validateUniqueRoles(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role unique roles check failed.",null); return res; } res = validateValidRealm(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role invalid realm specified.",null); return res; } EntityBody oldRealm = service.get(id); String oldRealmId = (String) oldRealm.get("realmId"); String updatedRealmId = (String) updated.get("realmId"); if (!updatedRealmId.equals(oldRealmId)) { auditSecEvent(uriInfo, "Failed to update realmId { from: " + oldRealmId + ", to: " + updatedRealmId + " } for role with id:" + id, oldRealmId); return buildBadRequest(ERROR_CHANGING_REALM_ID + ": '" + oldRealmId + "' -> '" + updatedRealmId + "'"); } if (service.update(id, updated, false)) { auditSecEvent(uriInfo, "Updated role with id:" + id,oldRealmId); this.sessions.clear(); return Response.status(Status.NO_CONTENT).build(); } return Response.status(Status.BAD_REQUEST).build(); }
CustomRoleResource { @PUT @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) public Response updateCustomRole(@PathParam("id") String id, EntityBody updated, @Context final UriInfo uriInfo) { Response res = validateRights(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role rights validation failed.",null); return res; } res = validateUniqueRoles(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role unique roles check failed.",null); return res; } res = validateValidRealm(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role invalid realm specified.",null); return res; } EntityBody oldRealm = service.get(id); String oldRealmId = (String) oldRealm.get("realmId"); String updatedRealmId = (String) updated.get("realmId"); if (!updatedRealmId.equals(oldRealmId)) { auditSecEvent(uriInfo, "Failed to update realmId { from: " + oldRealmId + ", to: " + updatedRealmId + " } for role with id:" + id, oldRealmId); return buildBadRequest(ERROR_CHANGING_REALM_ID + ": '" + oldRealmId + "' -> '" + updatedRealmId + "'"); } if (service.update(id, updated, false)) { auditSecEvent(uriInfo, "Updated role with id:" + id,oldRealmId); this.sessions.clear(); return Response.status(Status.NO_CONTENT).build(); } return Response.status(Status.BAD_REQUEST).build(); } }
CustomRoleResource { @PUT @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) public Response updateCustomRole(@PathParam("id") String id, EntityBody updated, @Context final UriInfo uriInfo) { Response res = validateRights(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role rights validation failed.",null); return res; } res = validateUniqueRoles(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role unique roles check failed.",null); return res; } res = validateValidRealm(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role invalid realm specified.",null); return res; } EntityBody oldRealm = service.get(id); String oldRealmId = (String) oldRealm.get("realmId"); String updatedRealmId = (String) updated.get("realmId"); if (!updatedRealmId.equals(oldRealmId)) { auditSecEvent(uriInfo, "Failed to update realmId { from: " + oldRealmId + ", to: " + updatedRealmId + " } for role with id:" + id, oldRealmId); return buildBadRequest(ERROR_CHANGING_REALM_ID + ": '" + oldRealmId + "' -> '" + updatedRealmId + "'"); } if (service.update(id, updated, false)) { auditSecEvent(uriInfo, "Updated role with id:" + id,oldRealmId); this.sessions.clear(); return Response.status(Status.NO_CONTENT).build(); } return Response.status(Status.BAD_REQUEST).build(); }  }
CustomRoleResource { @PUT @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) public Response updateCustomRole(@PathParam("id") String id, EntityBody updated, @Context final UriInfo uriInfo) { Response res = validateRights(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role rights validation failed.",null); return res; } res = validateUniqueRoles(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role unique roles check failed.",null); return res; } res = validateValidRealm(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role invalid realm specified.",null); return res; } EntityBody oldRealm = service.get(id); String oldRealmId = (String) oldRealm.get("realmId"); String updatedRealmId = (String) updated.get("realmId"); if (!updatedRealmId.equals(oldRealmId)) { auditSecEvent(uriInfo, "Failed to update realmId { from: " + oldRealmId + ", to: " + updatedRealmId + " } for role with id:" + id, oldRealmId); return buildBadRequest(ERROR_CHANGING_REALM_ID + ": '" + oldRealmId + "' -> '" + updatedRealmId + "'"); } if (service.update(id, updated, false)) { auditSecEvent(uriInfo, "Updated role with id:" + id,oldRealmId); this.sessions.clear(); return Response.status(Status.NO_CONTENT).build(); } return Response.status(Status.BAD_REQUEST).build(); }  @PostConstruct void init(); @GET @RightsAllowed({Right.CRUD_ROLE }) Response readAll(@Context final UriInfo uriInfo,
            @DefaultValue("") @QueryParam("realmId") String realmId); @GET @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) Response read(@PathParam("id") String id, @Context final UriInfo uriInfo); @POST @RightsAllowed({Right.CRUD_ROLE }) Response createCustomRole(EntityBody newCustomRole, @Context final UriInfo uriInfo); @PUT @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) Response updateCustomRole(@PathParam("id") String id, EntityBody updated, @Context final UriInfo uriInfo); @DELETE @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) Response deleteCustomRole(@PathParam("id") String id, @Context final UriInfo uriInfo); }
CustomRoleResource { @PUT @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) public Response updateCustomRole(@PathParam("id") String id, EntityBody updated, @Context final UriInfo uriInfo) { Response res = validateRights(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role rights validation failed.",null); return res; } res = validateUniqueRoles(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role unique roles check failed.",null); return res; } res = validateValidRealm(updated); if (res != null) { auditSecEvent(uriInfo, "Failed to create custom role invalid realm specified.",null); return res; } EntityBody oldRealm = service.get(id); String oldRealmId = (String) oldRealm.get("realmId"); String updatedRealmId = (String) updated.get("realmId"); if (!updatedRealmId.equals(oldRealmId)) { auditSecEvent(uriInfo, "Failed to update realmId { from: " + oldRealmId + ", to: " + updatedRealmId + " } for role with id:" + id, oldRealmId); return buildBadRequest(ERROR_CHANGING_REALM_ID + ": '" + oldRealmId + "' -> '" + updatedRealmId + "'"); } if (service.update(id, updated, false)) { auditSecEvent(uriInfo, "Updated role with id:" + id,oldRealmId); this.sessions.clear(); return Response.status(Status.NO_CONTENT).build(); } return Response.status(Status.BAD_REQUEST).build(); }  @PostConstruct void init(); @GET @RightsAllowed({Right.CRUD_ROLE }) Response readAll(@Context final UriInfo uriInfo,
            @DefaultValue("") @QueryParam("realmId") String realmId); @GET @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) Response read(@PathParam("id") String id, @Context final UriInfo uriInfo); @POST @RightsAllowed({Right.CRUD_ROLE }) Response createCustomRole(EntityBody newCustomRole, @Context final UriInfo uriInfo); @PUT @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) Response updateCustomRole(@PathParam("id") String id, EntityBody updated, @Context final UriInfo uriInfo); @DELETE @Path("{id}") @RightsAllowed({Right.CRUD_ROLE }) Response deleteCustomRole(@PathParam("id") String id, @Context final UriInfo uriInfo); static final String RESOURCE_NAME; }