Search in sources :

Example 1 with InteractiveCredentialResponse

use of com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse in project cloudbreak by hortonworks.

the class CredentialV1Controller method interactiveLogin.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.CREATE_CREDENTIAL)
public InteractiveCredentialResponse interactiveLogin(@Valid CredentialRequest credentialRequest) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    Credential credential = credentialConverter.convert(credentialRequest);
    credential.setType(ENVIRONMENT);
    Map<String, String> result = credentialService.interactiveLogin(accountId, credential);
    return new InteractiveCredentialResponse(result.get("user_code"), result.get("verification_url"));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) InteractiveCredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 2 with InteractiveCredentialResponse

use of com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse in project cloudbreak by hortonworks.

the class EnvironmentServiceIntegrationTest method testCredentialInteractiveLogin.

@Test
public void testCredentialInteractiveLogin() throws InterruptedException {
    credentialRequest.setName("testcredential");
    credentialRequest.setCloudPlatform("AZURE");
    AzureCredentialRequestParameters azureCredentialRequestParameters = new AzureCredentialRequestParameters();
    azureCredentialRequestParameters.setSubscriptionId("subid");
    azureCredentialRequestParameters.setTenantId("tenant");
    RoleBasedRequest roleBasedRequest = new RoleBasedRequest();
    roleBasedRequest.setDeploymentAddress("alma");
    roleBasedRequest.setRoleName("role");
    azureCredentialRequestParameters.setRoleBased(roleBasedRequest);
    credentialRequest.setAzure(azureCredentialRequestParameters);
    InteractiveLoginResult interactiveLoginResult = new InteractiveLoginResult(1L, Map.of("user_code", USER_CODE, "verification_url", VERIFICATION_URL));
    when(requestProvider.getInteractiveLoginRequest(any(), any())).thenReturn(interactiveLoginRequest);
    when(interactiveLoginRequest.await()).thenReturn(interactiveLoginResult);
    InteractiveCredentialResponse result = client.credentialV1Endpoint().interactiveLogin(credentialRequest);
    assertEquals(result.getUserCode(), USER_CODE);
    assertEquals(result.getVerificationUrl(), VERIFICATION_URL);
}
Also used : InteractiveLoginResult(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginResult) AzureCredentialRequestParameters(com.sequenceiq.environment.api.v1.credential.model.parameters.azure.AzureCredentialRequestParameters) InteractiveCredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse) RoleBasedRequest(com.sequenceiq.environment.api.v1.credential.model.parameters.azure.RoleBasedRequest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

InteractiveCredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse)2 CheckPermissionByAccount (com.sequenceiq.authorization.annotation.CheckPermissionByAccount)1 InteractiveLoginResult (com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginResult)1 AzureCredentialRequestParameters (com.sequenceiq.environment.api.v1.credential.model.parameters.azure.AzureCredentialRequestParameters)1 RoleBasedRequest (com.sequenceiq.environment.api.v1.credential.model.parameters.azure.RoleBasedRequest)1 Credential (com.sequenceiq.environment.credential.domain.Credential)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1