package de.accso.flexinale.security;

import de.accso.flexinale.data.model.Benutzer;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;

public class UserPrincipal implements UserDetails {

    private final Benutzer benutzer;

    public UserPrincipal(Benutzer user) {
        this.benutzer = user;
    }

    @Override
    @SuppressWarnings("Convert2Lambda")
    public Collection<? extends GrantedAuthority> getAuthorities() {
        Collection<GrantedAuthority> authorities = new ArrayList<>();
        GrantedAuthority authority = new GrantedAuthority() {
            @Override
            public String getAuthority() {
                return benutzer.rolle.toString();
            }
        };

        authorities.add(authority);
        return authorities;
    }

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

    @Override
    public String getUsername() {
        return benutzer.login;
    }

}
