package com.example.fooddeliverysystem.model.userssecurity; import com.example.fooddeliverysystem.model.User; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class UserPrincipal implements UserDetails { private final User user; public UserPrincipal(User user) { this.user = user; } @Override public Collection getAuthorities() { List authorityList = new ArrayList<>(); authorityList.add(new SimpleGrantedAuthority("ROLE_" + this.user.getUserRole().name())); return authorityList; } @Override public String getPassword() { return this.user.getPassword(); } @Override public String getUsername() { return this.user.getUsername(); } @Override public boolean isAccountNonExpired() { return true; } @Override public boolean isAccountNonLocked() { return true; } @Override public boolean isCredentialsNonExpired() { return true; } @Override public boolean isEnabled() { return true; } }