package com.tourguide.security; import com.tourguide.modules.user.domain.ClientType; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import java.util.Collections; import java.util.Arrays; import java.util.List; public class AppUserPrincipal { private final Long userId; private final String username; private final String role; private final ClientType clientType; public AppUserPrincipal(Long userId, String username, String role, ClientType clientType) { this.userId = userId; this.username = username; this.role = role; this.clientType = clientType; } public Long getUserId() { return userId; } public String getUsername() { return username; } public String getRole() { return role; } public ClientType getClientType() { return clientType; } public List getAuthorities() { if (clientType == ClientType.ADMIN && !"ADMIN".equals(role)) { return Arrays.asList( new SimpleGrantedAuthority("ROLE_ADMIN"), new SimpleGrantedAuthority("ROLE_" + role)); } return Collections.singletonList(new SimpleGrantedAuthority("ROLE_" + role)); } }