user_mgmt.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package models
  2. import (
  3. "time"
  4. jwt "github.com/golang-jwt/jwt/v4"
  5. )
  6. type NetworkID string
  7. type RsrcType string
  8. type RsrcID string
  9. type UserRole string
  10. type UserGroupID string
  11. func (r RsrcType) String() string {
  12. return string(r)
  13. }
  14. const (
  15. HostRsrc RsrcType = "hosts"
  16. RelayRsrc RsrcType = "relays"
  17. RemoteAccessGwRsrc RsrcType = "remote_access_gw"
  18. ExtClientsRsrc RsrcType = "extclients"
  19. InetGwRsrc RsrcType = "inet_gw"
  20. EgressGwRsrc RsrcType = "egress"
  21. NetworkRsrc RsrcType = "networks"
  22. EnrollmentKeysRsrc RsrcType = "enrollment_key"
  23. UserRsrc RsrcType = "users"
  24. AclRsrc RsrcType = "acl"
  25. DnsRsrc RsrcType = "dns"
  26. FailOverRsrc RsrcType = "fail_over"
  27. )
  28. const (
  29. AllHostRsrcID RsrcID = "all_host"
  30. AllRelayRsrcID RsrcID = "all_relay"
  31. AllRemoteAccessGwRsrcID RsrcID = "all_remote_access_gw"
  32. AllExtClientsRsrc RsrcType = "all_extclients"
  33. AllInetGwRsrcID RsrcID = "all_inet_gw"
  34. AllEgressGwRsrcID RsrcID = "all_egress"
  35. AllNetworkRsrcID RsrcID = "all_network"
  36. AllEnrollmentKeysRsrcID RsrcID = "all_enrollment_key"
  37. AllUserRsrcID RsrcID = "all_user"
  38. AllDnsRsrcID RsrcID = "all_dns"
  39. AllFailOverRsrc RsrcID = "all_fail_over"
  40. )
  41. // Pre-Defined User Roles
  42. const (
  43. SuperAdminRole UserRole = "super_admin"
  44. AdminRole UserRole = "admin"
  45. NetworkAdmin UserRole = "network_admin"
  46. NetworkUser UserRole = "network_user"
  47. )
  48. func (r UserRole) String() string {
  49. return string(r)
  50. }
  51. func (g UserGroupID) String() string {
  52. return string(g)
  53. }
  54. type RsrcPermissionScope struct {
  55. Create bool `json:"create"`
  56. Read bool `json:"read"`
  57. Update bool `json:"update"`
  58. Delete bool `json:"delete"`
  59. VPNAccess bool `json:"vpn_access"`
  60. }
  61. type UserRolePermissionTemplate struct {
  62. ID UserRole `json:"id"`
  63. Default bool `json:"default"`
  64. DenyDashboardAccess bool `json:"deny_dashboard_access"`
  65. FullAccess bool `json:"full_access"`
  66. IsNetworkRole bool `json:"network_role"`
  67. NetworkLevelAccess map[RsrcType]map[RsrcID]RsrcPermissionScope `json:"network_level_access"`
  68. GlobalLevelAccess map[RsrcType]map[RsrcID]RsrcPermissionScope `json:"global_level_access"`
  69. }
  70. type UserGroup struct {
  71. ID string `json:"id"`
  72. NetworkRoles map[NetworkID]UserRole `json:"network_roles"`
  73. MetaData string `json:"meta_data"`
  74. }
  75. // User struct - struct for Users
  76. type User struct {
  77. UserName string `json:"username" bson:"username" validate:"min=3,max=40,in_charset|email"`
  78. Password string `json:"password" bson:"password" validate:"required,min=5"`
  79. IsAdmin bool `json:"isadmin" bson:"isadmin"`
  80. IsSuperAdmin bool `json:"issuperadmin"`
  81. RemoteGwIDs map[string]struct{} `json:"remote_gw_ids"`
  82. UserGroup UserGroupID `json:"user_groups"`
  83. PlatformRoleID UserRole `json:"platform_role_id"`
  84. NetworkRoles map[NetworkID]UserRole `json:"network_roles"`
  85. LastLoginTime time.Time `json:"last_login_time"`
  86. }
  87. // ReturnUser - return user struct
  88. type ReturnUser struct {
  89. UserName string `json:"username"`
  90. IsAdmin bool `json:"isadmin"`
  91. IsSuperAdmin bool `json:"issuperadmin"`
  92. RemoteGwIDs map[string]struct{} `json:"remote_gw_ids"`
  93. UserGroups map[UserGroupID]struct{} `json:"user_groups"`
  94. PlatformRoleID string `json:"platform_role_id"`
  95. NetworkRoles map[NetworkID]UserRole `json:"network_roles"`
  96. LastLoginTime time.Time `json:"last_login_time"`
  97. }
  98. // UserAuthParams - user auth params struct
  99. type UserAuthParams struct {
  100. UserName string `json:"username"`
  101. Password string `json:"password"`
  102. }
  103. // UserClaims - user claims struct
  104. type UserClaims struct {
  105. IsAdmin bool
  106. IsSuperAdmin bool
  107. UserName string
  108. jwt.RegisteredClaims
  109. }