Search in sources :

Example 1 with LinkedAccountWithPassportAndVisas

use of bio.terra.externalcreds.models.LinkedAccountWithPassportAndVisas in project terra-external-credentials-manager by DataBiosphere.

the class ProviderService method getRefreshedPassportsAndVisas.

private LinkedAccountWithPassportAndVisas getRefreshedPassportsAndVisas(LinkedAccount linkedAccount) {
    var clientRegistration = providerClientCache.getProviderClient(linkedAccount.getProviderName()).orElseThrow(() -> new ExternalCredsException(String.format("Unable to find configs for the provider: %s", linkedAccount.getProviderName())));
    var accessTokenResponse = oAuth2Service.authorizeWithRefreshToken(clientRegistration, new OAuth2RefreshToken(linkedAccount.getRefreshToken(), null));
    // save the linked account with the new refresh token and extracted passport
    var linkedAccountWithRefreshToken = Optional.ofNullable(accessTokenResponse.getRefreshToken()).map(refreshToken -> linkedAccountService.upsertLinkedAccount(linkedAccount.withRefreshToken(refreshToken.getTokenValue()))).orElse(linkedAccount);
    // update the passport and visas
    var userInfo = oAuth2Service.getUserInfo(clientRegistration, accessTokenResponse.getAccessToken());
    return jwtUtils.enrichAccountWithPassportAndVisas(linkedAccountWithRefreshToken, userInfo);
}
Also used : AuditLogEvent(bio.terra.externalcreds.auditLogging.AuditLogEvent) VisaVerificationDetails(bio.terra.externalcreds.models.VisaVerificationDetails) LinkedAccount(bio.terra.externalcreds.models.LinkedAccount) AuditLogger(bio.terra.externalcreds.auditLogging.AuditLogger) OAuth2AuthorizationException(org.springframework.security.oauth2.core.OAuth2AuthorizationException) WebClient(org.springframework.web.reactive.function.client.WebClient) NotFoundException(bio.terra.common.exception.NotFoundException) ArrayList(java.util.ArrayList) SecureRandom(java.security.SecureRandom) ExternalCredsException(bio.terra.externalcreds.ExternalCredsException) OAuth2State(bio.terra.externalcreds.models.OAuth2State) Service(org.springframework.stereotype.Service) Duration(java.time.Duration) Map(java.util.Map) ProviderProperties(bio.terra.externalcreds.config.ProviderProperties) AuditLogEventType(bio.terra.externalcreds.auditLogging.AuditLogEventType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) Mono(reactor.core.publisher.Mono) CannotDecodeOAuth2State(bio.terra.externalcreds.models.CannotDecodeOAuth2State) Instant(java.time.Instant) OAuth2ErrorCodes(org.springframework.security.oauth2.core.OAuth2ErrorCodes) ClientRegistration(org.springframework.security.oauth2.client.registration.ClientRegistration) ExternalCredsConfig(bio.terra.externalcreds.config.ExternalCredsConfig) Objects(java.util.Objects) HttpStatus(org.springframework.http.HttpStatus) LinkedAccountWithPassportAndVisas(bio.terra.externalcreds.models.LinkedAccountWithPassportAndVisas) Slf4j(lombok.extern.slf4j.Slf4j) ChronoUnit(java.time.temporal.ChronoUnit) Stream(java.util.stream.Stream) BadRequestException(bio.terra.common.exception.BadRequestException) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) OAuth2RefreshToken(org.springframework.security.oauth2.core.OAuth2RefreshToken) Collections(java.util.Collections) ExternalCredsException(bio.terra.externalcreds.ExternalCredsException) OAuth2RefreshToken(org.springframework.security.oauth2.core.OAuth2RefreshToken)

Example 2 with LinkedAccountWithPassportAndVisas

use of bio.terra.externalcreds.models.LinkedAccountWithPassportAndVisas in project terra-external-credentials-manager by DataBiosphere.

the class ProviderServiceTest method createLinkedAccountWithOldVisa.

private LinkedAccountWithPassportAndVisas createLinkedAccountWithOldVisa(LinkedAccountService linkedAccountService) {
    var visaNeedingVerification = TestUtils.createRandomVisa().withTokenType(TokenTypeEnum.access_token).withLastValidated(new Timestamp(Instant.now().minus(Duration.ofDays(50)).toEpochMilli()));
    var savedLinkedAccountWithPassportAndVisa = linkedAccountService.upsertLinkedAccountWithPassportAndVisas(new LinkedAccountWithPassportAndVisas.Builder().linkedAccount(TestUtils.createRandomLinkedAccount()).passport(TestUtils.createRandomPassport()).visas(List.of(visaNeedingVerification)).build());
    return savedLinkedAccountWithPassportAndVisa;
}
Also used : Timestamp(java.sql.Timestamp) LinkedAccountWithPassportAndVisas(bio.terra.externalcreds.models.LinkedAccountWithPassportAndVisas)

Aggregations

LinkedAccountWithPassportAndVisas (bio.terra.externalcreds.models.LinkedAccountWithPassportAndVisas)2 Timestamp (java.sql.Timestamp)2 BadRequestException (bio.terra.common.exception.BadRequestException)1 NotFoundException (bio.terra.common.exception.NotFoundException)1 ExternalCredsException (bio.terra.externalcreds.ExternalCredsException)1 AuditLogEvent (bio.terra.externalcreds.auditLogging.AuditLogEvent)1 AuditLogEventType (bio.terra.externalcreds.auditLogging.AuditLogEventType)1 AuditLogger (bio.terra.externalcreds.auditLogging.AuditLogger)1 ExternalCredsConfig (bio.terra.externalcreds.config.ExternalCredsConfig)1 ProviderProperties (bio.terra.externalcreds.config.ProviderProperties)1 CannotDecodeOAuth2State (bio.terra.externalcreds.models.CannotDecodeOAuth2State)1 LinkedAccount (bio.terra.externalcreds.models.LinkedAccount)1 OAuth2State (bio.terra.externalcreds.models.OAuth2State)1 VisaVerificationDetails (bio.terra.externalcreds.models.VisaVerificationDetails)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SecureRandom (java.security.SecureRandom)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1