@Test public void testInitCodeGrantFlow() { String accessKey = "someAccessKey"; String tenantId = "1"; String secretKey = "someExtremelySecretKey"; String redirectUrl = "some.url.com"; Map<String, Object> parameters = new HashMap<>(); Map<String, Object> azureParams = new HashMap<>(); Map<String, String> codeGrantFlowParams = new HashMap<>(); codeGrantFlowParams.put("accessKey", accessKey); codeGrantFlowParams.put("tenantId", tenantId); codeGrantFlowParams.put("secretKey", secretKey); codeGrantFlowParams.put("deploymentAddress", DEPLOYMENT_ADDRESS); azureParams.put("codeGrantFlowBased", codeGrantFlowParams); parameters.put("azure", azureParams); CloudCredential cloudCredential = new CloudCredential("anId", "aName", parameters, false); when(appCreationCommand.getRedirectURL(String.valueOf(WORKSPACE_ID), DEPLOYMENT_ADDRESS)).thenReturn(redirectUrl); Map<String, String> result = underTest.initCodeGrantFlow(TEST_CLOUD_CONTEXT, cloudCredential); assertNotNull(result); assertFalse(result.isEmpty()); assertTrue(result.containsKey("appLoginUrl")); assertTrue(result.containsKey("appReplyUrl")); assertTrue(result.containsKey("codeGrantFlowState")); assertTrue(result.get("appLoginUrl").contains(result.get("codeGrantFlowState"))); assertEquals(redirectUrl, result.get("appReplyUrl")); verify(appCreationCommand, times(1)).getRedirectURL(String.valueOf(WORKSPACE_ID), DEPLOYMENT_ADDRESS); }
@Override public Map<String, String> initCodeGrantFlow(CloudContext cloudContext, CloudCredential cloudCredential) { Map<String, String> parameters = new HashMap<>(); AzureCredentialView azureCredential = new AzureCredentialView(cloudCredential); ApplicationTokenCredentials applicationCredentials = new ApplicationTokenCredentials( azureCredential.getAccessKey(), azureCredential.getTenantId(), azureCredential.getSecretKey(), AzureEnvironment.AZURE); String replyUrl = appCreationCommand.getRedirectURL(String.valueOf(cloudContext.getAccountId()), azureCredential.getDeploymentAddress()); CbDelegatedTokenCredentials creds = new CbDelegatedTokenCredentials(applicationCredentials, replyUrl, authenticationContextProvider, cbRefreshTokenClientProvider); String state = UUID.randomUUID().toString(); parameters.put("appLoginUrl", creds.generateAuthenticationUrl(state)); parameters.put("appReplyUrl", replyUrl); parameters.put("codeGrantFlowState", state); return parameters; }
AzureCredentialConnector implements CredentialConnector { @Override public Map<String, String> initCodeGrantFlow(CloudContext cloudContext, CloudCredential cloudCredential) { Map<String, String> parameters = new HashMap<>(); AzureCredentialView azureCredential = new AzureCredentialView(cloudCredential); ApplicationTokenCredentials applicationCredentials = new ApplicationTokenCredentials( azureCredential.getAccessKey(), azureCredential.getTenantId(), azureCredential.getSecretKey(), AzureEnvironment.AZURE); String replyUrl = appCreationCommand.getRedirectURL(String.valueOf(cloudContext.getAccountId()), azureCredential.getDeploymentAddress()); CbDelegatedTokenCredentials creds = new CbDelegatedTokenCredentials(applicationCredentials, replyUrl, authenticationContextProvider, cbRefreshTokenClientProvider); String state = UUID.randomUUID().toString(); parameters.put("appLoginUrl", creds.generateAuthenticationUrl(state)); parameters.put("appReplyUrl", replyUrl); parameters.put("codeGrantFlowState", state); return parameters; } }
AzureCredentialConnector implements CredentialConnector { @Override public Map<String, String> initCodeGrantFlow(CloudContext cloudContext, CloudCredential cloudCredential) { Map<String, String> parameters = new HashMap<>(); AzureCredentialView azureCredential = new AzureCredentialView(cloudCredential); ApplicationTokenCredentials applicationCredentials = new ApplicationTokenCredentials( azureCredential.getAccessKey(), azureCredential.getTenantId(), azureCredential.getSecretKey(), AzureEnvironment.AZURE); String replyUrl = appCreationCommand.getRedirectURL(String.valueOf(cloudContext.getAccountId()), azureCredential.getDeploymentAddress()); CbDelegatedTokenCredentials creds = new CbDelegatedTokenCredentials(applicationCredentials, replyUrl, authenticationContextProvider, cbRefreshTokenClientProvider); String state = UUID.randomUUID().toString(); parameters.put("appLoginUrl", creds.generateAuthenticationUrl(state)); parameters.put("appReplyUrl", replyUrl); parameters.put("codeGrantFlowState", state); return parameters; }  }
AzureCredentialConnector implements CredentialConnector { @Override public Map<String, String> initCodeGrantFlow(CloudContext cloudContext, CloudCredential cloudCredential) { Map<String, String> parameters = new HashMap<>(); AzureCredentialView azureCredential = new AzureCredentialView(cloudCredential); ApplicationTokenCredentials applicationCredentials = new ApplicationTokenCredentials( azureCredential.getAccessKey(), azureCredential.getTenantId(), azureCredential.getSecretKey(), AzureEnvironment.AZURE); String replyUrl = appCreationCommand.getRedirectURL(String.valueOf(cloudContext.getAccountId()), azureCredential.getDeploymentAddress()); CbDelegatedTokenCredentials creds = new CbDelegatedTokenCredentials(applicationCredentials, replyUrl, authenticationContextProvider, cbRefreshTokenClientProvider); String state = UUID.randomUUID().toString(); parameters.put("appLoginUrl", creds.generateAuthenticationUrl(state)); parameters.put("appReplyUrl", replyUrl); parameters.put("codeGrantFlowState", state); return parameters; }  @Override CloudCredentialStatus verify(AuthenticatedContext authenticatedContext, CredentialVerificationContext credentialVerificationContext); @Override CloudCredentialStatus create(AuthenticatedContext authenticatedContext); @Override Map<String, String> interactiveLogin(CloudContext cloudContext, ExtendedCloudCredential extendedCloudCredential,
            CredentialNotifier credentialNotifier); @Override CloudCredentialStatus delete(AuthenticatedContext authenticatedContext); @Override CredentialPrerequisitesResponse getPrerequisites(CloudContext cloudContext, String externalId, String deploymentAddress, CredentialType type); @Override Map<String, String> initCodeGrantFlow(CloudContext cloudContext, CloudCredential cloudCredential); }
AzureCredentialConnector implements CredentialConnector { @Override public Map<String, String> initCodeGrantFlow(CloudContext cloudContext, CloudCredential cloudCredential) { Map<String, String> parameters = new HashMap<>(); AzureCredentialView azureCredential = new AzureCredentialView(cloudCredential); ApplicationTokenCredentials applicationCredentials = new ApplicationTokenCredentials( azureCredential.getAccessKey(), azureCredential.getTenantId(), azureCredential.getSecretKey(), AzureEnvironment.AZURE); String replyUrl = appCreationCommand.getRedirectURL(String.valueOf(cloudContext.getAccountId()), azureCredential.getDeploymentAddress()); CbDelegatedTokenCredentials creds = new CbDelegatedTokenCredentials(applicationCredentials, replyUrl, authenticationContextProvider, cbRefreshTokenClientProvider); String state = UUID.randomUUID().toString(); parameters.put("appLoginUrl", creds.generateAuthenticationUrl(state)); parameters.put("appReplyUrl", replyUrl); parameters.put("codeGrantFlowState", state); return parameters; }  @Override CloudCredentialStatus verify(AuthenticatedContext authenticatedContext, CredentialVerificationContext credentialVerificationContext); @Override CloudCredentialStatus create(AuthenticatedContext authenticatedContext); @Override Map<String, String> interactiveLogin(CloudContext cloudContext, ExtendedCloudCredential extendedCloudCredential,
            CredentialNotifier credentialNotifier); @Override CloudCredentialStatus delete(AuthenticatedContext authenticatedContext); @Override CredentialPrerequisitesResponse getPrerequisites(CloudContext cloudContext, String externalId, String deploymentAddress, CredentialType type); @Override Map<String, String> initCodeGrantFlow(CloudContext cloudContext, CloudCredential cloudCredential);  }