Search in sources :

Example 1 with Role

use of com.sequenceiq.freeipa.client.model.Role in project cloudbreak by hortonworks.

the class RoleAddMemberResponse method handleInternal.

@Override
protected Role handleInternal(List<CloudVmMetaDataStatus> metadatas, String body) {
    Role role = new Role();
    role.setCn("roleName");
    role.setMemberUser(List.of());
    role.setMemberGroup(List.of());
    role.setMemberHost(List.of());
    role.setMemberHostGroup(List.of());
    role.setMemberService(List.of());
    return role;
}
Also used : Role(com.sequenceiq.freeipa.client.model.Role)

Example 2 with Role

use of com.sequenceiq.freeipa.client.model.Role in project cloudbreak by hortonworks.

the class RoleFindResponse method handleInternal.

@Override
protected Set<Role> handleInternal(List<CloudVmMetaDataStatus> metadatas, String body) {
    Role role = new Role();
    role.setCn("roleName");
    role.setMemberUser(List.of());
    role.setMemberGroup(List.of());
    role.setMemberHost(List.of());
    role.setMemberHostGroup(List.of());
    role.setMemberService(List.of());
    return Set.of(role);
}
Also used : Role(com.sequenceiq.freeipa.client.model.Role)

Example 3 with Role

use of com.sequenceiq.freeipa.client.model.Role in project cloudbreak by hortonworks.

the class KerberosMgmtRoleComponentV1Test method testAddRoleAndPrivilegesForHostWithRoleRaceCondition.

@Test
public void testAddRoleAndPrivilegesForHostWithRoleRaceCondition() throws Exception {
    Host host = new Host();
    host.setFqdn(HOST);
    RoleRequest roleRequest = new RoleRequest();
    roleRequest.setRoleName(ROLE);
    Set<String> privileges = new HashSet<>();
    privileges.add(PRIVILEGE1);
    privileges.add(PRIVILEGE2);
    roleRequest.setPrivileges(privileges);
    Role role = new Role();
    role.setCn(ROLE);
    Mockito.when(mockIpaClient.addRole(anyString())).thenThrow(new FreeIpaClientException("duplicate", new JsonRpcClientException(FreeIpaErrorCodes.DUPLICATE_ENTRY.getValue(), "duplicate", null)));
    Privilege privilege = new Privilege();
    Set<String> hosts = new HashSet<>();
    hosts.add(HOST);
    Set<String> noServices = new HashSet<>();
    Mockito.when(mockIpaClient.showRole(roleRequest.getRoleName())).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(NOT_FOUND, "notfound", null))).thenReturn(role);
    Mockito.when(mockIpaClient.showPrivilege(any())).thenReturn(privilege);
    Mockito.when(mockIpaClient.addRolePrivileges(any(), any())).thenReturn(role);
    Mockito.when(mockIpaClient.addRoleMember(any(), any(), any(), any(), any(), any())).thenReturn(role);
    underTest.addRoleAndPrivileges(Optional.empty(), Optional.of(host), roleRequest, mockIpaClient);
    Mockito.verify(mockIpaClient).addRole(ROLE);
    Mockito.verify(mockIpaClient).addRolePrivileges(ROLE, privileges);
    Mockito.verify(mockIpaClient).addRoleMember(ROLE, null, null, hosts, null, noServices);
}
Also used : Role(com.sequenceiq.freeipa.client.model.Role) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Host(com.sequenceiq.freeipa.client.model.Host) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Privilege(com.sequenceiq.freeipa.client.model.Privilege) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with Role

use of com.sequenceiq.freeipa.client.model.Role in project cloudbreak by hortonworks.

the class KerberosMgmtRoleComponentV1Test method testAddRoleAndPrivilegesForHostWithRoleThatAlreadyExists.

@Test
public void testAddRoleAndPrivilegesForHostWithRoleThatAlreadyExists() throws Exception {
    Host host = new Host();
    host.setFqdn(HOST);
    RoleRequest roleRequest = new RoleRequest();
    roleRequest.setRoleName(ROLE);
    Set<String> privileges = new HashSet<>();
    privileges.add(PRIVILEGE1);
    privileges.add(PRIVILEGE2);
    roleRequest.setPrivileges(privileges);
    Role role = new Role();
    role.setCn(ROLE);
    Privilege privilege = new Privilege();
    Set<String> hosts = new HashSet<>();
    hosts.add(HOST);
    Set<String> noServices = new HashSet<>();
    Mockito.when(mockIpaClient.showPrivilege(any())).thenReturn(privilege);
    Mockito.when(mockIpaClient.addRolePrivileges(any(), any())).thenReturn(role);
    Mockito.when(mockIpaClient.showRole(anyString())).thenReturn(role);
    Mockito.when(mockIpaClient.addRoleMember(any(), any(), any(), any(), any(), any())).thenReturn(role);
    underTest.addRoleAndPrivileges(Optional.empty(), Optional.of(host), roleRequest, mockIpaClient);
    Mockito.verify(mockIpaClient).addRolePrivileges(ROLE, privileges);
    Mockito.verify(mockIpaClient).addRoleMember(ROLE, null, null, hosts, null, noServices);
}
Also used : Role(com.sequenceiq.freeipa.client.model.Role) Host(com.sequenceiq.freeipa.client.model.Host) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Privilege(com.sequenceiq.freeipa.client.model.Privilege) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 5 with Role

use of com.sequenceiq.freeipa.client.model.Role in project cloudbreak by hortonworks.

the class KerberosMgmtRoleComponentV1Test method testDeleteRoleIfNoLongerUsedWhenRoleIsStillUsedAsMemberService.

@Test
public void testDeleteRoleIfNoLongerUsedWhenRoleIsStillUsedAsMemberService() throws Exception {
    Role role = new Role();
    role.setCn(ROLE);
    List<String> services = new ArrayList<>();
    services.add(SERVICE);
    role.setMemberService(services);
    Mockito.when(mockIpaClient.showRole(anyString())).thenReturn(role);
    underTest.deleteRoleIfItIsNoLongerUsed(ROLE, mockIpaClient);
    Mockito.verify(mockIpaClient, Mockito.never()).deleteRole(ROLE);
}
Also used : Role(com.sequenceiq.freeipa.client.model.Role) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

Role (com.sequenceiq.freeipa.client.model.Role)13 Test (org.junit.jupiter.api.Test)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)6 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)5 Host (com.sequenceiq.freeipa.client.model.Host)5 Privilege (com.sequenceiq.freeipa.client.model.Privilege)5 HashSet (java.util.HashSet)5 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)4 ArrayList (java.util.ArrayList)4 Service (com.sequenceiq.freeipa.client.model.Service)2 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)1 FreeIpaClientExceptionUtil (com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil)1 FreeIpaClientExceptionWrapper (com.sequenceiq.freeipa.client.FreeIpaClientExceptionWrapper)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Logger (org.slf4j.Logger)1