package it.finki.charitable.entities; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import javax.persistence.*; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; @Entity @Table(name = "app_user") public class AppUser implements UserDetails { @SequenceGenerator( name = "user_sequence", sequenceName = "user_sequence", allocationSize = 1 ) @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "user_sequence" ) @Id @Column( name = "id", nullable = false, updatable = false ) private Long id; private String firstName; private String lastName; private String email; private String password; @Enumerated(EnumType.STRING) private UserRole userRole; private Boolean enabled; public AppUser() { } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public void setPassword(String password) { this.password = password; } public UserRole getUserRole() { return userRole; } public void setUserRole(UserRole userRole) { this.userRole = userRole; } public Boolean getEnabled() { return enabled; } public void setEnabled(Boolean enabled) { this.enabled = enabled; } @Override public Collection getAuthorities() { SimpleGrantedAuthority authority = new SimpleGrantedAuthority(userRole.name()); return Collections.singletonList(authority); } @Override public String getPassword() { return password; } @Override public String getUsername() { return email; } @Override public boolean isAccountNonExpired() { return true; } @Override public boolean isAccountNonLocked() { return true; } @Override public boolean isCredentialsNonExpired() { return true; } @Override public boolean isEnabled() { return enabled; } }