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 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
    public Optional getCurrentAuditor() {
        Optional optionalUserAccountId = Optional.empty();
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null) {
            Object principal = authentication.getPrincipal();
            if (principal instanceof AtlassianHostUser) {
                AtlassianHostUser hostUser = (AtlassianHostUser) principal;
                optionalUserAccountId = hostUser.getUserAccountId();
            }
        }
        return optionalUserAccountId;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy