@Test public void testGetRoles_allSources() throws Exception { Role role1 = createRole("default", "id1", "role1", "role1", Arrays.asList("role1", "role2"), Arrays.asList("priv1", "priv2")); Role role2 = createRole("another", "id2", "role2", "role2", Arrays.asList("role2", "role3"), Arrays.asList("priv2", "priv3")); when(securitySystem.listRoles()).thenReturn(new LinkedHashSet<>(Arrays.asList(role2, role1))); List<RoleXOResponse> apiRoles = underTest.getRoles(null); assertThat(apiRoles.size(), is(2)); assertApiRole(apiRoles.get(0), "default", "id1", "role1", "role1", Arrays.asList("role1", "role2"), Arrays.asList("priv1", "priv2")); assertApiRole(apiRoles.get(1), "another", "id2", "role2", "role2", Arrays.asList("role2", "role3"), Arrays.asList("priv2", "priv3")); }
@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; }