@Test void testInitCodeGrantFlow() { when(credentialAdapter.initCodeGrantFlow(any(), anyString(), anyString())).thenReturn(CREDENTIAL); when(repository.save(any())).thenReturn(CREDENTIAL); String result = credentialServiceUnderTest.initCodeGrantFlow(ACCOUNT_ID, CREDENTIAL, USER_ID); assertEquals(REDIRECT_URL, result); verify(repository).save(eq(CREDENTIAL)); }
public String initCodeGrantFlow(String accountId, @Nonnull Credential credential, String creatorUserCrn) { repository.findByNameAndAccountId(credential.getName(), accountId, getEnabledPlatforms(), ENVIRONMENT) .map(Credential::getName) .ifPresent(name -> { throw new BadRequestException("Credential already exists with name: " + name); }); LOGGER.debug("Validating credential for cloudPlatform {} and creator {}.", credential.getCloudPlatform(), creatorUserCrn); credentialValidator.validateCredentialCloudPlatform(credential.getCloudPlatform(), creatorUserCrn); validateDeploymentAddress(credential); Credential created = credentialAdapter.initCodeGrantFlow(credential, accountId, creatorUserCrn); created.setResourceCrn(createCRN(accountId)); created.setAccountId(accountId); created.setCreator(creatorUserCrn); created = repository.save(created); return getCodeGrantFlowAppLoginUrl(created); }
CredentialService extends AbstractCredentialService implements ResourceBasedCrnProvider { public String initCodeGrantFlow(String accountId, @Nonnull Credential credential, String creatorUserCrn) { repository.findByNameAndAccountId(credential.getName(), accountId, getEnabledPlatforms(), ENVIRONMENT) .map(Credential::getName) .ifPresent(name -> { throw new BadRequestException("Credential already exists with name: " + name); }); LOGGER.debug("Validating credential for cloudPlatform {} and creator {}.", credential.getCloudPlatform(), creatorUserCrn); credentialValidator.validateCredentialCloudPlatform(credential.getCloudPlatform(), creatorUserCrn); validateDeploymentAddress(credential); Credential created = credentialAdapter.initCodeGrantFlow(credential, accountId, creatorUserCrn); created.setResourceCrn(createCRN(accountId)); created.setAccountId(accountId); created.setCreator(creatorUserCrn); created = repository.save(created); return getCodeGrantFlowAppLoginUrl(created); } }
CredentialService extends AbstractCredentialService implements ResourceBasedCrnProvider { public String initCodeGrantFlow(String accountId, @Nonnull Credential credential, String creatorUserCrn) { repository.findByNameAndAccountId(credential.getName(), accountId, getEnabledPlatforms(), ENVIRONMENT) .map(Credential::getName) .ifPresent(name -> { throw new BadRequestException("Credential already exists with name: " + name); }); LOGGER.debug("Validating credential for cloudPlatform {} and creator {}.", credential.getCloudPlatform(), creatorUserCrn); credentialValidator.validateCredentialCloudPlatform(credential.getCloudPlatform(), creatorUserCrn); validateDeploymentAddress(credential); Credential created = credentialAdapter.initCodeGrantFlow(credential, accountId, creatorUserCrn); created.setResourceCrn(createCRN(accountId)); created.setAccountId(accountId); created.setCreator(creatorUserCrn); created = repository.save(created); return getCodeGrantFlowAppLoginUrl(created); } protected  CredentialService(NotificationSender notificationSender, CloudbreakMessagesService messagesService,
            @Value("${environment.enabledplatforms}") Set<String> enabledPlatforms); }
CredentialService extends AbstractCredentialService implements ResourceBasedCrnProvider { public String initCodeGrantFlow(String accountId, @Nonnull Credential credential, String creatorUserCrn) { repository.findByNameAndAccountId(credential.getName(), accountId, getEnabledPlatforms(), ENVIRONMENT) .map(Credential::getName) .ifPresent(name -> { throw new BadRequestException("Credential already exists with name: " + name); }); LOGGER.debug("Validating credential for cloudPlatform {} and creator {}.", credential.getCloudPlatform(), creatorUserCrn); credentialValidator.validateCredentialCloudPlatform(credential.getCloudPlatform(), creatorUserCrn); validateDeploymentAddress(credential); Credential created = credentialAdapter.initCodeGrantFlow(credential, accountId, creatorUserCrn); created.setResourceCrn(createCRN(accountId)); created.setAccountId(accountId); created.setCreator(creatorUserCrn); created = repository.save(created); return getCodeGrantFlowAppLoginUrl(created); } protected  CredentialService(NotificationSender notificationSender, CloudbreakMessagesService messagesService,
            @Value("${environment.enabledplatforms}") Set<String> enabledPlatforms); Set<Credential> listAvailablesByAccountId(String accountId, CredentialType type); @Cacheable(cacheNames = "credentialCloudPlatformCache") Set<String> getValidPlatformsForAccountId(String accountId); Credential getByNameForAccountId(String name, String accountId, CredentialType type); Optional<Credential> getOptionalByNameForAccountId(String name, String accountId, CredentialType type); Credential getByCrnForAccountId(String crn, String accountId, CredentialType type); Optional<Credential> getOptionalByCrnForAccountId(String crn, String accountId, CredentialType type); Credential extractCredential(Optional<Credential> credential, String resourceIdentifier); Credential getByEnvironmentCrnAndAccountId(String environmentCrn, String accountId, CredentialType type); Credential getByEnvironmentNameAndAccountId(String environmentName, String accountId, CredentialType type); Map<String, String> interactiveLogin(String accountId, String userId, Credential credential); Credential verify(Credential credential); Credential updateByAccountId(Credential credential, String accountId, CredentialType type); @Retryable(value = BadRequestException.class, maxAttempts = 30, backoff = @Backoff(delay = 2000)) void createWithRetry(Credential credential, String accountId, String creatorUserCrn); Credential create(Credential credential, @Nonnull String accountId, @Nonnull String creatorUserCrn, CredentialType type); CredentialPrerequisitesResponse getPrerequisites(String cloudPlatform, String deploymentAddress, String userCrn, CredentialType type); String initCodeGrantFlow(String accountId, @Nonnull Credential credential, String creatorUserCrn); String initCodeGrantFlow(String accountId, String name, String userId); Credential authorizeCodeGrantFlow(String code, @Nonnull String state, String accountId, @Nonnull String platform); String getCloudPlatformByCredential(String credentialName, String accountId, CredentialType type); CreateAWSCredentialRequest getCreateAWSCredentialForCli(CredentialRequest credentialRequest); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount(); @Override AuthorizationResourceType getResourceType(); }
CredentialService extends AbstractCredentialService implements ResourceBasedCrnProvider { public String initCodeGrantFlow(String accountId, @Nonnull Credential credential, String creatorUserCrn) { repository.findByNameAndAccountId(credential.getName(), accountId, getEnabledPlatforms(), ENVIRONMENT) .map(Credential::getName) .ifPresent(name -> { throw new BadRequestException("Credential already exists with name: " + name); }); LOGGER.debug("Validating credential for cloudPlatform {} and creator {}.", credential.getCloudPlatform(), creatorUserCrn); credentialValidator.validateCredentialCloudPlatform(credential.getCloudPlatform(), creatorUserCrn); validateDeploymentAddress(credential); Credential created = credentialAdapter.initCodeGrantFlow(credential, accountId, creatorUserCrn); created.setResourceCrn(createCRN(accountId)); created.setAccountId(accountId); created.setCreator(creatorUserCrn); created = repository.save(created); return getCodeGrantFlowAppLoginUrl(created); } protected  CredentialService(NotificationSender notificationSender, CloudbreakMessagesService messagesService,
            @Value("${environment.enabledplatforms}") Set<String> enabledPlatforms); Set<Credential> listAvailablesByAccountId(String accountId, CredentialType type); @Cacheable(cacheNames = "credentialCloudPlatformCache") Set<String> getValidPlatformsForAccountId(String accountId); Credential getByNameForAccountId(String name, String accountId, CredentialType type); Optional<Credential> getOptionalByNameForAccountId(String name, String accountId, CredentialType type); Credential getByCrnForAccountId(String crn, String accountId, CredentialType type); Optional<Credential> getOptionalByCrnForAccountId(String crn, String accountId, CredentialType type); Credential extractCredential(Optional<Credential> credential, String resourceIdentifier); Credential getByEnvironmentCrnAndAccountId(String environmentCrn, String accountId, CredentialType type); Credential getByEnvironmentNameAndAccountId(String environmentName, String accountId, CredentialType type); Map<String, String> interactiveLogin(String accountId, String userId, Credential credential); Credential verify(Credential credential); Credential updateByAccountId(Credential credential, String accountId, CredentialType type); @Retryable(value = BadRequestException.class, maxAttempts = 30, backoff = @Backoff(delay = 2000)) void createWithRetry(Credential credential, String accountId, String creatorUserCrn); Credential create(Credential credential, @Nonnull String accountId, @Nonnull String creatorUserCrn, CredentialType type); CredentialPrerequisitesResponse getPrerequisites(String cloudPlatform, String deploymentAddress, String userCrn, CredentialType type); String initCodeGrantFlow(String accountId, @Nonnull Credential credential, String creatorUserCrn); String initCodeGrantFlow(String accountId, String name, String userId); Credential authorizeCodeGrantFlow(String code, @Nonnull String state, String accountId, @Nonnull String platform); String getCloudPlatformByCredential(String credentialName, String accountId, CredentialType type); CreateAWSCredentialRequest getCreateAWSCredentialForCli(CredentialRequest credentialRequest); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount(); @Override AuthorizationResourceType getResourceType();  }