@Test public void testUpdateRole_nameConflict() { RoleXORequest roleXo = createApiRole("id", "name", "description", Collections.singleton("role1"), Collections.singleton("priv1")); try { underTest.update("bad", roleXo); fail("exception should have been thrown for mismatched ids"); } catch (WebApplicationMessageException e) { assertThat(e.getResponse().getStatus(), is(409)); assertThat(e.getResponse().getMediaType(), is(MediaType.APPLICATION_JSON_TYPE)); assertThat(e.getResponse().getEntity().toString(), is("\"The Role id 'id' does not match the id used in the path 'bad'.\"")); } }
@Override @PUT @Path("/{id}") @RequiresAuthentication @RequiresPermissions("nexus:roles:update") public void update(@PathParam("id") @NotEmpty final String id, @NotNull @Valid final RoleXORequest roleXO) { try { if (!roleXO.getId().equals(id)) { throw buildRoleConflictException(roleXO.getId(), id); } AuthorizationManager authorizationManager = getDefaultAuthorizationManager(); int latestVersion = authorizationManager.getRole(id).getVersion(); Role role = fromXO(roleXO); role.setRoleId(id); role.setVersion(latestVersion); authorizationManager.updateRole(role); } catch (ReadonlyRoleException e) { throw buildReadonlyRoleException(id); } catch (NoSuchRoleException e) { if (e.getRoleId().equals(id)) { throw buildRoleNotFoundException(e.getRoleId()); } throw buildContainedRoleNotFoundException(e.getRoleId(), id); } catch (NoSuchPrivilegeException e) { throw buildContainedPrivilegeNotFoundException(e.getPrivilegeId(), id); } catch (RoleContainsItselfException e) { throw buildRoleContainsItselfException(e.getRoleId()); } }
RoleApiResource extends ComponentSupport implements Resource, RoleApiResourceDoc { @Override @PUT @Path("/{id}") @RequiresAuthentication @RequiresPermissions("nexus:roles:update") public void update(@PathParam("id") @NotEmpty final String id, @NotNull @Valid final RoleXORequest roleXO) { try { if (!roleXO.getId().equals(id)) { throw buildRoleConflictException(roleXO.getId(), id); } AuthorizationManager authorizationManager = getDefaultAuthorizationManager(); int latestVersion = authorizationManager.getRole(id).getVersion(); Role role = fromXO(roleXO); role.setRoleId(id); role.setVersion(latestVersion); authorizationManager.updateRole(role); } catch (ReadonlyRoleException e) { throw buildReadonlyRoleException(id); } catch (NoSuchRoleException e) { if (e.getRoleId().equals(id)) { throw buildRoleNotFoundException(e.getRoleId()); } throw buildContainedRoleNotFoundException(e.getRoleId(), id); } catch (NoSuchPrivilegeException e) { throw buildContainedPrivilegeNotFoundException(e.getPrivilegeId(), id); } catch (RoleContainsItselfException e) { throw buildRoleContainsItselfException(e.getRoleId()); } } }
RoleApiResource extends ComponentSupport implements Resource, RoleApiResourceDoc { @Override @PUT @Path("/{id}") @RequiresAuthentication @RequiresPermissions("nexus:roles:update") public void update(@PathParam("id") @NotEmpty final String id, @NotNull @Valid final RoleXORequest roleXO) { try { if (!roleXO.getId().equals(id)) { throw buildRoleConflictException(roleXO.getId(), id); } AuthorizationManager authorizationManager = getDefaultAuthorizationManager(); int latestVersion = authorizationManager.getRole(id).getVersion(); Role role = fromXO(roleXO); role.setRoleId(id); role.setVersion(latestVersion); authorizationManager.updateRole(role); } catch (ReadonlyRoleException e) { throw buildReadonlyRoleException(id); } catch (NoSuchRoleException e) { if (e.getRoleId().equals(id)) { throw buildRoleNotFoundException(e.getRoleId()); } throw buildContainedRoleNotFoundException(e.getRoleId(), id); } catch (NoSuchPrivilegeException e) { throw buildContainedPrivilegeNotFoundException(e.getPrivilegeId(), id); } catch (RoleContainsItselfException e) { throw buildRoleContainsItselfException(e.getRoleId()); } } @Inject  RoleApiResource(final SecuritySystem securitySystem); }
RoleApiResource extends ComponentSupport implements Resource, RoleApiResourceDoc { @Override @PUT @Path("/{id}") @RequiresAuthentication @RequiresPermissions("nexus:roles:update") public void update(@PathParam("id") @NotEmpty final String id, @NotNull @Valid final RoleXORequest roleXO) { try { if (!roleXO.getId().equals(id)) { throw buildRoleConflictException(roleXO.getId(), id); } AuthorizationManager authorizationManager = getDefaultAuthorizationManager(); int latestVersion = authorizationManager.getRole(id).getVersion(); Role role = fromXO(roleXO); role.setRoleId(id); role.setVersion(latestVersion); authorizationManager.updateRole(role); } catch (ReadonlyRoleException e) { throw buildReadonlyRoleException(id); } catch (NoSuchRoleException e) { if (e.getRoleId().equals(id)) { throw buildRoleNotFoundException(e.getRoleId()); } throw buildContainedRoleNotFoundException(e.getRoleId(), id); } catch (NoSuchPrivilegeException e) { throw buildContainedPrivilegeNotFoundException(e.getPrivilegeId(), id); } catch (RoleContainsItselfException e) { throw buildRoleContainsItselfException(e.getRoleId()); } } @Inject  RoleApiResource(final SecuritySystem securitySystem); @Override @GET @RequiresAuthentication @RequiresPermissions("nexus:roles:read") List<RoleXOResponse> getRoles(@QueryParam("source") final String source); @Override @POST @RequiresAuthentication @RequiresPermissions("nexus:roles:create") RoleXOResponse create(@NotNull @Valid final RoleXORequest roleXO); @Override @GET @Path("/{id}") @RequiresAuthentication @RequiresPermissions("nexus:roles:read") RoleXOResponse getRole(@DefaultValue(DEFAULT_SOURCE) @QueryParam("source") final String source,
                               @PathParam("id") @NotEmpty final String id); @Override @PUT @Path("/{id}") @RequiresAuthentication @RequiresPermissions("nexus:roles:update") void update(@PathParam("id") @NotEmpty final String id, @NotNull @Valid final RoleXORequest roleXO); @Override @DELETE @Path("/{id}") @RequiresAuthentication @RequiresPermissions("nexus:roles:delete") void delete(@PathParam("id") @NotEmpty final String id); }
RoleApiResource extends ComponentSupport implements Resource, RoleApiResourceDoc { @Override @PUT @Path("/{id}") @RequiresAuthentication @RequiresPermissions("nexus:roles:update") public void update(@PathParam("id") @NotEmpty final String id, @NotNull @Valid final RoleXORequest roleXO) { try { if (!roleXO.getId().equals(id)) { throw buildRoleConflictException(roleXO.getId(), id); } AuthorizationManager authorizationManager = getDefaultAuthorizationManager(); int latestVersion = authorizationManager.getRole(id).getVersion(); Role role = fromXO(roleXO); role.setRoleId(id); role.setVersion(latestVersion); authorizationManager.updateRole(role); } catch (ReadonlyRoleException e) { throw buildReadonlyRoleException(id); } catch (NoSuchRoleException e) { if (e.getRoleId().equals(id)) { throw buildRoleNotFoundException(e.getRoleId()); } throw buildContainedRoleNotFoundException(e.getRoleId(), id); } catch (NoSuchPrivilegeException e) { throw buildContainedPrivilegeNotFoundException(e.getPrivilegeId(), id); } catch (RoleContainsItselfException e) { throw buildRoleContainsItselfException(e.getRoleId()); } } @Inject  RoleApiResource(final SecuritySystem securitySystem); @Override @GET @RequiresAuthentication @RequiresPermissions("nexus:roles:read") List<RoleXOResponse> getRoles(@QueryParam("source") final String source); @Override @POST @RequiresAuthentication @RequiresPermissions("nexus:roles:create") RoleXOResponse create(@NotNull @Valid final RoleXORequest roleXO); @Override @GET @Path("/{id}") @RequiresAuthentication @RequiresPermissions("nexus:roles:read") RoleXOResponse getRole(@DefaultValue(DEFAULT_SOURCE) @QueryParam("source") final String source,
                               @PathParam("id") @NotEmpty final String id); @Override @PUT @Path("/{id}") @RequiresAuthentication @RequiresPermissions("nexus:roles:update") void update(@PathParam("id") @NotEmpty final String id, @NotNull @Valid final RoleXORequest roleXO); @Override @DELETE @Path("/{id}") @RequiresAuthentication @RequiresPermissions("nexus:roles:delete") void delete(@PathParam("id") @NotEmpty final String id); static final String SOURCE_NOT_FOUND; static final String ROLE_NOT_FOUND; static final String ROLE_INTERNAL; static final String ROLE_UNIQUE; static final String ROLE_CONFLICT; static final String CONTAINED_ROLE_NOT_FOUND; static final String CONTAINED_PRIV_NOT_FOUND; static final String ROLE_CONTAINS_ITSELF; }