package com.ziffit.autoconfigure.spring.security;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

public class SecurityUtils {

    private SecurityUtils() {
    }

    /**
     * Checks whether the current user is authenticated.
     *
     * @return <code>true</code> if the user is authenticated, <code>false</code> otherwise
     */
    public static boolean isCurrentUserAuthenticated() {
        SecurityContext securityContext = SecurityContextHolder.getContext();
        Authentication authentication = securityContext.getAuthentication();
        if (authentication != null) {
            return authentication.getAuthorities().stream()
                .noneMatch(grantedAuthority -> SecurityConstants.ROLE_ANONYMOUS.equals(grantedAuthority.getAuthority()));
        } else {
            return false;
        }
    }

    /**
     * Converts a list of <code>String</code> roles into {@link GrantedAuthority} objects.
     *
     * @param roles A collection of security roles, in the format of <code>ROLE_ANONYMOUS</code>.
     * @return A collection of {@link SimpleGrantedAuthority} objects.
     */
    public static Collection<? extends GrantedAuthority> convertToGrantedAuthorities(List<String> roles) {
        return roles.stream()
            .map(SimpleGrantedAuthority::new)
            .collect(Collectors.toList());
    }
}

@@ -399,24 +399,54 @@
 Collection;%0A
+import java.util.Collections;%0A
 import java.
@@ -1610,24 +1610,118 @@
 g%3E roles) %7B%0A
+        if (roles == null) %7B%0A            return Collections.emptyList();%0A        %7D else %7B%0A    
         retu
@@ -1730,32 +1730,36 @@
  roles.stream()%0A
+    
             .map
@@ -1800,16 +1800,20 @@
         
+    
 .collect
@@ -1831,20 +1831,30 @@
 .toList());%0A
+        %7D%0A
     %7D%0A%7D%0A

Fix a NullPointerException.