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