package com.juick.server.security.entities; import com.juick.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; /** * Created by aalexeev on 11/21/16. */ public class JuickUser implements UserDetails { public static final GrantedAuthority ROLE_USER = new SimpleGrantedAuthority("ROLE_USER"); public static final Collection USER_AUTHORITY = Collections.singletonList(ROLE_USER); private final com.juick.User user; public JuickUser(com.juick.User user) { this.user = user; } @Override public Collection getAuthorities() { return USER_AUTHORITY; } @Override public String getPassword() { return null; } @Override public String getUsername() { return user.getName(); } @Override public boolean isAccountNonExpired() { return true; } @Override public boolean isAccountNonLocked() { return false; } @Override public boolean isCredentialsNonExpired() { return true; } @Override public boolean isEnabled() { return !user.isBanned(); } public User getUser() { return user; } }