Selaa lähdekoodia

fix(NET-1540): add cfg to autoclose connections on rac, when logged out (#3130)

only auto-disconnect non-admin users when JWT expires on RAC and RAC_AUTO_DISABLE is set
Aceix 10 kuukautta sitten
vanhempi
commit
ce7c164e09
2 muutettua tiedostoa jossa 6 lisäystä ja 4 poistoa
  1. 3 2
      logic/jwts.go
  2. 3 2
      models/user_mgmt.go

+ 3 - 2
logic/jwts.go

@@ -56,8 +56,9 @@ func CreateJWT(uuid string, macAddress string, network string) (response string,
 func CreateUserJWT(username string, role models.UserRoleID) (response string, err error) {
 	expirationTime := time.Now().Add(servercfg.GetServerConfig().JwtValidityDuration)
 	claims := &models.UserClaims{
-		UserName: username,
-		Role:     role,
+		UserName:       username,
+		Role:           role,
+		RacAutoDisable: servercfg.GetRacAutoDisable() && (role != models.SuperAdminRole && role != models.AdminRole),
 		RegisteredClaims: jwt.RegisteredClaims{
 			Issuer:    "Netmaker",
 			Subject:   fmt.Sprintf("user|%s", username),

+ 3 - 2
models/user_mgmt.go

@@ -177,8 +177,9 @@ type UserAuthParams struct {
 
 // UserClaims - user claims struct
 type UserClaims struct {
-	Role     UserRoleID
-	UserName string
+	Role           UserRoleID
+	UserName       string
+	RacAutoDisable bool
 	jwt.RegisteredClaims
 }