// Path: src/main/java/org/andidev/applicationname/entity/User.java
// @Entity
// @NoArgsConstructor(access = PROTECTED)
// @RequiredArgsConstructor
// @Setter
// @Getter
// public class User extends IdEntity implements UserDetails, Serializable {
// 
//     @Column(unique = true)
//     @NonNull
//     private String username;
//     @NonNull
//     private String password;
//     private String firstName;
//     private String lastName;
//     private String email;
//     private boolean accountNonExpired;
//     private boolean accountNonLocked;
//     private boolean credentialsNonExpired;
//     private boolean enabled;
//     private Period automaticLogoutTime;
//     private Locale locale;
//     private DateTimeZone timeZone;
//     private String dateFormat = "yyyy/MM/dd";
//     private String timeFormat = "HH.mm";
//     @ElementCollection(targetClass = Role.class, fetch = EAGER)
//     @Enumerated(STRING)
//     private Set<Role> userRoles = EnumSet.noneOf(Role.class);
//     @ManyToMany(mappedBy = "users", fetch = EAGER)
//     private Set<Group> groups = new HashSet();
//     @OneToMany(fetch = EAGER)
//     private Set<PreferenceValue> preferenceValues = new HashSet();
// 
//     public Set<Role> getRoles() {
//         Set<Role> roles = EnumSet.noneOf(Role.class);
//         roles.addAll(getUserRoles());
//         roles.addAll(getGroupRoles());
//         return roles;
//     }
// 
//     private Set<Role> getGroupRoles() {
//         Set<Role> roles = EnumSet.noneOf(Role.class);
//         for (Group group : getGroups()) {
//             roles.addAll(group.getGroupRoles());
//         }
//         return roles;
//     }
// 
//     @Override
//     public Collection<? extends GrantedAuthority> getAuthorities() {
//         Set<GrantedAuthority> grantedAuthorities = new LinkedHashSet<>();
//         for (Role role : getRoles()) {
//             grantedAuthorities.add(new SimpleGrantedAuthority(role.name()));
//         }
//         return grantedAuthorities;
//     }
// }


import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.andidev.applicationname.entity.User;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
package org.andidev.applicationname.util;


public class ApplicationUtils {

    public static User getUser() {
        // Check authentication exists
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication == null) {
            return null;
        }

        // Get user
        Object principal = authentication.getPrincipal();
// Path: src/main/java/org/andidev/applicationname/entity/User.java
// @Entity
// @NoArgsConstructor(access = PROTECTED)
// @RequiredArgsConstructor
// @Setter
// @Getter
// public class User extends IdEntity implements UserDetails, Serializable {
// 
//     @Column(unique = true)
//     @NonNull
//     private String username;
//     @NonNull
//     private String password;
//     private String firstName;
//     private String lastName;
//     private String email;
//     private boolean accountNonExpired;
//     private boolean accountNonLocked;
//     private boolean credentialsNonExpired;
//     private boolean enabled;
//     private Period automaticLogoutTime;
//     private Locale locale;
//     private DateTimeZone timeZone;
//     private String dateFormat = "yyyy/MM/dd";
//     private String timeFormat = "HH.mm";
//     @ElementCollection(targetClass = Role.class, fetch = EAGER)
//     @Enumerated(STRING)
//     private Set<Role> userRoles = EnumSet.noneOf(Role.class);
//     @ManyToMany(mappedBy = "users", fetch = EAGER)
//     private Set<Group> groups = new HashSet();
//     @OneToMany(fetch = EAGER)
//     private Set<PreferenceValue> preferenceValues = new HashSet();
// 
//     public Set<Role> getRoles() {
//         Set<Role> roles = EnumSet.noneOf(Role.class);
//         roles.addAll(getUserRoles());
//         roles.addAll(getGroupRoles());
//         return roles;
//     }
// 
//     private Set<Role> getGroupRoles() {
//         Set<Role> roles = EnumSet.noneOf(Role.class);
//         for (Group group : getGroups()) {
//             roles.addAll(group.getGroupRoles());
//         }
//         return roles;
//     }
// 
//     @Override
//     public Collection<? extends GrantedAuthority> getAuthorities() {
//         Set<GrantedAuthority> grantedAuthorities = new LinkedHashSet<>();
//         for (Role role : getRoles()) {
//             grantedAuthorities.add(new SimpleGrantedAuthority(role.name()));
//         }
//         return grantedAuthorities;
//     }
// }


// Path: src/main/java/org/andidev/applicationname/util/ApplicationUtils.java
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.andidev.applicationname.entity.User;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

package org.andidev.applicationname.util;


public class ApplicationUtils {

    public static User getUser() {
        // Check authentication exists
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication == null) {
            return null;
        }

        // Get user
        Object principal = authentication.getPrincipal();
        if (principal instanceof User) {