Exemple #1
0
    def kerberos_update_ticket():
        """
        Update the kerberos ticket.
        """
        from werkzeug.datastructures import Headers
        headers = Headers()

        authorization = request.headers.get("Authorization", None)

        if authorization is None:
            # Send the Negotiate header to the client
            # if Kerberos ticket is not found.
            headers.add('WWW-Authenticate', 'Negotiate')
            return Response("Unauthorised", 401, headers)
        else:
            source = get_auth_sources(KERBEROS)
            auth_header = authorization.split()
            in_token = auth_header[1]

            # Validate the Kerberos ticket
            status, context = source.negotiate_start(in_token)
            if status:
                return Response("Ticket updated successfully.")

            return Response(context, 500)
Exemple #2
0
def oidc_login():

    auth_obj = AuthSourceManager(None, ['oidc'])
    print("Logging auth_obj")
    print(auth_obj)

    session['_auth_source_manager_obj'] = auth_obj.as_dict()
    print("added _auth_source_manager_obj to session")

    oidc_auth_source = get_auth_sources("oidc")
    print("Logging oidc_auth_source")
    print(oidc_auth_source)

    unique_id = "u" + oidc.user_getfield('sub') + "@cyton"
    display_name = oidc.user_getfield('preferred_username')
    email = oidc.user_getfield('email')

    if email is None or email == "None":
        email = unique_id

    user = User.query.filter_by(username=unique_id).first()

    if user is None:
        res, user = create_user({
            'username': unique_id,
            'email': email,
            'role': 2,
            'active': True,
            'is_active': True,
            'auth_source': 'oidc'
        })

        print("Logging res and user")
        print(res)
        print(user)

    print("querying for user")
    user = User.query.filter_by(username=unique_id).first()

    print("Logging user:"******"loading servers.json for user")

    storage_dir = get_storage_directory()
    print("storage_dir")
    print(storage_dir)
    system('rm -f ' + storage_dir + '/pgpassfile')
    system('cp /pgadmin4/pgpass/pgpassfile ' + storage_dir + '/')
    system('chmod 0600 ' + storage_dir + '/pgpassfile')

    system('/usr/local/bin/python /pgadmin4/setup.py --load-servers "' +
           environ.get('PGADMIN_SERVER_JSON_FILE') + '" --user ' + unique_id)

    return redirect(get_post_login_redirect())