"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "privacyidea/lib/realm.py" between
privacyidea-3.5.2.tar.gz and privacyidea-3.6.tar.gz

About: privacyIDEA is a flexible two factor authentication server that can be used to enhance the security of existing applications like local login, VPN, remote access, SSH connections or access to web sites.

realm.py  (privacyidea-3.5.2):realm.py  (privacyidea-3.6)
skipping to change at line 45 skipping to change at line 45
It is independent of any user or token libraries and can be tested standalone It is independent of any user or token libraries and can be tested standalone
in tests/test_lib_realm.py in tests/test_lib_realm.py
''' '''
from ..models import (Realm, from ..models import (Realm,
ResolverRealm, ResolverRealm,
Resolver, db, save_config_timestamp) Resolver, db, save_config_timestamp)
from .log import log_with from .log import log_with
from privacyidea.lib.config import get_config_object from privacyidea.lib.config import get_config_object
import logging import logging
from privacyidea.lib.utils import sanity_name_check, fetch_one_resource from privacyidea.lib.utils import sanity_name_check, fetch_one_resource, is_true
from privacyidea.lib.utils.export import (register_import, register_export)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@log_with(log) @log_with(log)
#@cache.memoize(10) #@cache.memoize(10)
def get_realms(realmname=""): def get_realms(realmname=None):
''' '''
either return all defined realms or a specific realm either return all defined realms or a specific realm
:param realmname: the realm, that is of interestet, if =="" :param realmname: the realm, that is of interestet, if ==""
all realms are returned all realms are returned
:type realmname: string :type realmname: string
:return: a dict with realm description like :return: a dict with realm description like
:rtype: dict :rtype: dict
''' '''
skipping to change at line 81 skipping to change at line 82
def get_realm(realmname): def get_realm(realmname):
""" """
:param realmname: :param realmname:
:return: dict with the keys realmname, resolver. resolver being a dict :return: dict with the keys realmname, resolver. resolver being a dict
with the keys name and type. with the keys name and type.
:rtype: dict :rtype: dict
""" """
r = get_realms(realmname).get(realmname) r = get_realms(realmname).get(realmname)
return r or {} return r or {}
def get_realm_id(realmname):
"""
Returns the realm_id for a realm name
:param realmname: The name of the realm
:return: The ID of the realm. If the realm does not exist, returns None.
"""
return get_config_object().realm.get(realmname, {}).get("id")
@log_with(log) @log_with(log)
def realm_is_defined(realm): def realm_is_defined(realm):
""" """
check, if a realm already exists or not check, if a realm already exists or not
:param realm: the realm, that should be verified :param realm: the realm, that should be verified
:type realm: string :type realm: string
:return: found or not found :return: found or not found
:rtype: boolean :rtype: boolean
skipping to change at line 223 skipping to change at line 232
else: else:
failed.append(reso_name) failed.append(reso_name)
# if this is the first realm, make it the default # if this is the first realm, make it the default
if Realm.query.count() == 1: if Realm.query.count() == 1:
r = Realm.query.filter_by(name=realm).first() r = Realm.query.filter_by(name=realm).first()
r.default = True r.default = True
save_config_timestamp() save_config_timestamp()
db.session.commit() db.session.commit()
return (added, failed) return added, failed
@register_export('realms')
def export_realm(name=None):
"""
Export given realm configuration or all realms
"""
return get_realms(realmname=name)
@register_import('realms')
def import_realms(data):
"""
Import given realm configurations
"""
# TODO: the set_realm() function always creates the realm in the DB even if
# the associated resolver are not available. So the realms must be imported
# *after* the resolver.
log.debug('Import realm config: {0!s}'.format(data))
for realm, r_config in data.items():
added, failed = set_realm(
realm, resolvers=[r['name'] for r in r_config['resolver']],
priority={r['name']: r['priority'] for r in r_config['resolver']})
if is_true(r_config['default']):
set_default_realm(realm)
log.info('realm: {0!s:<15} resolver added: {1!s} '
'failed: {2!s}'.format(realm, added, failed))
 End of changes. 4 change blocks. 
2 lines changed or deleted 11 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)