@Test void testGetAllAvailableSids() { User user = mock(User.class); when(user.getUsername()).thenReturn("username"); doReturn(true) .when(userPermissionEvaluator) .hasPermission(new EntityTypeIdentity(UserMetadata.USER), READ_DATA); doReturn(true) .when(userPermissionEvaluator) .hasPermission(new EntityTypeIdentity(RoleMetadata.ROLE), READ_DATA); when(userService.getUsers()).thenReturn(Collections.singletonList(user)); Role role = mock(Role.class); when(role.getString(RoleMetadata.NAME)).thenReturn("role1"); List<Entity> roles = Collections.singletonList(role); when(dataService.findAll(RoleMetadata.ROLE)).thenReturn(roles.stream()); assertEquals( newHashSet( new GrantedAuthoritySid("ROLE_role1"), new GrantedAuthoritySid("ROLE_ANONYMOUS"), new PrincipalSid("username")), userRoleTools.getAllAvailableSids()); }
Set<Sid> getAllAvailableSids() { Set<Sid> sids = new HashSet<>(); if (userPermissionEvaluator.hasPermission( new EntityTypeIdentity(UserMetadata.USER), READ_DATA)) { sids = userService.getUsers().stream() .map(user -> new PrincipalSid(user.getUsername())) .collect(toSet()); } if (userPermissionEvaluator.hasPermission( new EntityTypeIdentity(RoleMetadata.ROLE), READ_DATA)) { Set<Sid> roles = dataService .findAll(RoleMetadata.ROLE) .map(role -> new GrantedAuthoritySid(ROLE_PREFIX + role.getString(RoleMetadata.NAME))) .collect(toSet()); sids.addAll(roles); } sids.add(SidUtils.createSecurityContextSid()); return sids; }
UserRoleTools { Set<Sid> getAllAvailableSids() { Set<Sid> sids = new HashSet<>(); if (userPermissionEvaluator.hasPermission( new EntityTypeIdentity(UserMetadata.USER), READ_DATA)) { sids = userService.getUsers().stream() .map(user -> new PrincipalSid(user.getUsername())) .collect(toSet()); } if (userPermissionEvaluator.hasPermission( new EntityTypeIdentity(RoleMetadata.ROLE), READ_DATA)) { Set<Sid> roles = dataService .findAll(RoleMetadata.ROLE) .map(role -> new GrantedAuthoritySid(ROLE_PREFIX + role.getString(RoleMetadata.NAME))) .collect(toSet()); sids.addAll(roles); } sids.add(SidUtils.createSecurityContextSid()); return sids; } }
UserRoleTools { Set<Sid> getAllAvailableSids() { Set<Sid> sids = new HashSet<>(); if (userPermissionEvaluator.hasPermission( new EntityTypeIdentity(UserMetadata.USER), READ_DATA)) { sids = userService.getUsers().stream() .map(user -> new PrincipalSid(user.getUsername())) .collect(toSet()); } if (userPermissionEvaluator.hasPermission( new EntityTypeIdentity(RoleMetadata.ROLE), READ_DATA)) { Set<Sid> roles = dataService .findAll(RoleMetadata.ROLE) .map(role -> new GrantedAuthoritySid(ROLE_PREFIX + role.getString(RoleMetadata.NAME))) .collect(toSet()); sids.addAll(roles); } sids.add(SidUtils.createSecurityContextSid()); return sids; } UserRoleTools(
      UserService userService,
      DataService dataService,
      UserPermissionEvaluator userPermissionEvaluator); }
UserRoleTools { Set<Sid> getAllAvailableSids() { Set<Sid> sids = new HashSet<>(); if (userPermissionEvaluator.hasPermission( new EntityTypeIdentity(UserMetadata.USER), READ_DATA)) { sids = userService.getUsers().stream() .map(user -> new PrincipalSid(user.getUsername())) .collect(toSet()); } if (userPermissionEvaluator.hasPermission( new EntityTypeIdentity(RoleMetadata.ROLE), READ_DATA)) { Set<Sid> roles = dataService .findAll(RoleMetadata.ROLE) .map(role -> new GrantedAuthoritySid(ROLE_PREFIX + role.getString(RoleMetadata.NAME))) .collect(toSet()); sids.addAll(roles); } sids.add(SidUtils.createSecurityContextSid()); return sids; } 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 { Set<Sid> getAllAvailableSids() { Set<Sid> sids = new HashSet<>(); if (userPermissionEvaluator.hasPermission( new EntityTypeIdentity(UserMetadata.USER), READ_DATA)) { sids = userService.getUsers().stream() .map(user -> new PrincipalSid(user.getUsername())) .collect(toSet()); } if (userPermissionEvaluator.hasPermission( new EntityTypeIdentity(RoleMetadata.ROLE), READ_DATA)) { Set<Sid> roles = dataService .findAll(RoleMetadata.ROLE) .map(role -> new GrantedAuthoritySid(ROLE_PREFIX + role.getString(RoleMetadata.NAME))) .collect(toSet()); sids.addAll(roles); } sids.add(SidUtils.createSecurityContextSid()); return sids; } 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; }