Browse Source

Adding Model objects

main
ddangelorb 3 years ago
parent
commit
4b5e239498
  1. 1
      db/sys_config.sql
  2. 11
      src/main/java/org/waterproofingdata/wpdauth/model/Roles.java
  3. 56
      src/main/java/org/waterproofingdata/wpdauth/model/Users.java

1
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 $$;

11
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();
}
}

56
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> roles;
}
Loading…
Cancel
Save