summaryrefslogtreecommitdiff
path: root/spring-boot/09-spring-security-db-authentication/src/main/java/com/example/spring/user/entity/User.java
blob: a8ec6d2004d535f3d15a1f20a4665afe26e47792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.example.spring.user.entity;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

/*
    @Table - Used to set the database table name explicitely.
*/
@Entity
@Table(name="user_account")
public class User implements UserDetails {

    /*
        GenerationType.IDENTITY - Auto generate value based on database's native auto increment feature 
    */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(unique = true)
    private String username;

    private String password;

    /*
        Roles and permissions can be represented by GrantedAuthority instances.
    */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return new ArrayList<>();
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

}