Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AYS-455 | Use User ID Instead of emailAddress in User Tracking Fields #394

Merged
merged 7 commits into from
Nov 1, 2024
8 changes: 4 additions & 4 deletions src/main/java/org/ays/common/model/entity/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
*
* <p>
* This class utilizes Spring Security's {@link SecurityContextHolder} to fetch the currently
* authenticated user's email address and sets it as the {@code createdUser} or {@code updatedUser}.
* authenticated user's id and sets it as the {@code createdUser} or {@code updatedUser}.
* It also sets the timestamps {@code createdAt} and {@code updatedAt}.
* </p>
*
* <pre>
* Note: Ensure that Spring Security's context is properly configured to use JWTs and that the
* principal contains a claim for the user's email address.
* principal contains a claim for the user's id.
* </pre>
*
* @see SecurityContextHolder
Expand All @@ -69,7 +69,7 @@ public void prePersist() {
.map(Authentication::getPrincipal)
.filter(user -> !"anonymousUser".equals(user))
.map(Jwt.class::cast)
.map(jwt -> jwt.getClaim(AysTokenClaims.USER_EMAIL_ADDRESS.getValue()).toString())
.map(jwt -> jwt.getClaim(AysTokenClaims.USER_ID.getValue()).toString())
.orElse("AYS");
this.createdAt = Optional.ofNullable(this.createdAt)
.orElse(LocalDateTime.now());
Expand All @@ -88,7 +88,7 @@ public void preUpdate() {
.map(Authentication::getPrincipal)
.filter(user -> !"anonymousUser".equals(user))
.map(Jwt.class::cast)
.map(jwt -> jwt.getClaim(AysTokenClaims.USER_EMAIL_ADDRESS.getValue()).toString())
.map(jwt -> jwt.getClaim(AysTokenClaims.USER_ID.getValue()).toString())
.orElse("AYS");
this.updatedAt = LocalDateTime.now();
}
agitrubard marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading