Created
February 6, 2021 16:23
-
-
Save rajj6/6596258c0fa03bbd56492b46696051ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.raj.securingweb; | |
import com.raj.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.Collection; | |
import java.util.Collections; | |
public class UserPrincipal implements UserDetails { | |
private User user; | |
public UserPrincipal(User user) { | |
this.user = user; | |
} | |
@Override | |
public Collection<? extends GrantedAuthority> getAuthorities() { | |
return Collections.singleton(new SimpleGrantedAuthority("USER")); | |
} | |
@Override | |
public String getPassword() { | |
return user.getPassword(); | |
} | |
public String getName() { | |
return user.getName(); | |
} | |
@Override | |
public String getUsername() { | |
return user.getEmail(); | |
} | |
@Override | |
public boolean isAccountNonExpired() { | |
return true; | |
} | |
@Override | |
public boolean isAccountNonLocked() { | |
return true; | |
} | |
@Override | |
public boolean isCredentialsNonExpired() { | |
return true; | |
} | |
@Override | |
public boolean isEnabled() { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment