@Test public void testBadData() { Collection<GrantedAuthority> rights = new HashSet<GrantedAuthority>(); rights.addAll(Arrays.asList(Right.CRUD_SLC_OPERATOR, Right.CRUD_SEA_ADMIN, Right.CRUD_LEA_ADMIN)); Mockito.when(secUtil.getAllRights()).thenReturn(rights); User newUser = new User(); newUser.setGroups(Arrays.asList(RoleInitializer.SEA_ADMINISTRATOR)); Response res = resource.create(newUser); Assert.assertEquals(400, res.getStatus()); newUser.setGroups(Arrays.asList(RoleInitializer.LEA_ADMINISTRATOR)); res = resource.create(newUser); Assert.assertEquals(400, res.getStatus()); newUser.setTenant(TENANT); newUser.setGroups(Arrays.asList(RoleInitializer.SEA_ADMINISTRATOR)); res = resource.create(newUser); Assert.assertEquals(400, res.getStatus()); newUser.setGroups(Arrays.asList(RoleInitializer.LEA_ADMINISTRATOR)); res = resource.create(newUser); Assert.assertEquals(400, res.getStatus()); }
@POST @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response create(final User newUser) { Response result = validateUserCreate(newUser, secUtil.getTenantId()); if (result != null) { return result; } newUser.setGroups((List<String>) (RoleToGroupMapper.getInstance().mapRoleToGroups(newUser.getGroups()))); newUser.setStatus(User.Status.SUBMITTED); try { ldapService.createUser(realm, newUser); } catch (NameAlreadyBoundException e) { return Response.status(Status.CONFLICT).build(); } auditLogger.audit(createSecurityEvent("Created user " + newUser.getUid() + " with roles " + rolesToString(newUser), newUser.getTenant(), newUser.getEdorg())); return Response.status(Status.CREATED).build(); }
UserResource { @POST @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response create(final User newUser) { Response result = validateUserCreate(newUser, secUtil.getTenantId()); if (result != null) { return result; } newUser.setGroups((List<String>) (RoleToGroupMapper.getInstance().mapRoleToGroups(newUser.getGroups()))); newUser.setStatus(User.Status.SUBMITTED); try { ldapService.createUser(realm, newUser); } catch (NameAlreadyBoundException e) { return Response.status(Status.CONFLICT).build(); } auditLogger.audit(createSecurityEvent("Created user " + newUser.getUid() + " with roles " + rolesToString(newUser), newUser.getTenant(), newUser.getEdorg())); return Response.status(Status.CREATED).build(); } }
UserResource { @POST @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response create(final User newUser) { Response result = validateUserCreate(newUser, secUtil.getTenantId()); if (result != null) { return result; } newUser.setGroups((List<String>) (RoleToGroupMapper.getInstance().mapRoleToGroups(newUser.getGroups()))); newUser.setStatus(User.Status.SUBMITTED); try { ldapService.createUser(realm, newUser); } catch (NameAlreadyBoundException e) { return Response.status(Status.CONFLICT).build(); } auditLogger.audit(createSecurityEvent("Created user " + newUser.getUid() + " with roles " + rolesToString(newUser), newUser.getTenant(), newUser.getEdorg())); return Response.status(Status.CREATED).build(); }  }
UserResource { @POST @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response create(final User newUser) { Response result = validateUserCreate(newUser, secUtil.getTenantId()); if (result != null) { return result; } newUser.setGroups((List<String>) (RoleToGroupMapper.getInstance().mapRoleToGroups(newUser.getGroups()))); newUser.setStatus(User.Status.SUBMITTED); try { ldapService.createUser(realm, newUser); } catch (NameAlreadyBoundException e) { return Response.status(Status.CONFLICT).build(); } auditLogger.audit(createSecurityEvent("Created user " + newUser.getUid() + " with roles " + rolesToString(newUser), newUser.getTenant(), newUser.getEdorg())); return Response.status(Status.CREATED).build(); }  @POST @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response create(final User newUser); @GET @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response readAll(); @PUT @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response update(final User updateUser); @DELETE @Path("{uid}") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response delete(@PathParam("uid") final String uid); @GET @Path("edorgs") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response getEdOrgs(); void setRealm(String realm); }
UserResource { @POST @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) public final Response create(final User newUser) { Response result = validateUserCreate(newUser, secUtil.getTenantId()); if (result != null) { return result; } newUser.setGroups((List<String>) (RoleToGroupMapper.getInstance().mapRoleToGroups(newUser.getGroups()))); newUser.setStatus(User.Status.SUBMITTED); try { ldapService.createUser(realm, newUser); } catch (NameAlreadyBoundException e) { return Response.status(Status.CONFLICT).build(); } auditLogger.audit(createSecurityEvent("Created user " + newUser.getUid() + " with roles " + rolesToString(newUser), newUser.getTenant(), newUser.getEdorg())); return Response.status(Status.CREATED).build(); }  @POST @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response create(final User newUser); @GET @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response readAll(); @PUT @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response update(final User updateUser); @DELETE @Path("{uid}") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response delete(@PathParam("uid") final String uid); @GET @Path("edorgs") @RightsAllowed({Right.CRUD_LEA_ADMIN, Right.CRUD_SEA_ADMIN, Right.CRUD_SLC_OPERATOR, Right.CRUD_SANDBOX_ADMIN, Right.CRUD_SANDBOX_SLC_OPERATOR }) final Response getEdOrgs(); void setRealm(String realm);  }