Skip to content

Commit

Permalink
"Clear" user data. In last big update we broke this. It's due get_jwt…
Browse files Browse the repository at this point in the history
…_claims() functionality was removed from latest version of flask_jwt and by migration process was all user data mixed with jwt service data. (#447)
  • Loading branch information
Progress1 authored Dec 16, 2024
1 parent abc8da4 commit ddf3617
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/core/auth/base_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ def generate_jwt(username):
access_token = create_access_token(
identity=user.username,
additional_claims={
"id": user.id,
"name": user.name,
"organization_name": user.get_current_organization_name(),
"permissions": user.get_permissions(),
"user_claims": {
"id": user.id,
"name": user.name,
"organization_name": user.get_current_organization_name(),
"permissions": user.get_permissions(),
}
},
)

Expand Down
11 changes: 7 additions & 4 deletions src/core/managers/auth_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,13 @@ def get_perm_from_jwt_token(user):
"""
try:
# does it include permissions?
jwt_data = get_jwt()
if not jwt_data or "permissions" not in jwt_data:
log_manager.store_user_auth_error_activity(user, "Missing permissions in JWT")
if not jwt_data or "user_claims" not in jwt_data:
log_manager.store_user_auth_error_activity(user, "Missing user data in JWT")
return None
jwt_data = jwt_data["user_claims"]
if "permissions" not in jwt_data:
log_manager.store_user_auth_error_activity(user, "Missing user permissions in JWT")
return None

all_users_perms = set(jwt_data["permissions"])
Expand Down Expand Up @@ -363,7 +366,7 @@ def wrapper(*args, **kwargs):
log_manager.store_user_auth_error_activity(user, f"Access denied by ACL for user: {user.username}")
return error

# allow check here
# allow
log_manager.store_user_activity(user, str(required_permissions_set), str(request.get_json(force=True, silent=True)))
return fn(*args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/store/auth/taranis_authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const getters = {

getUserData(state) {
const data = JSON.parse(atob(state.jwt.split('.')[1]));
return data
return data.user_claims
},

getSubjectName(state) {
Expand Down

0 comments on commit ddf3617

Please sign in to comment.