Add Code Here/JAVA/spring sec/serivice/Users/UserDetailsPrincipal.java
<filename>Add Code Here/JAVA/spring sec/serivice/Users/UserDetailsPrincipal.javapackage com.example.informatic_parc.service.Users;

import com.example.informatic_parc.model.Users.Users;
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 UserDetailsPrincipal implements UserDetails {
    private final Users users;
    public UserDetailsPrincipal(Users users){
        this.users= users;
    }
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> roles = new ArrayList<>();
        roles.add(new SimpleGrantedAuthority("ROLE_"+users.getRole().getName()));
        return roles;
    }

    @Override
    public String getPassword() {
        return users.getPassword();
    }

    @Override
    public String getUsername() {
        return users.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;
    }
}
