sec_setup_session (private)

 sec_setup_session [ -cookie_domain cookie_domain ] new_user_id \
    auth_level account_status

Defined in packages/acs-tcl/tcl/security-procs.tcl

Set up the session, generating a new one if necessary, updates all user_relevant information in [ad_conn], and generates the cookies necessary for the session.

Switches:
-cookie_domain (optional)
Parameters:
new_user_id (required)
auth_level (required)
account_status (required)

Partial Call Graph (max 5 caller/called nodes):
%3 ad_user_login ad_user_login (public) sec_setup_session sec_setup_session ad_user_login->sec_setup_session sec_login_handler sec_login_handler (public) sec_login_handler->sec_setup_session ad_conn ad_conn (public) sec_setup_session->ad_conn sec_allocate_session sec_allocate_session (private) sec_setup_session->sec_allocate_session sec_generate_secure_token_cookie sec_generate_secure_token_cookie (private) sec_setup_session->sec_generate_secure_token_cookie sec_generate_session_id_cookie sec_generate_session_id_cookie (private) sec_setup_session->sec_generate_session_id_cookie sec_update_user_session_info sec_update_user_session_info (private) sec_setup_session->sec_update_user_session_info

Testcases:
No testcase defined.
Source code:
    ns_log debug "OACS= sec_setup_session: enter"

    set session_id [ad_conn session_id]
    ::security::log login_cookie "sec_setup_session session_id '$session_id'"

    # figure out the session id, if we don't already have it
    if { $session_id eq ""} {

        ns_log debug "OACS= empty session_id"

        set session_id [sec_allocate_session]
        # if we have a user on a newly allocated session, update
        # users table

        ns_log debug "OACS= newly allocated session $session_id"

        if { $new_user_id != 0 } {
            ns_log debug "OACS= about to update user session info, user_id NONZERO"
            sec_update_user_session_info $new_user_id
            ns_log debug "OACS= done updating user session info, user_id NONZERO"
        }
    } else {
        #
        # $session_id is an active verified session this call is
        # either a user doing a log-in on an active unidentified
        # session, or a change in identity for a browser that is
        # already logged-in.
        #
        set prev_user_id [ad_conn user_id]

        #
        # Change the session id for all user_id changes, also on
        # changes from user_id 0, since owasp recommends to renew the
        # session_id after any privilege level change.
        #
        ns_log debug "prev_user_id $prev_user_id new_user_id $new_user_id"

        if { $prev_user_id != 0 && $prev_user_id != $new_user_id } {
            #
            # This is a change in identity so we create
            # a new session_id to avoid sharing of session-level data
            #
            set session_id [sec_allocate_session]
        }

        if { $prev_user_id != $new_user_id } {
            #
            # A change of user_id on an active session demands an
            # update of the users table.
            #
            ns_log debug "sec_update_user_session_info"
            sec_update_user_session_info $new_user_id
        }
    }

    set user_id 0
    #
    # If both auth_level and account_status are 'ok' or better, we
    # have a solid user_id.
    #
    if { ($auth_level eq "ok" || $auth_level eq "secure") && $account_status eq "ok" } {
        set user_id $new_user_id
    }

    # Set ad_conn variables
    ad_conn -set untrusted_user_id $new_user_id
    ad_conn -set session_id $session_id
    ad_conn -set auth_level $auth_level
    ad_conn -set account_status $account_status
    ad_conn -set user_id $user_id

    ns_log debug "OACS= about to generate session id cookie"

    sec_generate_session_id_cookie -cookie_domain $cookie_domain

    ns_log debug "OACS= done generating session id cookie"

    if { $auth_level eq "secure"
         && ([security::secure_conn_p] || [ad_conn behind_secure_proxy_p])
         && $new_user_id != 0
     } {
        #
        # This is a secure session, so the browser needs
        # a cookie marking it as such.
        #
        sec_generate_secure_token_cookie
    }
Generic XQL file:
packages/acs-tcl/tcl/security-procs.xql

PostgreSQL XQL file:
packages/acs-tcl/tcl/security-procs-postgresql.xql

Oracle XQL file:
packages/acs-tcl/tcl/security-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: