diff --git a/src/main/java/bio/overture/ego/controller/AuthController.java b/src/main/java/bio/overture/ego/controller/AuthController.java index 006834b0..c8b463a8 100644 --- a/src/main/java/bio/overture/ego/controller/AuthController.java +++ b/src/main/java/bio/overture/ego/controller/AuthController.java @@ -37,6 +37,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; import java.util.Objects; +import java.util.Optional; import lombok.NonNull; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -134,6 +135,13 @@ public ResponseEntity user( user.getAccessToken()) : null; + Optional providerType = ProviderType + .findIfExist(authentication.getAuthorizedClientRegistrationId()); + + if(user.getClaim(GA4GH_PASSPORT_SCOPE) != null && providerType.isEmpty()){ + providerType = Optional.of(ProviderType.PASSPORT); + } + String token = tokenService.generateUserToken( IDToken.builder() @@ -141,9 +149,8 @@ public ResponseEntity user( .email(user.getEmail()) .familyName(user.getFamilyName()) .givenName(user.getGivenName()) - .providerType( - ProviderType.resolveProviderType( - authentication.getAuthorizedClientRegistrationId())) + .providerType(providerType.get()) + .providerIssuerUri(user.getIssuer().toString()) .build(), passportJwtToken, authentication.getAuthorizedClientRegistrationId()); diff --git a/src/main/java/bio/overture/ego/model/dto/CreateUserRequest.java b/src/main/java/bio/overture/ego/model/dto/CreateUserRequest.java index f0ffc790..1c88eb92 100644 --- a/src/main/java/bio/overture/ego/model/dto/CreateUserRequest.java +++ b/src/main/java/bio/overture/ego/model/dto/CreateUserRequest.java @@ -47,4 +47,6 @@ public class CreateUserRequest { @NotNull ProviderType providerType; @NotNull String providerSubjectId; + + private String providerIssuerUri; } diff --git a/src/main/java/bio/overture/ego/model/entity/User.java b/src/main/java/bio/overture/ego/model/entity/User.java index 88f5d7fe..9af3163a 100644 --- a/src/main/java/bio/overture/ego/model/entity/User.java +++ b/src/main/java/bio/overture/ego/model/entity/User.java @@ -148,6 +148,10 @@ public class User implements PolicyOwner, Identifiable { @Column(name = SqlFields.PROVIDERSUBJECTID, nullable = false) private String providerSubjectId; + @JsonView({Views.JWTAccessToken.class, Views.REST.class}) + @Column(name = SqlFields.PROVIDERISSUERURI) + private String providerIssuerUri; + @JsonIgnore @OneToMany( mappedBy = JavaFields.OWNER, diff --git a/src/main/java/bio/overture/ego/model/enums/ProviderType.java b/src/main/java/bio/overture/ego/model/enums/ProviderType.java index e4b912b7..fc6f531a 100644 --- a/src/main/java/bio/overture/ego/model/enums/ProviderType.java +++ b/src/main/java/bio/overture/ego/model/enums/ProviderType.java @@ -8,6 +8,8 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; +import java.util.Optional; + @RequiredArgsConstructor public enum ProviderType { GOOGLE, @@ -53,6 +55,12 @@ public static ProviderType resolveProviderType(@NonNull String providerType) { providerType, COMMA.join(values())))); } + public static Optional findIfExist(@NonNull String providerType) { + return stream(values()) + .filter(x -> x.toString().equalsIgnoreCase(providerType)) + .findFirst(); + } + @Override public String toString() { return this.name(); diff --git a/src/main/java/bio/overture/ego/model/enums/SqlFields.java b/src/main/java/bio/overture/ego/model/enums/SqlFields.java index dfdf0a5f..a00a6820 100644 --- a/src/main/java/bio/overture/ego/model/enums/SqlFields.java +++ b/src/main/java/bio/overture/ego/model/enums/SqlFields.java @@ -36,6 +36,7 @@ public class SqlFields { public static final String USER_ID = "user_id"; public static final String PROVIDERTYPE = "providertype"; public static final String PROVIDERSUBJECTID = "providersubjectid"; + public static final String PROVIDERISSUERURI = "providerissueruri"; public static final String INITIALIZED = "initialized"; public static final String ERRORREDIRECTURI = "errorredirecturi"; public static final String SOURCE = "source"; diff --git a/src/main/java/bio/overture/ego/security/CustomOidc2UserInfoService.java b/src/main/java/bio/overture/ego/security/CustomOidc2UserInfoService.java index 9ebd55f8..c7a405cd 100644 --- a/src/main/java/bio/overture/ego/security/CustomOidc2UserInfoService.java +++ b/src/main/java/bio/overture/ego/security/CustomOidc2UserInfoService.java @@ -36,9 +36,9 @@ public OidcUser loadUser(OidcUserRequest oAuth2UserRequest) throws OAuth2Authent OidcUser oidcUser = super.loadUser(oAuth2UserRequest); try { String provider = oAuth2UserRequest.getClientRegistration().getRegistrationId(); - val idName = ProviderType.getIdAccessor(ProviderType.resolveProviderType(provider)); if (provider.equalsIgnoreCase(ProviderType.ORCID.toString())) { val info = getOrcidUserInfo(oidcUser, oAuth2UserRequest); + val idName = ProviderType.getIdAccessor(ProviderType.resolveProviderType(provider)); return CustomOAuth2User.builder() .oauth2User(new DefaultOAuth2User(oidcUser.getAuthorities(), info, idName)) .subjectId(info.get(idName).toString()) diff --git a/src/main/java/bio/overture/ego/service/UserService.java b/src/main/java/bio/overture/ego/service/UserService.java index 894a394a..c6141bc9 100644 --- a/src/main/java/bio/overture/ego/service/UserService.java +++ b/src/main/java/bio/overture/ego/service/UserService.java @@ -175,6 +175,7 @@ public User createFromIDToken(IDToken idToken) { .type(userDefaultsConfig.getDefaultUserType()) .providerType(idToken.getProviderType()) .providerSubjectId(idToken.getProviderSubjectId()) + .providerIssuerUri(idToken.getProviderIssuerUri()) .build()); } diff --git a/src/main/java/bio/overture/ego/token/IDToken.java b/src/main/java/bio/overture/ego/token/IDToken.java index 8a0eca68..92ce4368 100644 --- a/src/main/java/bio/overture/ego/token/IDToken.java +++ b/src/main/java/bio/overture/ego/token/IDToken.java @@ -43,4 +43,6 @@ public class IDToken { @JsonProperty("provider_subject_id") @NonNull String providerSubjectId; + + private String providerIssuerUri; } diff --git a/src/main/resources/flyway/sql/V1_25__add_provider_issuer_uri.sql b/src/main/resources/flyway/sql/V1_25__add_provider_issuer_uri.sql new file mode 100644 index 00000000..b9a55f3b --- /dev/null +++ b/src/main/resources/flyway/sql/V1_25__add_provider_issuer_uri.sql @@ -0,0 +1 @@ +ALTER TABLE egouser ADD COLUMN providerissueruri VARCHAR(255); \ No newline at end of file