@@ -168,9 +168,14 @@ func (impl UserServiceImpl) SelfRegisterUserIfNotExists(userInfo *bean.UserInfo)
168168 userInfo .Exist = dbUser .Active
169169 userResponse = append (userResponse , & bean.UserInfo {Id : userInfo .Id , EmailId : emailId , Groups : userInfo .Groups , RoleFilters : userInfo .RoleFilters , SuperAdmin : userInfo .SuperAdmin })
170170 }
171+
171172 if len (policies ) > 0 {
173+ //loading policy for safety
174+ casbin2 .LoadPolicy ()
172175 pRes := casbin2 .AddPolicy (policies )
173176 println (pRes )
177+ //loading policy for syncing orchestrator to casbin with newly added policies
178+ casbin2 .LoadPolicy ()
174179 }
175180 err = tx .Commit ()
176181 if err != nil {
@@ -218,6 +223,7 @@ func (impl UserServiceImpl) saveUser(userInfo *bean.UserInfo, emailId string) (*
218223}
219224
220225func (impl UserServiceImpl ) CreateUser (userInfo * bean.UserInfo , token string , managerAuth func (resource , token string , object string ) bool ) ([]* bean.UserInfo , error ) {
226+
221227 var pass []string
222228 var userResponse []* bean.UserInfo
223229 emailIds := strings .Split (userInfo .EmailId , "," )
@@ -317,7 +323,8 @@ func (impl UserServiceImpl) createUserIfNotExists(userInfo *bean.UserInfo, email
317323 return nil , err
318324 }
319325 userInfo .Id = model .Id
320-
326+ //loading policy for safety
327+ casbin2 .LoadPolicy ()
321328 //Starts Role and Mapping
322329 var policies []casbin2.Policy
323330 if userInfo .SuperAdmin == false {
@@ -454,11 +461,12 @@ func (impl UserServiceImpl) createUserIfNotExists(userInfo *bean.UserInfo, email
454461 println (pRes )
455462 }
456463 //Ends
457-
458464 err = tx .Commit ()
459465 if err != nil {
460466 return nil , err
461467 }
468+ //loading policy for syncing orchestrator to casbin with newly added policies
469+ casbin2 .LoadPolicy ()
462470 return userInfo , nil
463471}
464472
@@ -653,7 +661,8 @@ func (impl UserServiceImpl) UpdateUser(userInfo *bean.UserInfo, token string, ma
653661 restrictedGroups := []string {}
654662 rolesChanged := false
655663 groupsModified := false
656-
664+ //loading policy for safety
665+ casbin2 .LoadPolicy ()
657666 if userInfo .SuperAdmin == false {
658667 //Starts Role and Mapping
659668 userRoleModels , err := impl .userAuthRepository .GetUserRoleMappingByUserId (model .Id )
@@ -887,6 +896,8 @@ func (impl UserServiceImpl) UpdateUser(userInfo *bean.UserInfo, token string, ma
887896 if err != nil {
888897 return nil , false , false , nil , err
889898 }
899+ //loading policy for syncing orchestrator to casbin with newly added policies
900+ casbin2 .LoadPolicy ()
890901
891902 return userInfo , rolesChanged , groupsModified , restrictedGroups , nil
892903}
@@ -1320,6 +1331,8 @@ func (impl UserServiceImpl) SyncOrchestratorToCasbin() (bool, error) {
13201331 total := len (roles )
13211332 processed := 0
13221333 impl .logger .Infow ("total roles found for sync" , "len" , total )
1334+ //loading policy for safety
1335+ casbin2 .LoadPolicy ()
13231336 for _ , role := range roles {
13241337 if len (role .Team ) > 0 {
13251338 flag , err := impl .userAuthRepository .SyncOrchestratorToCasbin (role .Team , role .EntityName , role .Environment , nil )
@@ -1333,6 +1346,8 @@ func (impl UserServiceImpl) SyncOrchestratorToCasbin() (bool, error) {
13331346 }
13341347 processed = processed + 1
13351348 }
1349+ //loading policy for syncing orchestrator to casbin with updated policies(if any)
1350+ casbin2 .LoadPolicy ()
13361351 impl .logger .Infow ("total roles processed for sync" , "len" , processed )
13371352 return true , nil
13381353}
0 commit comments