@Test public void testCreateRole_alreadyExists() throws Exception { when(authorizationManager.addRole(any())).thenThrow(DuplicateRoleException.class); RoleXORequest roleXo = createApiRole("roleId", "roleName", "description", Collections.emptySet(), Collections.emptySet()); try { underTest.create(roleXo); fail("create should have failed as role exists."); } catch (WebApplicationMessageException e) { assertThat(e.getResponse().getStatus(), is(400)); assertThat(e.getResponse().getMediaType(), is(MediaType.APPLICATION_JSON_TYPE)); assertThat(e.getResponse().getEntity().toString(), is("\"Role 'roleId' already exists, use a unique roleId.\"")); } }
@Override @POST @RequiresAuthentication @RequiresPermissions("nexus:roles:create") public RoleXOResponse create(@NotNull @Valid final RoleXORequest roleXO) { try { Role role = getDefaultAuthorizationManager().addRole(fromXO(roleXO)); return RoleXOResponse.fromRole(role); } catch (DuplicateRoleException e) { throw buildDuplicateRoleException(roleXO.getId()); } catch (NoSuchRoleException e) { throw buildContainedRoleNotFoundException(e.getRoleId(), roleXO.getId()); } catch (NoSuchPrivilegeException e) { throw buildContainedPrivilegeNotFoundException(e.getPrivilegeId(), roleXO.getId()); } }
RoleApiResource extends ComponentSupport implements Resource, RoleApiResourceDoc { @Override @POST @RequiresAuthentication @RequiresPermissions("nexus:roles:create") public RoleXOResponse create(@NotNull @Valid final RoleXORequest roleXO) { try { Role role = getDefaultAuthorizationManager().addRole(fromXO(roleXO)); return RoleXOResponse.fromRole(role); } catch (DuplicateRoleException e) { throw buildDuplicateRoleException(roleXO.getId()); } catch (NoSuchRoleException e) { throw buildContainedRoleNotFoundException(e.getRoleId(), roleXO.getId()); } catch (NoSuchPrivilegeException e) { throw buildContainedPrivilegeNotFoundException(e.getPrivilegeId(), roleXO.getId()); } } }
RoleApiResource extends ComponentSupport implements Resource, RoleApiResourceDoc { @Override @POST @RequiresAuthentication @RequiresPermissions("nexus:roles:create") public RoleXOResponse create(@NotNull @Valid final RoleXORequest roleXO) { try { Role role = getDefaultAuthorizationManager().addRole(fromXO(roleXO)); return RoleXOResponse.fromRole(role); } catch (DuplicateRoleException e) { throw buildDuplicateRoleException(roleXO.getId()); } catch (NoSuchRoleException e) { throw buildContainedRoleNotFoundException(e.getRoleId(), roleXO.getId()); } catch (NoSuchPrivilegeException e) { throw buildContainedPrivilegeNotFoundException(e.getPrivilegeId(), roleXO.getId()); } } @Inject  RoleApiResource(final SecuritySystem securitySystem); }
RoleApiResource extends ComponentSupport implements Resource, RoleApiResourceDoc { @Override @POST @RequiresAuthentication @RequiresPermissions("nexus:roles:create") public RoleXOResponse create(@NotNull @Valid final RoleXORequest roleXO) { try { Role role = getDefaultAuthorizationManager().addRole(fromXO(roleXO)); return RoleXOResponse.fromRole(role); } catch (DuplicateRoleException e) { throw buildDuplicateRoleException(roleXO.getId()); } catch (NoSuchRoleException e) { throw buildContainedRoleNotFoundException(e.getRoleId(), roleXO.getId()); } catch (NoSuchPrivilegeException e) { throw buildContainedPrivilegeNotFoundException(e.getPrivilegeId(), roleXO.getId()); } } @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 @POST @RequiresAuthentication @RequiresPermissions("nexus:roles:create") public RoleXOResponse create(@NotNull @Valid final RoleXORequest roleXO) { try { Role role = getDefaultAuthorizationManager().addRole(fromXO(roleXO)); return RoleXOResponse.fromRole(role); } catch (DuplicateRoleException e) { throw buildDuplicateRoleException(roleXO.getId()); } catch (NoSuchRoleException e) { throw buildContainedRoleNotFoundException(e.getRoleId(), roleXO.getId()); } catch (NoSuchPrivilegeException e) { throw buildContainedPrivilegeNotFoundException(e.getPrivilegeId(), roleXO.getId()); } } @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; }