All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.atlassian.connect.spring.internal.jpa.AtlassianConnectHostUserAuditorAware Maven / Gradle / Ivy

There is a newer version: 5.1.4
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy