Search in sources :

Example 1 with RoleRequest

use of com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest in project cloudbreak by hortonworks.

the class CmServiceKeytabRequestFactory method create.

public ServiceKeytabRequest create(Stack stack, GatewayConfig primaryGatewayConfig) {
    ServiceKeytabRequest request = new ServiceKeytabRequest();
    request.setEnvironmentCrn(stack.getEnvironmentCrn());
    request.setClusterCrn(stack.getResourceCrn());
    String fqdn = primaryGatewayConfig.getHostname();
    request.setServerHostName(fqdn);
    String hostname = StringUtils.substringBefore(fqdn, ".");
    if (!fqdn.equals(hostname)) {
        request.setServerHostNameAlias(hostname);
    }
    request.setServiceName("CM");
    request.setDoNotRecreateKeytab(Boolean.TRUE);
    RoleRequest roleRequest = new RoleRequest();
    roleRequest.setRoleName("hadoopadminrole-" + stack.getName());
    roleRequest.setPrivileges(Set.of("Service Administrators", "Certificate Administrators", "Host Administrators", "CA Administrator"));
    request.setRoleRequest(roleRequest);
    return request;
}
Also used : ServiceKeytabRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabRequest) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)

Example 2 with RoleRequest

use of com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest in project cloudbreak by hortonworks.

the class KeytabCommonServiceTest method testAddHostFreeIpaException.

@Test
public void testAddHostFreeIpaException() throws FreeIpaClientException {
    FreeIpaClient ipaClient = mock(FreeIpaClient.class);
    RoleRequest roleRequest = new RoleRequest();
    when(ipaClient.showHost(HOST)).thenThrow(new FreeIpaClientException("expected"));
    assertThrows(KeytabCreationException.class, () -> underTest.addHost(HOST, roleRequest, ipaClient));
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) Test(org.junit.jupiter.api.Test)

Example 3 with RoleRequest

use of com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest in project cloudbreak by hortonworks.

the class KeytabCommonServiceTest method testAddHostRetryableException.

@Test
public void testAddHostRetryableException() throws FreeIpaClientException {
    FreeIpaClient ipaClient = mock(FreeIpaClient.class);
    RoleRequest roleRequest = new RoleRequest();
    when(ipaClient.showHost(HOST)).thenThrow(new RetryableFreeIpaClientException("expected", new FreeIpaClientException("inner")));
    assertThrows(RetryableFreeIpaClientException.class, () -> underTest.addHost(HOST, roleRequest, ipaClient));
}
Also used : RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) Test(org.junit.jupiter.api.Test)

Example 4 with RoleRequest

use of com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest in project cloudbreak by hortonworks.

the class ServiceKeytabServiceTest method testGetExistingWithRoleRequest.

@Test
public void testGetExistingWithRoleRequest() {
    ServiceKeytabRequest request = new ServiceKeytabRequest();
    request.setEnvironmentCrn(ENVIRONMENT_CRN);
    request.setServiceName(SERVICE_NAME);
    request.setServerHostName(HOST);
    request.setRoleRequest(new RoleRequest());
    assertThrows(KeytabCreationException.class, () -> underTest.getExistingServiceKeytab(request, ACCOUNT_ID));
}
Also used : ServiceKeytabRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabRequest) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) Test(org.junit.jupiter.api.Test)

Example 5 with RoleRequest

use of com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest in project cloudbreak by hortonworks.

the class ServiceKeytabServiceTest method testGenerateExistingNotCachedDoNotRecreateTrue.

@Test
public void testGenerateExistingNotCachedDoNotRecreateTrue() throws FreeIpaClientException {
    ServiceKeytabRequest request = new ServiceKeytabRequest();
    request.setEnvironmentCrn(ENVIRONMENT_CRN);
    request.setServiceName(SERVICE_NAME);
    request.setServerHostName(HOST);
    request.setDoNotRecreateKeytab(Boolean.TRUE);
    request.setServerHostNameAlias(ALIAS);
    RoleRequest roleRequest = new RoleRequest();
    request.setRoleRequest(roleRequest);
    when(keytabCacheService.findByEnvironmentCrnAndPrincipal(ENVIRONMENT_CRN, PRINCIPAL)).thenReturn(Optional.empty());
    FreeIpaClient ipaClient = mock(FreeIpaClient.class);
    when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(ipaClient);
    when(roleComponent.privilegesExist(roleRequest, ipaClient)).thenReturn(Boolean.TRUE);
    Service service = new Service();
    service.setKrbcanonicalname(PRINCIPAL);
    service.setHasKeytab(Boolean.TRUE);
    when(ipaClient.showService(PRINCIPAL)).thenReturn(service);
    when(keytabCommonService.constructPrincipal(SERVICE_NAME, ALIAS, REALM)).thenReturn(ALIAS_PRINCIPAL);
    when(keytabCommonService.getExistingKeytab(ENVIRONMENT_CRN, PRINCIPAL, HOST, ipaClient)).thenReturn(keytabCache);
    ServiceKeytabResponse result = underTest.generateServiceKeytab(request, ACCOUNT_ID);
    verify(ipaClient).addServiceAlias(PRINCIPAL, ALIAS_PRINCIPAL);
    verify(roleComponent).addRoleAndPrivileges(Optional.of(service), Optional.empty(), roleRequest, ipaClient);
    assertEquals(keytabResponse, result.getKeytab());
    assertEquals(principalResponse, result.getServicePrincipal());
}
Also used : ServiceKeytabRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabRequest) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Service(com.sequenceiq.freeipa.client.model.Service) ServiceKeytabResponse(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabResponse) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) Test(org.junit.jupiter.api.Test)

Aggregations

RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)28 Test (org.junit.jupiter.api.Test)26 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)17 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)14 Host (com.sequenceiq.freeipa.client.model.Host)13 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)10 ServiceKeytabRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabRequest)8 Service (com.sequenceiq.freeipa.client.model.Service)7 HashSet (java.util.HashSet)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Privilege (com.sequenceiq.freeipa.client.model.Privilege)6 Role (com.sequenceiq.freeipa.client.model.Role)6 HostKeytabRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabRequest)5 ServiceKeytabResponse (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabResponse)5 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)5 Stack (com.sequenceiq.freeipa.entity.Stack)4 Optional (java.util.Optional)4 Secret (com.sequenceiq.cloudbreak.service.secret.domain.Secret)3 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)3 HostKeytabResponse (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabResponse)3