Title / Description
Code package com.example.reactivespringsecurityauthentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import javax.persistence.Entity; import java.util.Arrays; import java.util.Collection; import java.util.stream.Collectors; @Entity public class User implements UserDetails { private Account account; Collection<GrantedAuthority> authorities; public User(Account account, String[] roles) { this.authorities = Arrays.asList(roles) .stream() .map(SimpleGrantedAuthority::new) .collect(Collectors.toList()); this.account = account; } @Override public Collection<? extends GrantedAuthority> getAuthorities() { return authorities; } @Override public String getPassword() { return account.getPassword(); } @Override public String getUsername() { return account.getUsername(); } @Override public boolean isAccountNonExpired() { return account.isActive(); } @Override public boolean isAccountNonLocked() { return account.isActive(); } @Override public boolean isCredentialsNonExpired() { return account.isActive(); } @Override public boolean isEnabled() { return account.isActive(); } }
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code