Search in sources :

Example 1 with CredentialAttributes

use of com.sequenceiq.environment.credential.attributes.CredentialAttributes in project cloudbreak by hortonworks.

the class CredentialService method updateAuthorizationCodeOfAzureCredential.

private void updateAuthorizationCodeOfAzureCredential(Credential credential, String authorizationCode) {
    try {
        CredentialAttributes credentialAttributes = new Json(credential.getAttributes()).get(CredentialAttributes.class);
        if (credentialAttributes.getAzure() != null && credentialAttributes.getAzure().getCodeGrantFlowBased() != null) {
            CodeGrantFlowAttributes codeGrantFlowAttributes = credentialAttributes.getAzure().getCodeGrantFlowBased();
            codeGrantFlowAttributes.setAuthorizationCode(authorizationCode);
            credential.setAttributes(new Json(credentialAttributes).getValue());
        }
    } catch (IOException e) {
        LOGGER.info("Attributes of credential '{}' could not get from JSON attributes", credential.getName());
    }
}
Also used : CredentialAttributes(com.sequenceiq.environment.credential.attributes.CredentialAttributes) CodeGrantFlowAttributes(com.sequenceiq.environment.credential.attributes.azure.CodeGrantFlowAttributes) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException)

Example 2 with CredentialAttributes

use of com.sequenceiq.environment.credential.attributes.CredentialAttributes in project cloudbreak by hortonworks.

the class CredentialServiceTest method getTestAttributesWithCodeGrantFlow.

private String getTestAttributesWithCodeGrantFlow(CodeGrantFlowAttributes codeGrantFlowAttributes) {
    CredentialAttributes credentialAttributes = new CredentialAttributes();
    AzureCredentialAttributes azureAttributes = new AzureCredentialAttributes();
    azureAttributes.setCodeGrantFlowBased(codeGrantFlowAttributes);
    credentialAttributes.setAzure(azureAttributes);
    return getAttributesAsString(credentialAttributes);
}
Also used : AzureCredentialAttributes(com.sequenceiq.environment.credential.attributes.azure.AzureCredentialAttributes) CredentialAttributes(com.sequenceiq.environment.credential.attributes.CredentialAttributes) AzureCredentialAttributes(com.sequenceiq.environment.credential.attributes.azure.AzureCredentialAttributes)

Example 3 with CredentialAttributes

use of com.sequenceiq.environment.credential.attributes.CredentialAttributes in project cloudbreak by hortonworks.

the class CredentialServiceTest method testAuthorizeCodeGrantFlowFoundStateMatches.

@Test
void testAuthorizeCodeGrantFlowFoundStateMatches() throws IOException {
    when(repository.save(any())).thenReturn(CREDENTIAL);
    when(repository.findAllByAccountId(eq(ACCOUNT_ID), anyCollection(), any())).thenReturn(Set.of(CREDENTIAL));
    when(credentialAdapter.verify(any(), anyString())).thenAnswer(i -> new CredentialVerification(i.getArgument(0), true));
    Credential result = credentialServiceUnderTest.authorizeCodeGrantFlow(DIFFERENT_CODE, STATE, ACCOUNT_ID, "platform");
    CredentialAttributes resultAttributes = new Json(result.getAttributes()).get(CredentialAttributes.class);
    assertEquals(DIFFERENT_CODE, resultAttributes.getAzure().getCodeGrantFlowBased().getAuthorizationCode());
}
Also used : AzureCredentialAttributes(com.sequenceiq.environment.credential.attributes.azure.AzureCredentialAttributes) CredentialAttributes(com.sequenceiq.environment.credential.attributes.CredentialAttributes) Credential(com.sequenceiq.environment.credential.domain.Credential) CredentialVerification(com.sequenceiq.environment.credential.verification.CredentialVerification) Json(com.sequenceiq.cloudbreak.common.json.Json) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with CredentialAttributes

use of com.sequenceiq.environment.credential.attributes.CredentialAttributes in project cloudbreak by hortonworks.

the class CredentialV1RequestToCredentialConverter method convertAttributes.

private void convertAttributes(CredentialRequest source, Credential credential) {
    CredentialAttributes credentialAttributes = new CredentialAttributes();
    doIfNotNull(source.getAws(), param -> credentialAttributes.setAws(awsConverter.convert(param)));
    doIfNotNull(source.getAzure(), param -> credentialAttributes.setAzure(azureConverter.convert(param)));
    doIfNotNull(source.getGcp(), param -> credentialAttributes.setGcp(gcpConverter.convert(param)));
    doIfNotNull(source.getMock(), param -> credentialAttributes.setMock(mockConverter.convert(param)));
    doIfNotNull(source.getYarn(), param -> credentialAttributes.setYarn(yarnConverter.convert(param)));
    credential.setAttributes(new Json(credentialAttributes).getValue());
}
Also used : CredentialAttributes(com.sequenceiq.environment.credential.attributes.CredentialAttributes) Json(com.sequenceiq.cloudbreak.common.json.Json)

Example 5 with CredentialAttributes

use of com.sequenceiq.environment.credential.attributes.CredentialAttributes in project cloudbreak by hortonworks.

the class CredentialServiceTest method testInteractiveLoginBadRequestNoCorrectAttributes.

@Test
void testInteractiveLoginBadRequestNoCorrectAttributes() throws JsonProcessingException {
    CredentialAttributes azureAttributes = new CredentialAttributes();
    CREDENTIAL.setAttributes(JsonUtil.writeValueAsString(azureAttributes));
    when(credentialAdapter.interactiveLogin(eq(CREDENTIAL), anyString())).thenReturn(Map.of("any", "any"));
    assertThrows(BadRequestException.class, () -> credentialServiceUnderTest.interactiveLogin("any", CREDENTIAL));
}
Also used : AzureCredentialAttributes(com.sequenceiq.environment.credential.attributes.azure.AzureCredentialAttributes) CredentialAttributes(com.sequenceiq.environment.credential.attributes.CredentialAttributes) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

CredentialAttributes (com.sequenceiq.environment.credential.attributes.CredentialAttributes)9 Json (com.sequenceiq.cloudbreak.common.json.Json)6 AzureCredentialAttributes (com.sequenceiq.environment.credential.attributes.azure.AzureCredentialAttributes)3 IOException (java.io.IOException)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 CodeGrantFlowAttributes (com.sequenceiq.environment.credential.attributes.azure.CodeGrantFlowAttributes)1 Credential (com.sequenceiq.environment.credential.domain.Credential)1 CredentialVerification (com.sequenceiq.environment.credential.verification.CredentialVerification)1 BadRequestException (javax.ws.rs.BadRequestException)1