diff --git a/db/sys_config.sql b/db/sys_config.sql index 6922ba7..99a2c66 100644 --- a/db/sys_config.sql +++ b/db/sys_config.sql @@ -1,5 +1,6 @@ DO $$ BEGIN INSERT INTO roles(name, active) VALUES ('ROLE_ADMIN', 1); + INSERT INTO roles(name, active) VALUES ('ROLE_INSTITUTION', 1); INSERT INTO roles(name, active) VALUES ('ROLE_CLIENT', 1); END $$; diff --git a/src/main/java/org/waterproofingdata/wpdauth/model/Roles.java b/src/main/java/org/waterproofingdata/wpdauth/model/Roles.java new file mode 100644 index 0000000..175d44d --- /dev/null +++ b/src/main/java/org/waterproofingdata/wpdauth/model/Roles.java @@ -0,0 +1,11 @@ +package org.waterproofingdata.wpdauth.model; + +import org.springframework.security.core.GrantedAuthority; + +public enum Roles implements GrantedAuthority { + ROLE_ADMIN, ROLE_INSTITUTION, ROLE_CLIENT; + + public String getAuthority() { + return name(); + } +} diff --git a/src/main/java/org/waterproofingdata/wpdauth/model/Users.java b/src/main/java/org/waterproofingdata/wpdauth/model/Users.java new file mode 100644 index 0000000..71c85a4 --- /dev/null +++ b/src/main/java/org/waterproofingdata/wpdauth/model/Users.java @@ -0,0 +1,56 @@ +package org.waterproofingdata.wpdauth.model; + +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.Column; +import javax.validation.constraints.Size; + +import org.waterproofingdata.wpdauth.model.Roles; + +import javax.persistence.ElementCollection; + +import lombok.Getter; +import lombok.Setter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@Setter +@NoArgsConstructor +public class Users { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Size(min = 4, max = 255, message = "Minimum name length: 4 characters") + @Column(unique = true, nullable = false) + private String username; + + @Size(min = 8, message = "Minimum password length: 8 characters") + @Column(nullable = false) + private String password; + + @Column(unique = true, nullable = true) + private String email; + + @Size(min = 4, max = 255, message = "Minimum firstname length: 4 characters") + @Column(nullable = true) + private String firstname; + + @Size(min = 4, max = 255, message = "Minimum surname length: 4 characters") + @Column(nullable = true) + private String surname; + + private String avatar; + + @Column(nullable = false) + private Integer active; + + @ElementCollection(fetch = FetchType.EAGER) + List roles; +}