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;
}
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));
}
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));
}
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));
}
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());
}
Aggregations