public boolean shouldAssociate(String userName, String ignore) { return adminsConfig.hasUser(new CaseInsensitiveString(userName), userRoleMatcher); }
@Test public void shouldReturnTrueIfHasUser() { AdminsConfig adminsConfig = new AdminsConfig(new AdminUser(new CaseInsensitiveString("user1"))); assertThat("shouldReturnTrueIfHasUser", adminsConfig.hasUser(new CaseInsensitiveString("user1"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(true)); }
@Test public void shouldReturnFalseIfUserDoesNotExist() { AdminsConfig adminsConfig = new AdminsConfig(new AdminUser(new CaseInsensitiveString("user1"))); assertThat("shouldReturnFalseIfUserDoesNotExist", adminsConfig.hasUser(new CaseInsensitiveString("anyone"), UserRoleMatcherMother.ALWAYS_FALSE_MATCHER), is(false)); }
public CruiseConfig update(CruiseConfig cruiseConfig) { final AdminsConfig adminsConfig = cruiseConfig.server().security().adminsConfig(); switch (adminPrivilegeSelection.getAction()) { case add: if (!adminsConfig.hasUser(new CaseInsensitiveString(user), ALWAYS_FALSE_MATCHER)) { adminsConfig.add(new AdminUser(new CaseInsensitiveString(user))); } break; case remove: adminsConfig.remove(new AdminUser(new CaseInsensitiveString(user))); break; } return cruiseConfig; } }
@Test public void shouldReturnTrueIfUserMatchRole() { AdminsConfig adminsConfig = new AdminsConfig(new AdminUser(new CaseInsensitiveString("user1")), new AdminRole(new CaseInsensitiveString("role"))); assertThat("shouldReturnTrueIfUserMatchRole", adminsConfig.hasUser(new CaseInsensitiveString("roleuser"), UserRoleMatcherMother.ALWAYS_TRUE_MATCHER), is(true)); }