11""" Module that holds DISET Authorization class for services
22"""
3+ from cachetools import TTLCache
4+
35from DIRAC .ConfigurationSystem .Client .Config import gConfig
46from DIRAC .ConfigurationSystem .Client .Helpers import Registry
57from DIRAC .Core .Security import Properties
@@ -26,6 +28,8 @@ def __init__(self, authSection):
2628 :param authSection: Section containing the authorization rules
2729 """
2830 self .authSection = authSection
31+ self ._cache_getUsersInGroup = TTLCache (maxsize = 1000 , ttl = 60 )
32+ self ._cache_getUsernameForDN = TTLCache (maxsize = 1000 , ttl = 60 )
2933
3034 def authQuery (self , methodQuery , credDict , defaultProperties = False ):
3135 """
@@ -257,10 +261,18 @@ def getUsername(self, credDict):
257261 return False
258262 credDict [self .KW_GROUP ] = result ["Value" ]
259263 credDict [self .KW_PROPERTIES ] = Registry .getPropertiesForGroup (credDict [self .KW_GROUP ], [])
260- usersInGroup = Registry .getUsersInGroup (credDict [self .KW_GROUP ], [])
264+
265+ usersInGroup = self ._cache_getUsersInGroup .get (credDict [self .KW_GROUP ])
266+ if usersInGroup is None :
267+ usersInGroup = Registry .getUsersInGroup (credDict [self .KW_GROUP ], [])
268+ self ._cache_getUsersInGroup [credDict [self .KW_GROUP ]] = usersInGroup
261269 if not usersInGroup :
262270 return False
263- retVal = Registry .getUsernameForDN (credDict [self .KW_DN ], usersInGroup )
271+
272+ retVal = self ._cache_getUsernameForDN .get (credDict [self .KW_DN ])
273+ if retVal is None :
274+ retVal = Registry .getUsernameForDN (credDict [self .KW_DN ], usersInGroup )
275+ self ._cache_getUsernameForDN [credDict [self .KW_DN ]] = retVal
264276 if retVal ["OK" ]:
265277 credDict [self .KW_USERNAME ] = retVal ["Value" ]
266278 return True
0 commit comments