def get_client_uuid(self, name_or_uuid): if is_uuid(name_or_uuid): return name_or_uuid else: # hostname used for uuid in self.__client: if self.__client[uuid]["name"] == name_or_uuid: return uuid return name_or_uuid
def exists(self, misc, needed=None): """ Check whether the given uuid or dn exists """ json = self.__load() if is_uuid(misc): return misc in json['objects'] else: for uuid in json: for obj in json[uuid]: if "dn" in json[uuid][obj] and json[uuid][obj]["dn"] == misc: return True return False
def exists(self, misc, needed=None): """ Check whether the given uuid or dn exists """ json = self.__load() if is_uuid(misc): return misc in json['objects'] else: for uuid in json: for obj in json[uuid]: if "dn" in json[uuid][obj] and json[uuid][obj][ "dn"] == misc: return True return False
def exists(self, misc): if is_uuid(misc): fltr_tpl = "%s=%%s" % self.uuid_entry fltr = ldap.filter.filter_format(fltr_tpl, [misc]) res = self.con.search_s(self.lh.get_base(), ldap.SCOPE_SUBTREE, fltr, [self.uuid_entry]) else: res = [] try: res = self.con.search_s(misc, ldap.SCOPE_BASE, '(objectClass=*)', [self.uuid_entry]) except ldap.NO_SUCH_OBJECT: pass if not res: return False return len(res) == 1
def get_method_from_user(self, user): """ Get the currently used two-factor authentication method of the given user :param user: User to check :type user: ObjectProxy :return: the two-factor method of the user :rtype: string or None """ if isinstance(user, str): if not is_uuid(user): user = self.__dn_to_uuid(user) elif isinstance(user, ObjectProxy): user = user.uuid if user in self.__settings: if 'otp_secret' in self.__settings[user]: return "otp" elif '_u2f_devices_' in self.__settings[user]: return "u2f" return None
def removeObject(self, user, oid, *args, **kwargs): """ Open object on the agent side and calls its remove method ================= ========================== Parameter Description ================= ========================== oid OID of the object to create args/kwargs Arguments to be used when getting an object instance ================= ========================== ``Return``: True """ # In case of "object" we want to check the lock if oid == 'object': lck = self.__get_lock(args[0]) if lck: raise Exception(C.make_error("OBJECT_LOCKED", object=args[0], user=lck['user'], when=lck['created'].strftime("%Y-%m-%d (%H:%M:%S)") )) # Use oid to find the object type obj_type = self.__get_object_type(oid) # Make object instance and store it kwargs['user'] = user try: obj = obj_type(*args, **kwargs) obj.remove() except ProxyException as e: if e.status == 404 and is_uuid(args[0]): PluginRegistry.getInstance("ObjectIndex").remove_by_uuid(args[0]) return True else: raise e return True
def __init__(self, _id, what=None, user=None, session_id=None): self.__env = Environment.getInstance() self.__log = getLogger(__name__) self.__factory = ObjectFactory.getInstance() self.__base = None self.__extensions = {} self.__initial_extension_state = {} self.__retractions = {} self.__attribute_map = {} self.__method_map = {} self.__current_user = user self.__current_session_id = session_id self.__acl_resolver = PluginRegistry.getInstance("ACLResolver") self.__attribute_type_map = {} self.__attributes = [] self.__method_type_map = {} self.__property_map = {} self.__foreign_attrs = [] self.__all_method_names = [] # Do we have a uuid when opening? dn_or_base = _id if is_uuid(_id): index = PluginRegistry.getInstance("ObjectIndex") res = index.search({'uuid': _id}, {'dn': 1}) if len(res) == 1: dn_or_base = res[0]['dn'] else: raise ProxyException(C.make_error('OBJECT_NOT_FOUND', id=_id)) # Load available object types object_types = self.__factory.getObjectTypes() base_mode = "update" base, extensions = self.__factory.identifyObject(dn_or_base) if what: if what not in object_types: raise ProxyException(C.make_error('OBJECT_UNKNOWN_TYPE', type=type)) start_dn = dn_or_base dn_or_base = self.find_dn_for_object(what, base, start_dn, []) if base else dn_or_base self.create_missing_containers(dn_or_base, start_dn, base) base = what base_mode = "create" extensions = [] if not base: raise ProxyException(C.make_error('OBJECT_NOT_FOUND', id=dn_or_base)) # Get available extensions self.__log.debug("loading %s base object for %s" % (base, dn_or_base)) all_extensions = object_types[base]['extended_by'] # Load base object and extensions self.__base = self.__factory.getObject(base, dn_or_base, mode=base_mode) self.__base._owner = self.__current_user self.__base._session_id = self.__current_session_id self.__base.parent = self self.__base_type = base self.__base_mode = base_mode for extension in extensions: self.__log.debug("loading %s extension for %s" % (extension, dn_or_base)) self.__extensions[extension] = self.__factory.getObject(extension, self.__base.uuid) self.__extensions[extension].dn = self.__base.dn self.__extensions[extension].parent = self self.__extensions[extension]._owner = self.__current_user self.__extensions[extension]._session_id = self.__current_session_id self.__initial_extension_state[extension] = True for extension in all_extensions: if extension not in self.__extensions: self.__extensions[extension] = None self.__initial_extension_state[extension] = False # Collect all method names (also not available due to deactivated extension) for obj in [base] + all_extensions: self.__all_method_names = self.__all_method_names + self.__factory.getObjectMethods(obj) # Generate method mapping for obj in [base] + extensions: for method in object_types[obj]['methods']: if obj == self.__base.__class__.__name__: self.__method_map[method] = getattr(self.__base, method) self.__method_type_map[method] = self.__base_type continue if obj in self.__extensions: self.__method_map[method] = getattr(self.__extensions[obj], method) self.__method_type_map[method] = obj for ext in all_extensions: if self.__extensions[ext]: props = self.__extensions[ext].getProperties() else: props = self.__factory.getObjectProperties(ext) # Generate read and write mapping for attributes self.__attribute_map = self.__factory.get_attributes_by_object(self.__base_type) # Generate attribute to object-type mapping for attr in [n for n, o in self.__base.getProperties().items() if not o['foreign']]: self.__attributes.append(attr) self.__property_map = self.__base.getProperties() for ext in all_extensions: if self.__extensions[ext]: props = self.__extensions[ext].getProperties() else: props = self.__factory.getObjectProperties(ext) for attr in props: if not props[attr]['foreign']: self.__attributes.append(attr) self.__property_map[attr] = props[attr] else: # Remember foreign properties to be able to the correct # values to them after we have finished building up all classes self.__foreign_attrs.append((attr, ext)) # Get attribute to object-type mapping self.__attribute_type_map = self.__factory.getAttributeTypeMap(self.__base_type) self.uuid = self.__base.uuid self.dn = self.__base.dn self.populate_to_foreign_properties()