68 lines
1.3 KiB
Java
68 lines
1.3 KiB
Java
package com.baeldung.security;
|
|
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
|
|
import com.baeldung.models.AppUser;
|
|
|
|
public class AppUserPrincipal implements UserDetails {
|
|
|
|
private final AppUser user;
|
|
|
|
//
|
|
|
|
public AppUserPrincipal(AppUser user) {
|
|
this.user = user;
|
|
}
|
|
|
|
//
|
|
|
|
@Override
|
|
public String getUsername() {
|
|
return user.getUsername();
|
|
}
|
|
|
|
@Override
|
|
public String getPassword() {
|
|
return user.getPassword();
|
|
}
|
|
|
|
@Override
|
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
|
final List<GrantedAuthority> authorities = Collections.singletonList(new SimpleGrantedAuthority("User"));
|
|
return authorities;
|
|
}
|
|
|
|
@Override
|
|
public boolean isAccountNonExpired() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean isAccountNonLocked() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean isCredentialsNonExpired() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean isEnabled() {
|
|
return true;
|
|
}
|
|
|
|
//
|
|
|
|
public AppUser getAppUser() {
|
|
return user;
|
|
}
|
|
|
|
}
|