Search in sources :

Example 6 with FmsUser

use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.

the class UsersStateDifferenceCalculatorTest method testCalculateUsersToRemove.

@Test
void testCalculateUsersToRemove() {
    FmsUser userUms = new FmsUser().withName("userUms");
    FmsUser userBoth = new FmsUser().withName("userBoth");
    FmsUser userIPA = new FmsUser().withName("userIPA");
    FmsUser userIPA2 = new FmsUser().withName("userIPA2");
    FmsUser userProtected = new FmsUser().withName(FreeIpaChecks.IPA_PROTECTED_USERS.get(0));
    UmsUsersState umsUsersState = new UmsUsersState.Builder().setUsersState(new UsersState.Builder().addUser(userUms).addMemberToGroup(UserSyncConstants.CDP_USERSYNC_INTERNAL_GROUP, userUms.getName()).addUser(userBoth).addMemberToGroup(UserSyncConstants.CDP_USERSYNC_INTERNAL_GROUP, userBoth.getName()).build()).build();
    UsersState ipaUsersState = new UsersState.Builder().addUser(userBoth).addMemberToGroup(UserSyncConstants.CDP_USERSYNC_INTERNAL_GROUP, userBoth.getName()).addUser(userIPA).addMemberToGroup(UserSyncConstants.CDP_USERSYNC_INTERNAL_GROUP, userIPA.getName()).addUser(userIPA2).addUser(userProtected).addMemberToGroup(UserSyncConstants.CDP_USERSYNC_INTERNAL_GROUP, userProtected.getName()).build();
    ImmutableSet<String> usersToRemove = new UserStateDifferenceCalculator().calculateUsersToRemove(umsUsersState, ipaUsersState);
    // the users that exists only in IPA that are members of the CDP_USERSYNC_INTERNAL_GROUP will be removed
    assertTrue(usersToRemove.contains(userIPA.getName()));
    // protected users will be ignored
    assertFalse(usersToRemove.contains(userProtected.getName()));
    // users that exist only in ums, exist in both ums and ipa, or are not members of CDP_USERSYNC_INTERNAL_GROUP will not be removed
    assertFalse(usersToRemove.contains(userUms.getName()));
    assertFalse(usersToRemove.contains(userBoth.getName()));
    assertFalse(usersToRemove.contains(userIPA2.getName()));
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) Test(org.junit.jupiter.api.Test)

Example 7 with FmsUser

use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.

the class UsersStateDifferenceCalculatorTest method testCalculateUsersToAdd.

@Test
void testCalculateUsersToAdd() {
    FmsUser userUms = new FmsUser().withName("userUms");
    FmsUser userDisabledUms = new FmsUser().withName("userDisabledUms").withState(FmsUser.State.DISABLED);
    FmsUser userProtected = new FmsUser().withName(FreeIpaChecks.IPA_PROTECTED_USERS.get(0));
    FmsUser userBothUms = new FmsUser().withName("userBoth");
    FmsUser userBothIpa = new FmsUser().withName("userBoth");
    FmsUser userIpa = new FmsUser().withName("userIPA");
    FmsUser userSameStateUms = new FmsUser().withName("userSameState").withState(FmsUser.State.DISABLED);
    FmsUser userSameStateIpa = new FmsUser().withName("userSameState").withState(FmsUser.State.DISABLED);
    FmsUser userDifferentStateUms = new FmsUser().withName("userDifferentState").withState(FmsUser.State.ENABLED);
    FmsUser userDifferentStateIpa = new FmsUser().withName("userDifferentState").withState(FmsUser.State.DISABLED);
    UmsUsersState umsUsersState = new UmsUsersState.Builder().setUsersState(new UsersState.Builder().addUser(userUms).addUser(userDisabledUms).addUser(userProtected).addUser(userBothUms).addUser(userSameStateUms).addUser(userDifferentStateUms).build()).build();
    UsersState ipaUsersState = new UsersState.Builder().addUser(userBothIpa).addUser(userIpa).addUser(userSameStateIpa).addUser(userDifferentStateIpa).build();
    ImmutableSet<FmsUser> usersToAdd = new UserStateDifferenceCalculator().calculateUsersToAdd(umsUsersState, ipaUsersState);
    // the user that exists only in the UMS will be added
    assertTrue(usersToAdd.contains(userUms));
    assertTrue(usersToAdd.contains(userDisabledUms));
    // protected users will be ignored
    assertFalse(usersToAdd.contains(userProtected));
    // users that exist in both or only in ipa will not be added
    assertFalse(usersToAdd.contains(userBothUms));
    assertFalse(usersToAdd.contains(userIpa));
    assertFalse(usersToAdd.contains(userSameStateUms));
    assertFalse(usersToAdd.contains(userDifferentStateUms));
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) Test(org.junit.jupiter.api.Test)

Example 8 with FmsUser

use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.

the class FmsUserConverterTest method testUserToFmsUserMissingNames.

@Test
public void testUserToFmsUserMissingNames() {
    String workloadUsername = "foobar";
    UserManagementProto.User umsUser = UserManagementProto.User.newBuilder().setWorkloadUsername(workloadUsername).setState(UserManagementProto.ActorState.Value.ACTIVE).build();
    FmsUser fmsUser = underTest.toFmsUser(umsUser);
    assertEquals(workloadUsername, fmsUser.getName());
    assertEquals(underTest.NONE_STRING, fmsUser.getFirstName());
    assertEquals(underTest.NONE_STRING, fmsUser.getLastName());
    assertEquals(FmsUser.State.ENABLED, fmsUser.getState());
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) UserManagementProto(com.cloudera.thunderhead.service.usermanagement.UserManagementProto) Test(org.junit.jupiter.api.Test)

Example 9 with FmsUser

use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.

the class FmsUserConverterTest method testUserSyncActorDetailsToFmsUserUnrecognizedState.

@Test
public void testUserSyncActorDetailsToFmsUserUnrecognizedState() {
    String workloadUsername = "foobar";
    UserManagementProto.UserSyncActorDetails actorDetails = UserManagementProto.UserSyncActorDetails.newBuilder().setWorkloadUsername(workloadUsername).setStateValue(UNRECOGNIZED_STATE_VALUE).build();
    FmsUser fmsUser = underTest.toFmsUser(actorDetails);
    assertEquals(workloadUsername, fmsUser.getName());
    assertEquals(underTest.NONE_STRING, fmsUser.getFirstName());
    assertEquals(underTest.NONE_STRING, fmsUser.getLastName());
    assertEquals(FmsUser.State.ENABLED, fmsUser.getState());
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) UserManagementProto(com.cloudera.thunderhead.service.usermanagement.UserManagementProto) Test(org.junit.jupiter.api.Test)

Example 10 with FmsUser

use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.

the class FmsUserConverterTest method testUserToFmsUserMissingState.

@Test
public void testUserToFmsUserMissingState() {
    String workloadUsername = "foobar";
    UserManagementProto.User umsUser = UserManagementProto.User.newBuilder().setWorkloadUsername(workloadUsername).build();
    FmsUser fmsUser = underTest.toFmsUser(umsUser);
    assertEquals(workloadUsername, fmsUser.getName());
    assertEquals(underTest.NONE_STRING, fmsUser.getFirstName());
    assertEquals(underTest.NONE_STRING, fmsUser.getLastName());
    assertEquals(FmsUser.State.ENABLED, fmsUser.getState());
}
Also used : FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) UserManagementProto(com.cloudera.thunderhead.service.usermanagement.UserManagementProto) Test(org.junit.jupiter.api.Test)

Aggregations

FmsUser (com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser)42 Test (org.junit.jupiter.api.Test)33 UserManagementProto (com.cloudera.thunderhead.service.usermanagement.UserManagementProto)23 UsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UsersState)8 FmsGroup (com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup)6 UmsUsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState)5 List (java.util.List)5 Map (java.util.Map)5 UserMetadata (com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata)4 UsersStateDifference (com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference)3 Collection (java.util.Collection)3 Set (java.util.Set)3 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)2 IPA_PROTECTED_USERS (com.sequenceiq.freeipa.client.FreeIpaChecks.IPA_PROTECTED_USERS)2 IPA_UNMANAGED_GROUPS (com.sequenceiq.freeipa.client.FreeIpaChecks.IPA_UNMANAGED_GROUPS)2 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)2 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)2 FreeIpaErrorCodes (com.sequenceiq.freeipa.client.FreeIpaErrorCodes)2