updates on batch logic
This commit is contained in:
21
src/main/java/zw/qantra/tm/utils/SecurityUtils.java
Normal file
21
src/main/java/zw/qantra/tm/utils/SecurityUtils.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package zw.qantra.tm.utils;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
public class SecurityUtils {
|
||||
|
||||
public static String getCurrentUsername() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication != null && authentication.isAuthenticated()) {
|
||||
Object principal = authentication.getPrincipal();
|
||||
if (principal instanceof UserDetails) {
|
||||
return ((UserDetails) principal).getUsername();
|
||||
} else {
|
||||
return principal.toString(); // For cases where principal might be a String
|
||||
}
|
||||
}
|
||||
return null; // Or throw an exception if the user is expected to be logged in
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user