@Test void testGetSids() { List<Sid> expected = Arrays.asList( new PrincipalSid("user1"), new PrincipalSid("user2"), new GrantedAuthoritySid("ROLE_role1"), new GrantedAuthoritySid("ROLE_role2")); Query query = mock(Query.class); doReturn(query).when(query).eq(RoleMetadata.NAME, "role1"); doReturn(query).when(query).eq(RoleMetadata.NAME, "role2"); doReturn(mock(Role.class)).when(query).findOne(); doReturn(mock(User.class)).when(userService).getUser("user1"); doReturn(mock(User.class)).when(userService).getUser("user2"); when(dataService.query(RoleMetadata.ROLE, Role.class)).thenReturn(query); when(query.findOne()).thenReturn(mock(Role.class)); assertTrue( userRoleTools .getSids(Arrays.asList("user1", "user2"), Arrays.asList("role1", "role2")) .containsAll(expected)); }
public List<Sid> getSids(List<String> users, List<String> roles) { List<Sid> results = new ArrayList<>(); for (String user : users) { checkUserExists(user); results.add(createUserSid(user)); } for (String role : roles) { checkRoleExists(role); results.add(createRoleSid(role)); } return results; }
UserRoleTools { public List<Sid> getSids(List<String> users, List<String> roles) { List<Sid> results = new ArrayList<>(); for (String user : users) { checkUserExists(user); results.add(createUserSid(user)); } for (String role : roles) { checkRoleExists(role); results.add(createRoleSid(role)); } return results; } }
UserRoleTools { public List<Sid> getSids(List<String> users, List<String> roles) { List<Sid> results = new ArrayList<>(); for (String user : users) { checkUserExists(user); results.add(createUserSid(user)); } for (String role : roles) { checkRoleExists(role); results.add(createRoleSid(role)); } return results; } UserRoleTools(
      UserService userService,
      DataService dataService,
      UserPermissionEvaluator userPermissionEvaluator); }
UserRoleTools { public List<Sid> getSids(List<String> users, List<String> roles) { List<Sid> results = new ArrayList<>(); for (String user : users) { checkUserExists(user); results.add(createUserSid(user)); } for (String role : roles) { checkRoleExists(role); results.add(createRoleSid(role)); } return results; } UserRoleTools(
      UserService userService,
      DataService dataService,
      UserPermissionEvaluator userPermissionEvaluator); void checkRoleExists(String role); void checkUserExists(String user); List<Sid> getSids(List<String> users, List<String> roles); static Optional<String> getUsername(Sid sid); static Optional<String> getRolename(Sid sid); static String getName(Sid sid); List<Sid> getRolesForSid(Sid sid); }
UserRoleTools { public List<Sid> getSids(List<String> users, List<String> roles) { List<Sid> results = new ArrayList<>(); for (String user : users) { checkUserExists(user); results.add(createUserSid(user)); } for (String role : roles) { checkRoleExists(role); results.add(createRoleSid(role)); } return results; } UserRoleTools(
      UserService userService,
      DataService dataService,
      UserPermissionEvaluator userPermissionEvaluator); void checkRoleExists(String role); void checkUserExists(String user); List<Sid> getSids(List<String> users, List<String> roles); static Optional<String> getUsername(Sid sid); static Optional<String> getRolename(Sid sid); static String getName(Sid sid); List<Sid> getRolesForSid(Sid sid); static final String ANONYMOUS; }