Ignore:
Timestamp:
02/03/23 23:11:04 (23 months ago)
Author:
DenicaKj <dkorvezir@…>
Branches:
master
Children:
eb226b2
Parents:
1b248e4
Message:

Spring Security

Location:
src/main/java/com/example/moviezone/model
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/moviezone/model/Customer.java

    r1b248e4 rac25203  
    77import lombok.Setter;
    88import lombok.ToString;
     9import org.springframework.security.core.GrantedAuthority;
     10
     11import java.util.Collection;
     12import java.util.Collections;
    913
    1014@Entity
     
    1923    Integer points;
    2024
     25    @Override
     26    public Collection<? extends GrantedAuthority> getAuthorities() {
     27        return Collections.singletonList(Role.ROLE_ADMIN);
     28    }
    2129
    2230}
  • src/main/java/com/example/moviezone/model/User.java

    r1b248e4 rac25203  
    55import lombok.Setter;
    66import lombok.ToString;
     7import org.springframework.security.core.GrantedAuthority;
     8import org.springframework.security.core.userdetails.UserDetails;
    79
     10import javax.management.relation.Role;
    811import java.time.LocalDateTime;
     12import java.util.Collection;
    913
    1014@Entity
     
    1418@Table(name = "users")
    1519@Inheritance(strategy = InheritanceType.JOINED)
    16 public class User {
     20public class User implements UserDetails {
    1721
    1822    @Id
     
    2428    String address;
    2529    String contact_number;
     30    String username;
    2631    LocalDateTime date_created;
    2732
     33    private boolean isAccountNonExpired = true;
     34    private boolean isAccountNonLocked = true;
     35    private boolean isCredentialsNonExpired = true;
     36    private boolean isEnabled = true;
    2837
    29     public User(Integer id_user, String password, String first_name, String last_name, String address, String contact_number, LocalDateTime date_created) {
     38    @Enumerated(value = EnumType.STRING)
     39    private Role role;
     40
     41    public User(Integer id_user, String password, String first_name, String last_name, String address, String contact_number, String username, LocalDateTime date_created, Role role) {
    3042        this.id_user = id_user;
    3143        this.password = password;
     
    3446        this.address = address;
    3547        this.contact_number = contact_number;
     48        this.username = username;
    3649        this.date_created = date_created;
     50        this.role = role;
    3751    }
    3852
     
    4054
    4155    }
     56
     57    @Override
     58    public Collection<? extends GrantedAuthority> getAuthorities() {
     59        return null;
     60    }
     61
     62
     63    @Override
     64    public boolean isAccountNonExpired() {
     65        return isAccountNonExpired;
     66    }
     67
     68    @Override
     69    public boolean isAccountNonLocked() {
     70        return isAccountNonLocked;
     71    }
     72
     73    @Override
     74    public boolean isCredentialsNonExpired() {
     75        return isCredentialsNonExpired;
     76    }
     77
     78    @Override
     79    public boolean isEnabled() {
     80        return isEnabled;
     81    }
     82
    4283}
  • src/main/java/com/example/moviezone/model/Worker.java

    r1b248e4 rac25203  
    55import lombok.Setter;
    66import lombok.ToString;
     7import org.springframework.security.core.GrantedAuthority;
     8
     9import java.util.Collection;
     10import java.util.Collections;
    711
    812@Entity
     
    2125    @ManyToOne()
    2226    Cinema cinema;
     27    @Override
     28    public Collection<? extends GrantedAuthority> getAuthorities() {
     29        return Collections.singletonList(Role.ROLE_ADMIN);
     30    }
    2331
    2432}
Note: See TracChangeset for help on using the changeset viewer.