diff --git a/cmdb-api/Pipfile b/cmdb-api/Pipfile index 4ae8224..fb2e52e 100644 --- a/cmdb-api/Pipfile +++ b/cmdb-api/Pipfile @@ -62,6 +62,7 @@ alembic = "==1.7.7" hvac = "==2.0.0" colorama = ">=0.4.6" pycryptodomex = ">=3.19.0" +lz4 = ">=4.3.2" [dev-packages] # Testing diff --git a/cmdb-api/api/flask_cas/routing.py b/cmdb-api/api/flask_cas/routing.py index 7341027..affa648 100644 --- a/cmdb-api/api/flask_cas/routing.py +++ b/cmdb-api/api/flask_cas/routing.py @@ -1,7 +1,5 @@ # -*- coding:utf-8 -*- -import json - import bs4 from flask import Blueprint from flask import current_app, session, request, url_for, redirect @@ -34,8 +32,7 @@ def login(): if request.values.get("next"): session["next"] = request.values.get("next") - _service = url_for('cas.login', _external=True, next=session["next"]) \ - if session.get("next") else url_for('cas.login', _external=True) + _service = url_for('cas.login', _external=True) redirect_url = create_cas_login_url( current_app.config['CAS_SERVER'], current_app.config['CAS_LOGIN_ROUTE'], @@ -47,8 +44,7 @@ def login(): if request.args.get('ticket'): if validate(request.args['ticket']): - redirect_url = session.get("next") or \ - current_app.config.get("CAS_AFTER_LOGIN") + redirect_url = session.get("next") or current_app.config.get("CAS_AFTER_LOGIN") username = session.get("CAS_USERNAME") user = UserCache.get(username) login_user(user) @@ -115,21 +111,19 @@ def validate(ticket): try: response = urlopen(cas_validate_url).read() - ticketid = _parse_tag(response, "cas:user") - strs = [s.strip() for s in ticketid.split('|') if s.strip()] + ticket_id = _parse_tag(response, "cas:user") + strs = [s.strip() for s in ticket_id.split('|') if s.strip()] username, is_valid = None, False if len(strs) == 1: username = strs[0] is_valid = True - user_info = json.loads(_parse_tag(response, "cas:other")) - current_app.logger.info(user_info) except ValueError: current_app.logger.error("CAS returned unexpected result") is_valid = False return is_valid if is_valid: - current_app.logger.debug("valid") + current_app.logger.debug("{}: {}".format(cas_username_session_key, username)) session[cas_username_session_key] = username user = UserCache.get(username) @@ -164,4 +158,5 @@ def _parse_tag(string, tag): if soup.find(tag) is None: return '' + return soup.find(tag).string.strip() diff --git a/cmdb-api/requirements.txt b/cmdb-api/requirements.txt index 1776a05..849bf9c 100644 --- a/cmdb-api/requirements.txt +++ b/cmdb-api/requirements.txt @@ -34,7 +34,7 @@ cryptography>=41.0.2 PyJWT==2.4.0 PyMySQL==1.1.0 ldap3==2.9.1 -PyYAML==6.0 +PyYAML==6.0.1 redis==4.6.0 requests==2.31.0 requests_oauthlib==1.3.1 @@ -48,6 +48,6 @@ treelib==1.6.1 Werkzeug>=2.3.6 WTForms==3.0.0 shamir~=17.12.0 -hvac~=2.0.0 pycryptodomex>=3.19.0 colorama>=0.4.6 +lz4>=4.3.2 \ No newline at end of file