user_mgmt.go 3.8 KB

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