package org.example.models; import org.springframework.data.neo4j.core.schema.GeneratedValue; import org.springframework.data.neo4j.core.schema.Id; import org.springframework.data.neo4j.core.schema.Node; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import java.util.Arrays; import java.util.Collection; @Node public class User implements UserDetails { @Id @GeneratedValue private Long id; private String name; private String username; private String password; private String roles; public User() { } public Long getId() { return id; } public String getName() { return name; } @Override public String getUsername() { return username; } @Override public String getPassword() { return password; } public String getRoles() { return roles; } public void setName(String name) { this.name = name; } public void setUsername(String username) { this.username = username; } public void setPassword(String password) { this.password = password; } public void setRoles(String roles) { this.roles = roles; } @Override public boolean isAccountNonExpired() { return true; } @Override public boolean isAccountNonLocked() { return true; } @Override public boolean isCredentialsNonExpired() { return true; } @Override public boolean isEnabled() { return true; } @Override public Collection getAuthorities() { return Arrays.stream(roles.split(",")) .map(SimpleGrantedAuthority::new) .toList(); } @Override public String toString() { return "User{" + "name='" + name + '\'' + ", username='" + username + '\'' + ", roles='" + roles + '\'' + '}'; } }