package cn.edu.zjnu.acm.judge.util;

import java.util.Optional;
import javax.annotation.Nullable;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtils {

    public static Authentication getAuthentication() {
        return SecurityContextHolder.getContext().getAuthentication();
    }

    @Nullable
    public static String getUserId() {
        return Optional.ofNullable(getAuthentication()).map(Authentication::getName).orElse(null);
    }

}

@@ -91,16 +91,97 @@
 llable;%0A
+import org.springframework.security.authentication.AnonymousAuthenticationToken;%0A
 import o
@@ -573,16 +573,119 @@
 ation())
+%0A                .filter(auth -%3E !AnonymousAuthenticationToken.class.isInstance(auth))%0A                
 .map(Aut
@@ -705,16 +705,33 @@
 getName)
+%0A                
 .orElse(

Fix user id getting