示例#1
0
def before_request():
    """
    This is executed before the request
    """
    update_config_object()
    request.all_data = get_all_params(request.values, request.data)
    request.User = get_user_from_param(request.all_data)
    privacyidea_server = current_app.config.get("PI_AUDIT_SERVERNAME") or \
                         request.host
    # Create a policy_object, that reads the database audit settings
    # and contains the complete policy definition during the request.
    # This audit_object can be used in the postpolicy and prepolicy and it
    # can be passed to the innerpolicies.

    g.policy_object = PolicyClass()

    g.audit_object = getAudit(current_app.config)
    g.event_config = EventConfiguration()
    # access_route contains the ip addresses of all clients, hops and proxies.
    g.client_ip = get_client_ip(request, get_from_config(SYSCONF.OVERRIDECLIENT))
    g.audit_object.log({"success": False,
                        "action_detail": "",
                        "client": g.client_ip,
                        "client_user_agent": request.user_agent.browser,
                        "privacyidea_server": privacyidea_server,
                        "action": "{0!s} {1!s}".format(request.method, request.url_rule),
                        "info": ""})
示例#2
0
def before_request():
    """
    This is executed before the request
    """
    update_config_object()
    request.all_data = get_all_params(request.values, request.data)
    privacyidea_server = current_app.config.get("PI_AUDIT_SERVERNAME") or \
                         request.host
    g.policy_object = PolicyClass()
    g.audit_object = getAudit(current_app.config)
    # access_route contains the ip adresses of all clients, hops and proxies.
    g.client_ip = get_client_ip(request,
                                get_from_config(SYSCONF.OVERRIDECLIENT))
    g.audit_object.log({
        "success":
        False,
        "client":
        g.client_ip,
        "client_user_agent":
        request.user_agent.browser,
        "privacyidea_server":
        privacyidea_server,
        "action":
        "{0!s} {1!s}".format(request.method, request.url_rule),
        "action_detail":
        "",
        "info":
        ""
    })
示例#3
0
def before_request():
    """
    This is executed before the request
    """
    update_config_object()
    request.all_data = get_all_params(request.values, request.data)
    privacyidea_server = current_app.config.get("PI_AUDIT_SERVERNAME") or \
                         request.host
    # Create a policy_object, that reads the database audit settings
    # and contains the complete policy definition during the request.
    # This audit_object can be used in the postpolicy and prepolicy and it
    # can be passed to the innerpolicies.
    g.policy_object = PolicyClass()
    g.audit_object = getAudit(current_app.config)
    # access_route contains the ip adresses of all clients, hops and proxies.
    g.client_ip = get_client_ip(request,
                                get_from_config(SYSCONF.OVERRIDECLIENT))
    g.audit_object.log({
        "success":
        False,
        "action_detail":
        "",
        "client":
        g.client_ip,
        "client_user_agent":
        request.user_agent.browser,
        "privacyidea_server":
        privacyidea_server,
        "action":
        "{0!s} {1!s}".format(request.method, request.url_rule),
        "info":
        ""
    })
示例#4
0
 def test_08_config_object(self):
     set_privacyidea_config(key="k1", value="v1")
     self.assertEqual(get_config_object().get_config("k1"), "v1")
     set_privacyidea_config(key="k1", value="v2")
     # not updated yet
     self.assertEqual(get_config_object().get_config("k1"), "v1")
     # updated now
     self.assertEqual(update_config_object().get_config("k1"), "v2")
示例#5
0
def get_default_realm():
    """
    return the default realm
    - lookup in the config for the DefaultRealm key
    
    @return: the realm name
    @rtype : string
    """
    config_object = update_config_object()
    return config_object.default_realm
示例#6
0
def get_default_realm():
    """
    return the default realm
    - lookup in the config for the DefaultRealm key
    
    @return: the realm name
    @rtype : string
    """
    config_object = update_config_object()
    return config_object.default_realm
示例#7
0
def before_request():
    """
    This is executed before the request
    """
    update_config_object()
    request.all_data = get_all_params(request.values, request.data)
    privacyidea_server = current_app.config.get("PI_AUDIT_SERVERNAME") or \
                         request.host
    g.policy_object = PolicyClass()
    g.audit_object = getAudit(current_app.config)
    # access_route contains the ip adresses of all clients, hops and proxies.
    g.client_ip = get_client_ip(request,
                                get_from_config(SYSCONF.OVERRIDECLIENT))
    g.audit_object.log({"success": False,
                        "client": g.client_ip,
                        "client_user_agent": request.user_agent.browser,
                        "privacyidea_server": privacyidea_server,
                        "action": "{0!s} {1!s}".format(request.method, request.url_rule),
                        "action_detail": "",
                        "info": ""})
示例#8
0
def get_realms(realmname=""):
    '''
    either return all defined realms or a specific realm
    
    :param realmname: the realm, that is of interestet, if ==""
                      all realms are returned
    :type realmname: string

    :return: a dict with realm description like
    :rtype: dict
    '''
    config_object = update_config_object()
    realms = config_object.realm
    if realmname:
        if realmname in realms:
            realms = {realmname: realms.get(realmname)}
        else:
            realms = {}
    return realms
示例#9
0
def get_realms(realmname=""):
    '''
    either return all defined realms or a specific realm
    
    :param realmname: the realm, that is of interestet, if ==""
                      all realms are returned
    :type realmname: string

    :return: a dict with realm description like
    :rtype: dict
    '''
    config_object = update_config_object()
    realms = config_object.realm
    if realmname:
        if realmname in realms:
            realms = {realmname: realms.get(realmname)}
        else:
            realms = {}
    return realms
示例#10
0
def before_request():
    """
    This is executed before the request.

    user_required checks if there is a logged in admin or user

    The checks for ONLY admin are preformed in api/system.py
    """
    # remove session from param and gather all parameters, either
    # from the Form data or from JSON in the request body.
    update_config_object()
    request.all_data = get_all_params(request.values, request.data)
    try:
        request.User = get_user_from_param(request.all_data)
    except AttributeError:
        # Some endpoints do not need users OR e.g. the setPolicy endpoint
        # takes a list as the userobject
        request.User = None
    except UserError:
        # In cases like the policy API, the parameter "user" is part of the
        # policy and will not resolve to a user object
        request.User = User()

    g.policy_object = PolicyClass()
    g.audit_object = getAudit(current_app.config)
    g.event_config = EventConfiguration()
    # access_route contains the ip adresses of all clients, hops and proxies.
    g.client_ip = get_client_ip(request,
                                get_from_config(SYSCONF.OVERRIDECLIENT))
    privacyidea_server = current_app.config.get("PI_AUDIT_SERVERNAME") or \
                         request.host
    # Already get some typical parameters to log
    serial = getParam(request.all_data, "serial")
    if serial:
        tokentype = get_token_type(serial)
    else:
        tokentype = None
    realm = getParam(request.all_data, "realm")
    user_loginname = ""
    resolver = ""
    if "token_blueprint" in request.endpoint:
        # In case of token endpoint we evaluate the user in the request.
        # Note: In policy-endpoint "user" is part of the policy configuration
        #  and will cause an exception
        user = get_user_from_param(request.all_data)
        user_loginname = user.login
        realm = user.realm or realm
        resolver = user.resolver

    g.audit_object.log({
        "success":
        False,
        "serial":
        serial,
        "user":
        user_loginname,
        "realm":
        realm,
        "resolver":
        resolver,
        "token_type":
        tokentype,
        "client":
        g.client_ip,
        "client_user_agent":
        request.user_agent.browser,
        "privacyidea_server":
        privacyidea_server,
        "action":
        "{0!s} {1!s}".format(request.method, request.url_rule),
        "action_detail":
        "",
        "info":
        ""
    })

    if g.logged_in_user.get("role") == "user":
        # A user is calling this API
        # In case the token API is called by the user and not by the admin we
        #  need to restrict the token view.
        CurrentUser = get_user_from_param({
            "user":
            g.logged_in_user.get("username"),
            "realm":
            g.logged_in_user.get("realm")
        })
        request.all_data["user"] = CurrentUser.login
        request.all_data["resolver"] = CurrentUser.resolver
        request.all_data["realm"] = CurrentUser.realm
        g.audit_object.log({
            "user": CurrentUser.login,
            "resolver": CurrentUser.resolver,
            "realm": CurrentUser.realm
        })
    else:
        # An administrator is calling this API
        g.audit_object.log({"administrator": g.logged_in_user.get("username")})