@Test public void testGetRoles_noRoles() throws Exception { when(securitySystem.listRoles("default")).thenReturn(new HashSet<>()); List<RoleXOResponse> apiRoles = underTest.getRoles("default"); assertThat(apiRoles.size(), is(0)); }
@Override @GET @RequiresAuthentication @RequiresPermissions("nexus:roles:read") public List<RoleXOResponse> getRoles(@QueryParam("source") final String source) { if (StringUtils.isEmpty(source)) { return securitySystem.listRoles().stream().map(RoleXOResponse::fromRole) .sorted(Comparator.comparing(RoleXOResponse::getId)).collect(toList()); } else { try { return securitySystem.listRoles(source).stream().map(RoleXOResponse::fromRole) .sorted(Comparator.comparing(RoleXOResponse::getId)).collect(toList()); } catch (NoSuchAuthorizationManagerException e) { throw buildBadSourceException(source); } } }
RoleApiResource extends ComponentSupport implements Resource, RoleApiResourceDoc { @Override @GET @RequiresAuthentication @RequiresPermissions("nexus:roles:read") public List<RoleXOResponse> getRoles(@QueryParam("source") final String source) { if (StringUtils.isEmpty(source)) { return securitySystem.listRoles().stream().map(RoleXOResponse::fromRole) .sorted(Comparator.comparing(RoleXOResponse::getId)).collect(toList()); } else { try { return securitySystem.listRoles(source).stream().map(RoleXOResponse::fromRole) .sorted(Comparator.comparing(RoleXOResponse::getId)).collect(toList()); } catch (NoSuchAuthorizationManagerException e) { throw buildBadSourceException(source); } } } }
RoleApiResource extends ComponentSupport implements Resource, RoleApiResourceDoc { @Override @GET @RequiresAuthentication @RequiresPermissions("nexus:roles:read") public List<RoleXOResponse> getRoles(@QueryParam("source") final String source) { if (StringUtils.isEmpty(source)) { return securitySystem.listRoles().stream().map(RoleXOResponse::fromRole) .sorted(Comparator.comparing(RoleXOResponse::getId)).collect(toList()); } else { try { return securitySystem.listRoles(source).stream().map(RoleXOResponse::fromRole) .sorted(Comparator.comparing(RoleXOResponse::getId)).collect(toList()); } catch (NoSuchAuthorizationManagerException e) { throw buildBadSourceException(source); } } } @Inject  RoleApiResource(final SecuritySystem securitySystem); }
RoleApiResource extends ComponentSupport implements Resource, RoleApiResourceDoc { @Override @GET @RequiresAuthentication @RequiresPermissions("nexus:roles:read") public List<RoleXOResponse> getRoles(@QueryParam("source") final String source) { if (StringUtils.isEmpty(source)) { return securitySystem.listRoles().stream().map(RoleXOResponse::fromRole) .sorted(Comparator.comparing(RoleXOResponse::getId)).collect(toList()); } else { try { return securitySystem.listRoles(source).stream().map(RoleXOResponse::fromRole) .sorted(Comparator.comparing(RoleXOResponse::getId)).collect(toList()); } catch (NoSuchAuthorizationManagerException e) { throw buildBadSourceException(source); } } } @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 @GET @RequiresAuthentication @RequiresPermissions("nexus:roles:read") public List<RoleXOResponse> getRoles(@QueryParam("source") final String source) { if (StringUtils.isEmpty(source)) { return securitySystem.listRoles().stream().map(RoleXOResponse::fromRole) .sorted(Comparator.comparing(RoleXOResponse::getId)).collect(toList()); } else { try { return securitySystem.listRoles(source).stream().map(RoleXOResponse::fromRole) .sorted(Comparator.comparing(RoleXOResponse::getId)).collect(toList()); } catch (NoSuchAuthorizationManagerException e) { throw buildBadSourceException(source); } } } @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; }