@Test public void test_getAllAdmins() { Entry<Object, Object> entry = new SimpleEntry<>(USERNAME, USERDATA); Set<Entry<Object, Object>> set = new HashSet<>(); set.add(entry); Mockito.when(users.entrySet()).thenReturn(set); List<UserDetails> admins = adminDetailsServiceToTest.getAllAdmins(); Assert.assertTrue(admins.size() == 1); Assert.assertEquals(USERNAME, admins.get(0).getUsername()); Assert.assertEquals("", admins.get(0).getPassword()); Assert.assertEquals( GilesGrantedAuthority.ROLE_ADMIN, ((GilesGrantedAuthority)admins.get(0).getAuthorities().toArray()[0]).getAuthority()); }
@Override public List<UserDetails> getAllAdmins() { List<UserDetails> userList = new ArrayList<>(); Set<Entry<Object, Object>> entries = users.entrySet(); for (Entry<Object, Object> entry : entries) { String userData = users.getProperty(entry.getKey().toString()); String[] data = userData.split(","); if (data.length >= 3) { List<GrantedAuthority> roles = new ArrayList<GrantedAuthority>(); roles.add(new GilesGrantedAuthority(data[1])); UserDetails details = new User(entry.getKey().toString(), "", roles); userList.add(details); } } return userList; }
AdminUserDetailsService implements IAdminUserDetailsService { @Override public List<UserDetails> getAllAdmins() { List<UserDetails> userList = new ArrayList<>(); Set<Entry<Object, Object>> entries = users.entrySet(); for (Entry<Object, Object> entry : entries) { String userData = users.getProperty(entry.getKey().toString()); String[] data = userData.split(","); if (data.length >= 3) { List<GrantedAuthority> roles = new ArrayList<GrantedAuthority>(); roles.add(new GilesGrantedAuthority(data[1])); UserDetails details = new User(entry.getKey().toString(), "", roles); userList.add(details); } } return userList; } }
AdminUserDetailsService implements IAdminUserDetailsService { @Override public List<UserDetails> getAllAdmins() { List<UserDetails> userList = new ArrayList<>(); Set<Entry<Object, Object>> entries = users.entrySet(); for (Entry<Object, Object> entry : entries) { String userData = users.getProperty(entry.getKey().toString()); String[] data = userData.split(","); if (data.length >= 3) { List<GrantedAuthority> roles = new ArrayList<GrantedAuthority>(); roles.add(new GilesGrantedAuthority(data[1])); UserDetails details = new User(entry.getKey().toString(), "", roles); userList.add(details); } } return userList; }  }
AdminUserDetailsService implements IAdminUserDetailsService { @Override public List<UserDetails> getAllAdmins() { List<UserDetails> userList = new ArrayList<>(); Set<Entry<Object, Object>> entries = users.entrySet(); for (Entry<Object, Object> entry : entries) { String userData = users.getProperty(entry.getKey().toString()); String[] data = userData.split(","); if (data.length >= 3) { List<GrantedAuthority> roles = new ArrayList<GrantedAuthority>(); roles.add(new GilesGrantedAuthority(data[1])); UserDetails details = new User(entry.getKey().toString(), "", roles); userList.add(details); } } return userList; }  @PostConstruct void init(); @Override UserDetails loadUserByUsername(String arg0); @Override List<UserDetails> getAllAdmins(); @Override boolean changePassword(String username, String password); @Override boolean isPasswordValid(String username, String password); }
AdminUserDetailsService implements IAdminUserDetailsService { @Override public List<UserDetails> getAllAdmins() { List<UserDetails> userList = new ArrayList<>(); Set<Entry<Object, Object>> entries = users.entrySet(); for (Entry<Object, Object> entry : entries) { String userData = users.getProperty(entry.getKey().toString()); String[] data = userData.split(","); if (data.length >= 3) { List<GrantedAuthority> roles = new ArrayList<GrantedAuthority>(); roles.add(new GilesGrantedAuthority(data[1])); UserDetails details = new User(entry.getKey().toString(), "", roles); userList.add(details); } } return userList; }  @PostConstruct void init(); @Override UserDetails loadUserByUsername(String arg0); @Override List<UserDetails> getAllAdmins(); @Override boolean changePassword(String username, String password); @Override boolean isPasswordValid(String username, String password);  }