@Test public void testAddClientRole() throws Exception { try { resource.updateRealm("-1", null, null); assertFalse(false); } catch (IllegalArgumentException e) { assertTrue(true); } UriInfo uriInfo = ResourceTestUtil.buildMockUriInfo(""); Response res = resource.updateRealm("1234", mapping, uriInfo); Assert.assertEquals(Status.BAD_REQUEST.getStatusCode(), res.getStatus()); idp.put(RealmResource.SOURCE_ID, "ccf4f3895f6e37896e7511ed1d991b1d96f04ac1"); res = resource.updateRealm("1234", mapping, uriInfo); Assert.assertEquals(204, res.getStatus()); idp.remove(RealmResource.SOURCE_ID); }
@PUT @Path("{realmId}") @Consumes("application/json") @RightsAllowed({ Right.CRUD_REALM }) public Response updateRealm(@PathParam("realmId") String realmId, EntityBody updatedRealm, @Context final UriInfo uriInfo) { if (updatedRealm == null) { throw new IllegalArgumentException("Updated Realm was null"); } EntityBody oldRealm = service.get(realmId); if (!canEditCurrentRealm(updatedRealm) || oldRealm.get(ED_ORG) != null && !oldRealm.get(ED_ORG).equals(SecurityUtil.getEdOrg())) { EntityBody body = new EntityBody(); body.put(RESPONSE, "You are not authorized to update this realm."); return Response.status(Status.FORBIDDEN).entity(body).build(); } Response validateUniqueness = validateUniqueId(realmId, (String) updatedRealm.get(UNIQUE_IDENTIFIER), (String) updatedRealm.get(NAME), getIdpId(updatedRealm)); if (validateUniqueness != null) { return validateUniqueness; } Map<String, Object> idp = (Map<String, Object>) updatedRealm.get(IDP); Response validateArtifactResolution = validateArtifactResolution((String) idp.get(ARTIFACT_RESOLUTION_ENDPOINT), (String) idp.get(SOURCE_ID)); if (validateArtifactResolution != null) { LOG.debug("Invalid artifact resolution information"); return validateArtifactResolution; } updatedRealm.put("tenantId", SecurityUtil.getTenantId()); updatedRealm.put(ED_ORG, SecurityUtil.getEdOrg()); if (service.update(realmId, updatedRealm, false)) { logSecurityEvent(uriInfo, oldRealm, updatedRealm); return Response.status(Status.NO_CONTENT).build(); } return Response.status(Status.BAD_REQUEST).build(); }
RealmResource { @PUT @Path("{realmId}") @Consumes("application/json") @RightsAllowed({ Right.CRUD_REALM }) public Response updateRealm(@PathParam("realmId") String realmId, EntityBody updatedRealm, @Context final UriInfo uriInfo) { if (updatedRealm == null) { throw new IllegalArgumentException("Updated Realm was null"); } EntityBody oldRealm = service.get(realmId); if (!canEditCurrentRealm(updatedRealm) || oldRealm.get(ED_ORG) != null && !oldRealm.get(ED_ORG).equals(SecurityUtil.getEdOrg())) { EntityBody body = new EntityBody(); body.put(RESPONSE, "You are not authorized to update this realm."); return Response.status(Status.FORBIDDEN).entity(body).build(); } Response validateUniqueness = validateUniqueId(realmId, (String) updatedRealm.get(UNIQUE_IDENTIFIER), (String) updatedRealm.get(NAME), getIdpId(updatedRealm)); if (validateUniqueness != null) { return validateUniqueness; } Map<String, Object> idp = (Map<String, Object>) updatedRealm.get(IDP); Response validateArtifactResolution = validateArtifactResolution((String) idp.get(ARTIFACT_RESOLUTION_ENDPOINT), (String) idp.get(SOURCE_ID)); if (validateArtifactResolution != null) { LOG.debug("Invalid artifact resolution information"); return validateArtifactResolution; } updatedRealm.put("tenantId", SecurityUtil.getTenantId()); updatedRealm.put(ED_ORG, SecurityUtil.getEdOrg()); if (service.update(realmId, updatedRealm, false)) { logSecurityEvent(uriInfo, oldRealm, updatedRealm); return Response.status(Status.NO_CONTENT).build(); } return Response.status(Status.BAD_REQUEST).build(); } }
RealmResource { @PUT @Path("{realmId}") @Consumes("application/json") @RightsAllowed({ Right.CRUD_REALM }) public Response updateRealm(@PathParam("realmId") String realmId, EntityBody updatedRealm, @Context final UriInfo uriInfo) { if (updatedRealm == null) { throw new IllegalArgumentException("Updated Realm was null"); } EntityBody oldRealm = service.get(realmId); if (!canEditCurrentRealm(updatedRealm) || oldRealm.get(ED_ORG) != null && !oldRealm.get(ED_ORG).equals(SecurityUtil.getEdOrg())) { EntityBody body = new EntityBody(); body.put(RESPONSE, "You are not authorized to update this realm."); return Response.status(Status.FORBIDDEN).entity(body).build(); } Response validateUniqueness = validateUniqueId(realmId, (String) updatedRealm.get(UNIQUE_IDENTIFIER), (String) updatedRealm.get(NAME), getIdpId(updatedRealm)); if (validateUniqueness != null) { return validateUniqueness; } Map<String, Object> idp = (Map<String, Object>) updatedRealm.get(IDP); Response validateArtifactResolution = validateArtifactResolution((String) idp.get(ARTIFACT_RESOLUTION_ENDPOINT), (String) idp.get(SOURCE_ID)); if (validateArtifactResolution != null) { LOG.debug("Invalid artifact resolution information"); return validateArtifactResolution; } updatedRealm.put("tenantId", SecurityUtil.getTenantId()); updatedRealm.put(ED_ORG, SecurityUtil.getEdOrg()); if (service.update(realmId, updatedRealm, false)) { logSecurityEvent(uriInfo, oldRealm, updatedRealm); return Response.status(Status.NO_CONTENT).build(); } return Response.status(Status.BAD_REQUEST).build(); }  }
RealmResource { @PUT @Path("{realmId}") @Consumes("application/json") @RightsAllowed({ Right.CRUD_REALM }) public Response updateRealm(@PathParam("realmId") String realmId, EntityBody updatedRealm, @Context final UriInfo uriInfo) { if (updatedRealm == null) { throw new IllegalArgumentException("Updated Realm was null"); } EntityBody oldRealm = service.get(realmId); if (!canEditCurrentRealm(updatedRealm) || oldRealm.get(ED_ORG) != null && !oldRealm.get(ED_ORG).equals(SecurityUtil.getEdOrg())) { EntityBody body = new EntityBody(); body.put(RESPONSE, "You are not authorized to update this realm."); return Response.status(Status.FORBIDDEN).entity(body).build(); } Response validateUniqueness = validateUniqueId(realmId, (String) updatedRealm.get(UNIQUE_IDENTIFIER), (String) updatedRealm.get(NAME), getIdpId(updatedRealm)); if (validateUniqueness != null) { return validateUniqueness; } Map<String, Object> idp = (Map<String, Object>) updatedRealm.get(IDP); Response validateArtifactResolution = validateArtifactResolution((String) idp.get(ARTIFACT_RESOLUTION_ENDPOINT), (String) idp.get(SOURCE_ID)); if (validateArtifactResolution != null) { LOG.debug("Invalid artifact resolution information"); return validateArtifactResolution; } updatedRealm.put("tenantId", SecurityUtil.getTenantId()); updatedRealm.put(ED_ORG, SecurityUtil.getEdOrg()); if (service.update(realmId, updatedRealm, false)) { logSecurityEvent(uriInfo, oldRealm, updatedRealm); return Response.status(Status.NO_CONTENT).build(); } return Response.status(Status.BAD_REQUEST).build(); }  @PostConstruct void init(); void setService(EntityService service); @PUT @Path("{realmId}") @Consumes("application/json") @RightsAllowed({ Right.CRUD_REALM }) Response updateRealm(@PathParam("realmId") String realmId, EntityBody updatedRealm,
            @Context final UriInfo uriInfo); @DELETE @Path("{realmId}") @RightsAllowed({ Right.CRUD_REALM }) Response deleteRealm(@PathParam("realmId") String realmId, @Context final UriInfo uriInfo); @POST @RightsAllowed({ Right.CRUD_REALM }) Response createRealm(EntityBody newRealm, @Context final UriInfo uriInfo); @GET @Path("{realmId}") @RightsAllowed({ Right.ADMIN_ACCESS }) Response readRealm(@PathParam("realmId") String realmId); @GET @RightsAllowed({ Right.ADMIN_ACCESS }) Response getRealms(@QueryParam(REALM) @DefaultValue("") String realm, @Context UriInfo info); }
RealmResource { @PUT @Path("{realmId}") @Consumes("application/json") @RightsAllowed({ Right.CRUD_REALM }) public Response updateRealm(@PathParam("realmId") String realmId, EntityBody updatedRealm, @Context final UriInfo uriInfo) { if (updatedRealm == null) { throw new IllegalArgumentException("Updated Realm was null"); } EntityBody oldRealm = service.get(realmId); if (!canEditCurrentRealm(updatedRealm) || oldRealm.get(ED_ORG) != null && !oldRealm.get(ED_ORG).equals(SecurityUtil.getEdOrg())) { EntityBody body = new EntityBody(); body.put(RESPONSE, "You are not authorized to update this realm."); return Response.status(Status.FORBIDDEN).entity(body).build(); } Response validateUniqueness = validateUniqueId(realmId, (String) updatedRealm.get(UNIQUE_IDENTIFIER), (String) updatedRealm.get(NAME), getIdpId(updatedRealm)); if (validateUniqueness != null) { return validateUniqueness; } Map<String, Object> idp = (Map<String, Object>) updatedRealm.get(IDP); Response validateArtifactResolution = validateArtifactResolution((String) idp.get(ARTIFACT_RESOLUTION_ENDPOINT), (String) idp.get(SOURCE_ID)); if (validateArtifactResolution != null) { LOG.debug("Invalid artifact resolution information"); return validateArtifactResolution; } updatedRealm.put("tenantId", SecurityUtil.getTenantId()); updatedRealm.put(ED_ORG, SecurityUtil.getEdOrg()); if (service.update(realmId, updatedRealm, false)) { logSecurityEvent(uriInfo, oldRealm, updatedRealm); return Response.status(Status.NO_CONTENT).build(); } return Response.status(Status.BAD_REQUEST).build(); }  @PostConstruct void init(); void setService(EntityService service); @PUT @Path("{realmId}") @Consumes("application/json") @RightsAllowed({ Right.CRUD_REALM }) Response updateRealm(@PathParam("realmId") String realmId, EntityBody updatedRealm,
            @Context final UriInfo uriInfo); @DELETE @Path("{realmId}") @RightsAllowed({ Right.CRUD_REALM }) Response deleteRealm(@PathParam("realmId") String realmId, @Context final UriInfo uriInfo); @POST @RightsAllowed({ Right.CRUD_REALM }) Response createRealm(EntityBody newRealm, @Context final UriInfo uriInfo); @GET @Path("{realmId}") @RightsAllowed({ Right.ADMIN_ACCESS }) Response readRealm(@PathParam("realmId") String realmId); @GET @RightsAllowed({ Right.ADMIN_ACCESS }) Response getRealms(@QueryParam(REALM) @DefaultValue("") String realm, @Context UriInfo info); static final String REALM; static final String ED_ORG; static final String RESPONSE; static final String NAME; static final String UNIQUE_IDENTIFIER; static final String IDP_ID; static final String ARTIFACT_RESOLUTION_ENDPOINT; static final String SOURCE_ID; static final String IDP; }