Skip to content

Commit

Permalink
Version: Change naming mechanism for editor
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyKarnbach committed Jan 20, 2025
1 parent 40781c2 commit c19062d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void newRevision(Object revisionEntity) {
if (revisionEntity instanceof DamapRevisionEntity) {

final String userId = CDI.current().select(SecurityService.class).get().getUserId();
final String username = CDI.current().select(SecurityService.class).get().getUserName();
final String username = CDI.current().select(SecurityService.class).get().getDisplayName();
((DamapRevisionEntity) revisionEntity).setChangedById(userId);
((DamapRevisionEntity) revisionEntity).setChangedBy(username);
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/damap/base/security/SecurityService.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ public String getUserName() {
return ((OidcJwtCallerPrincipal) principal).getName();
}

public String getDisplayName() {
final Principal principal = securityIdentity.getPrincipal();
if (!(principal instanceof OidcJwtCallerPrincipal)) return null;
String name = ((OidcJwtCallerPrincipal) principal).getClaims().getClaimValue("name").toString();
String firstName = ((OidcJwtCallerPrincipal) principal).getClaims().getClaimValue("given_name").toString();
String lastName = ((OidcJwtCallerPrincipal) principal).getClaims().getClaimValue("family_name").toString();
String email = ((OidcJwtCallerPrincipal) principal).getClaims().getClaimValue("email").toString();

String displayName = name;
if (name == null) {
if (firstName != null && lastName != null) {
displayName = firstName + " " + lastName;
} else {
displayName = email;
}
}

return displayName;
}

/**
* isAdmin.
*
Expand Down

0 comments on commit c19062d

Please sign in to comment.