Skip to content

Commit

Permalink
add column providerissueruri
Browse files Browse the repository at this point in the history
  • Loading branch information
leoraba committed Jun 15, 2023
1 parent b2ccb87 commit 002742f
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/main/java/bio/overture/ego/controller/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,16 +135,22 @@ public ResponseEntity<String> user(
user.getAccessToken()) :
null;

Optional<ProviderType> 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()
.providerSubjectId(user.getSubjectId())
.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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ public class CreateUserRequest {
@NotNull ProviderType providerType;

@NotNull String providerSubjectId;

private String providerIssuerUri;
}
4 changes: 4 additions & 0 deletions src/main/java/bio/overture/ego/model/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ public class User implements PolicyOwner, Identifiable<UUID> {
@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,
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/bio/overture/ego/model/enums/ProviderType.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import java.util.Optional;

@RequiredArgsConstructor
public enum ProviderType {
GOOGLE,
Expand Down Expand Up @@ -53,6 +55,12 @@ public static ProviderType resolveProviderType(@NonNull String providerType) {
providerType, COMMA.join(values()))));
}

public static Optional<ProviderType> findIfExist(@NonNull String providerType) {
return stream(values())
.filter(x -> x.toString().equalsIgnoreCase(providerType))
.findFirst();
}

@Override
public String toString() {
return this.name();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/bio/overture/ego/model/enums/SqlFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions src/main/java/bio/overture/ego/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public User createFromIDToken(IDToken idToken) {
.type(userDefaultsConfig.getDefaultUserType())
.providerType(idToken.getProviderType())
.providerSubjectId(idToken.getProviderSubjectId())
.providerIssuerUri(idToken.getProviderIssuerUri())
.build());
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/bio/overture/ego/token/IDToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ public class IDToken {
@JsonProperty("provider_subject_id")
@NonNull
String providerSubjectId;

private String providerIssuerUri;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE egouser ADD COLUMN providerissueruri VARCHAR(255);

0 comments on commit 002742f

Please sign in to comment.