@Test void testInitCodeGrantFlowWhenInitCodeGrantFlowRequestFailsOnAwaitWithInterruptedExceptionThenOperationExceptionComes() throws InterruptedException { doThrow(new InterruptedException("Error while executing initialization of authorization code grant based credential creation:")) .when(initCodeGrantFlowRequest).await(); OperationException operationException = assertThrows(OperationException.class, () -> underTest.initCodeGrantFlow(credential, ACCOUNT_ID, USER_ID)); assertThat(operationException.getMessage()) .contains("Error while executing initialization of authorization code grant based credential creation:"); }
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);  }