@Test public void isAdmin() { StaticUser user1 = new StaticUser("user1", ImmutableList.of("group2"), null, null); StaticUser user2 = new StaticUser("user2", null, "password2", null); StaticUser user3 = new StaticUser("user3", ImmutableList.of("group2"), "password3", null); List<StaticUser> users = ImmutableList.of(user1, user2, user3); AuthenticationManagerStatic auth = new AuthenticationManagerStatic(users, ImmutableList.of("group2"), ImmutableList.of("user2"), ImmutableList.of("user3"), false); assertTrue(auth.isAdmin(user1)); assertTrue(auth.isAdmin(user2)); assertFalse(auth.isAdmin(user3)); }
@Override boolean isAdmin(User user) { if (user == null) { return false; } if (noAdminUsers.contains(user.name())) { return false; } if (adminUsers.contains(user.name())) { return true; } List<String> groups = user.groups(); for (String group : groups) { if (adminGroups.contains(group)) { return true; } } return false; }
AuthenticationManagerStatic extends AuthenticationManager { @Override boolean isAdmin(User user) { if (user == null) { return false; } if (noAdminUsers.contains(user.name())) { return false; } if (adminUsers.contains(user.name())) { return true; } List<String> groups = user.groups(); for (String group : groups) { if (adminGroups.contains(group)) { return true; } } return false; } }
AuthenticationManagerStatic extends AuthenticationManager { @Override boolean isAdmin(User user) { if (user == null) { return false; } if (noAdminUsers.contains(user.name())) { return false; } if (adminUsers.contains(user.name())) { return true; } List<String> groups = user.groups(); for (String group : groups) { if (adminGroups.contains(group)) { return true; } } return false; } @JsonCreator  AuthenticationManagerStatic(@Nonnull @JsonProperty("users") List<StaticUser> users,
                                       @Nonnull @JsonProperty("adminGroups") List<String> adminGroups,
                                       @Nonnull @JsonProperty("adminUsers") List<String> adminUsers,
                                       @Nonnull @JsonProperty("noAdminUsers") List<String> noAdminUsers,
                                       @JsonProperty(value = "requireSSL", required = true) boolean requireSSL); }
AuthenticationManagerStatic extends AuthenticationManager { @Override boolean isAdmin(User user) { if (user == null) { return false; } if (noAdminUsers.contains(user.name())) { return false; } if (adminUsers.contains(user.name())) { return true; } List<String> groups = user.groups(); for (String group : groups) { if (adminGroups.contains(group)) { return true; } } return false; } @JsonCreator  AuthenticationManagerStatic(@Nonnull @JsonProperty("users") List<StaticUser> users,
                                       @Nonnull @JsonProperty("adminGroups") List<String> adminGroups,
                                       @Nonnull @JsonProperty("adminUsers") List<String> adminUsers,
                                       @Nonnull @JsonProperty("noAdminUsers") List<String> noAdminUsers,
                                       @JsonProperty(value = "requireSSL", required = true) boolean requireSSL); @Override boolean verify(String username, String password, boolean ssl); @Override void evict(String username); }
AuthenticationManagerStatic extends AuthenticationManager { @Override boolean isAdmin(User user) { if (user == null) { return false; } if (noAdminUsers.contains(user.name())) { return false; } if (adminUsers.contains(user.name())) { return true; } List<String> groups = user.groups(); for (String group : groups) { if (adminGroups.contains(group)) { return true; } } return false; } @JsonCreator  AuthenticationManagerStatic(@Nonnull @JsonProperty("users") List<StaticUser> users,
                                       @Nonnull @JsonProperty("adminGroups") List<String> adminGroups,
                                       @Nonnull @JsonProperty("adminUsers") List<String> adminUsers,
                                       @Nonnull @JsonProperty("noAdminUsers") List<String> noAdminUsers,
                                       @JsonProperty(value = "requireSSL", required = true) boolean requireSSL); @Override boolean verify(String username, String password, boolean ssl); @Override void evict(String username);  }