com.atlassian.connect.spring.internal.jpa.AtlassianConnectHostUserAuditorAware Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of atlassian-connect-spring-boot-jpa-starter Show documentation
Show all versions of atlassian-connect-spring-boot-jpa-starter Show documentation
Provides JPA support and migrations for Atlassian Connect Spring Boot add-ons
package com.atlassian.connect.spring.internal.jpa;
import com.atlassian.connect.spring.AtlassianHostUser;
import jakarta.annotation.Nonnull;
import org.springframework.data.domain.AuditorAware;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
public class AtlassianConnectHostUserAuditorAware implements AuditorAware {
@Override
@Nonnull
public Optional getCurrentAuditor() {
Optional optionalUserAccountId = Optional.empty();
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null) {
Object principal = authentication.getPrincipal();
if (principal instanceof AtlassianHostUser hostUser) {
optionalUserAccountId = hostUser.getUserAccountId();
}
}
return optionalUserAccountId;
}
}