@Test void testInitCodeGrantFlowShouldAddAdditionalAttributesToAzureCodeGrantFlowAttributes() { String expectedAdditionalAttributeKey = "someCloudCredentialKey"; String expectedAdditionalAttributeValue = "someCloudCredentialValue"; String initialAttributeKey = "aKey"; String initialAttributeValue = "aValue"; Map<String, Object> initialAttributes = new HashMap<>(); Map<String, Object> initialAzureAttributes = new HashMap<>(); Map<String, String> initialAzureCodeGrantFlowParams = new HashMap<>(); initialAzureCodeGrantFlowParams.put(initialAttributeKey, initialAttributeValue); initialAzureAttributes.put("codeGrantFlowBased", initialAzureCodeGrantFlowParams); initialAttributes.put("azure", initialAzureAttributes); Credential credential = new Credential(); String initialCredentialAttriute = new Json(initialAttributes).getValue(); credential.setAttributes(initialCredentialAttriute); credential.setId(CREDENTIAL_ID); credential.setCloudPlatform(CLOUD_PLATFORM); credential.setName(CREDENTIAL_NAME); when(credentialConverter.convert(credential)).thenReturn(convertedCredential); when(initCodeGrantFlowResponse.getCodeGrantFlowInitParams()).thenReturn(Map.of(expectedAdditionalAttributeKey, expectedAdditionalAttributeValue)); Credential result = underTest.initCodeGrantFlow(credential, ACCOUNT_ID, USER_ID); assertNotEquals(initialCredentialAttriute, result.getAttributes()); var attributeMap = new Json(result.getAttributes()).getMap(); Map<String, Object> azureAttributes = (Map<String, Object>) attributeMap.get("azure"); Map<String, String> codeGrattFlowAttributes = (Map<String, String>) azureAttributes.get("codeGrantFlowBased"); assertTrue(codeGrattFlowAttributes.containsKey(initialAttributeKey)); assertTrue(codeGrattFlowAttributes.containsKey(expectedAdditionalAttributeKey)); assertEquals(expectedAdditionalAttributeValue, codeGrattFlowAttributes.get(expectedAdditionalAttributeKey)); assertEquals(initialAttributeValue, codeGrattFlowAttributes.get(initialAttributeKey)); assertEquals(credential, result); }
public Credential initCodeGrantFlow(Credential credential, String accountId, String userId) { CloudContext cloudContext = new CloudContext(credential.getId(), credential.getName(), credential.getCloudPlatform(), userId, accountId); CloudCredential cloudCredential = credentialConverter.convert(credential); LOGGER.debug("Requesting code grant flow cloudPlatform {} and creator {}.", credential.getCloudPlatform(), userId); InitCodeGrantFlowRequest request = requestProvider.getInitCodeGrantFlowRequest(cloudContext, cloudCredential); LOGGER.info("Triggering event: {}", request); eventBus.notify(request.selector(), eventFactory.createEvent(request)); try { InitCodeGrantFlowResponse res = request.await(); LOGGER.info("Result: {}", res); if (res.getStatus() != EventStatus.OK) { String message = "Authorization code grant based credential creation couldn't be initialized: "; LOGGER.error(message, res.getErrorDetails()); throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails()); } Map<String, String> codeGrantFlowInitParams = res.getCodeGrantFlowInitParams(); addCodeGrantFlowInitAttributesToCredential(credential, codeGrantFlowInitParams); return credential; } catch (InterruptedException e) { LOGGER.error("Error while executing initialization of authorization code grant based credential creation:", e); throw new OperationException(e); } }
ServiceProviderCredentialAdapter { public Credential initCodeGrantFlow(Credential credential, String accountId, String userId) { CloudContext cloudContext = new CloudContext(credential.getId(), credential.getName(), credential.getCloudPlatform(), userId, accountId); CloudCredential cloudCredential = credentialConverter.convert(credential); LOGGER.debug("Requesting code grant flow cloudPlatform {} and creator {}.", credential.getCloudPlatform(), userId); InitCodeGrantFlowRequest request = requestProvider.getInitCodeGrantFlowRequest(cloudContext, cloudCredential); LOGGER.info("Triggering event: {}", request); eventBus.notify(request.selector(), eventFactory.createEvent(request)); try { InitCodeGrantFlowResponse res = request.await(); LOGGER.info("Result: {}", res); if (res.getStatus() != EventStatus.OK) { String message = "Authorization code grant based credential creation couldn't be initialized: "; LOGGER.error(message, res.getErrorDetails()); throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails()); } Map<String, String> codeGrantFlowInitParams = res.getCodeGrantFlowInitParams(); addCodeGrantFlowInitAttributesToCredential(credential, codeGrantFlowInitParams); return credential; } catch (InterruptedException e) { LOGGER.error("Error while executing initialization of authorization code grant based credential creation:", e); throw new OperationException(e); } } }
ServiceProviderCredentialAdapter { public Credential initCodeGrantFlow(Credential credential, String accountId, String userId) { CloudContext cloudContext = new CloudContext(credential.getId(), credential.getName(), credential.getCloudPlatform(), userId, accountId); CloudCredential cloudCredential = credentialConverter.convert(credential); LOGGER.debug("Requesting code grant flow cloudPlatform {} and creator {}.", credential.getCloudPlatform(), userId); InitCodeGrantFlowRequest request = requestProvider.getInitCodeGrantFlowRequest(cloudContext, cloudCredential); LOGGER.info("Triggering event: {}", request); eventBus.notify(request.selector(), eventFactory.createEvent(request)); try { InitCodeGrantFlowResponse res = request.await(); LOGGER.info("Result: {}", res); if (res.getStatus() != EventStatus.OK) { String message = "Authorization code grant based credential creation couldn't be initialized: "; LOGGER.error(message, res.getErrorDetails()); throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails()); } Map<String, String> codeGrantFlowInitParams = res.getCodeGrantFlowInitParams(); addCodeGrantFlowInitAttributesToCredential(credential, codeGrantFlowInitParams); return credential; } catch (InterruptedException e) { LOGGER.error("Error while executing initialization of authorization code grant based credential creation:", e); throw new OperationException(e); } }  }
ServiceProviderCredentialAdapter { public Credential initCodeGrantFlow(Credential credential, String accountId, String userId) { CloudContext cloudContext = new CloudContext(credential.getId(), credential.getName(), credential.getCloudPlatform(), userId, accountId); CloudCredential cloudCredential = credentialConverter.convert(credential); LOGGER.debug("Requesting code grant flow cloudPlatform {} and creator {}.", credential.getCloudPlatform(), userId); InitCodeGrantFlowRequest request = requestProvider.getInitCodeGrantFlowRequest(cloudContext, cloudCredential); LOGGER.info("Triggering event: {}", request); eventBus.notify(request.selector(), eventFactory.createEvent(request)); try { InitCodeGrantFlowResponse res = request.await(); LOGGER.info("Result: {}", res); if (res.getStatus() != EventStatus.OK) { String message = "Authorization code grant based credential creation couldn't be initialized: "; LOGGER.error(message, res.getErrorDetails()); throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails()); } Map<String, String> codeGrantFlowInitParams = res.getCodeGrantFlowInitParams(); addCodeGrantFlowInitAttributesToCredential(credential, codeGrantFlowInitParams); return credential; } catch (InterruptedException e) { LOGGER.error("Error while executing initialization of authorization code grant based credential creation:", e); throw new OperationException(e); } }  CredentialVerification verify(Credential credential, String accountId); CredentialVerification verify(Credential credential, String accountId, boolean creationVerification); Map<String, String> interactiveLogin(Credential credential, String accountId, String userId); Credential update(Credential credential); Credential initCodeGrantFlow(Credential credential, String accountId, String userId); }
ServiceProviderCredentialAdapter { public Credential initCodeGrantFlow(Credential credential, String accountId, String userId) { CloudContext cloudContext = new CloudContext(credential.getId(), credential.getName(), credential.getCloudPlatform(), userId, accountId); CloudCredential cloudCredential = credentialConverter.convert(credential); LOGGER.debug("Requesting code grant flow cloudPlatform {} and creator {}.", credential.getCloudPlatform(), userId); InitCodeGrantFlowRequest request = requestProvider.getInitCodeGrantFlowRequest(cloudContext, cloudCredential); LOGGER.info("Triggering event: {}", request); eventBus.notify(request.selector(), eventFactory.createEvent(request)); try { InitCodeGrantFlowResponse res = request.await(); LOGGER.info("Result: {}", res); if (res.getStatus() != EventStatus.OK) { String message = "Authorization code grant based credential creation couldn't be initialized: "; LOGGER.error(message, res.getErrorDetails()); throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails()); } Map<String, String> codeGrantFlowInitParams = res.getCodeGrantFlowInitParams(); addCodeGrantFlowInitAttributesToCredential(credential, codeGrantFlowInitParams); return credential; } catch (InterruptedException e) { LOGGER.error("Error while executing initialization of authorization code grant based credential creation:", e); throw new OperationException(e); } }  CredentialVerification verify(Credential credential, String accountId); CredentialVerification verify(Credential credential, String accountId, boolean creationVerification); Map<String, String> interactiveLogin(Credential credential, String accountId, String userId); Credential update(Credential credential); Credential initCodeGrantFlow(Credential credential, String accountId, String userId);  }