-
Notifications
You must be signed in to change notification settings - Fork 2.1k
FINERACT-2391: check for AppUser type before casting Authentication Principal in getCurrentAuditor #5094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
if (securityContext != null) { | ||
final Authentication authentication = securityContext.getAuthentication(); | ||
if (authentication != null) { | ||
if (authentication != null && authentication.getPrincipal() instanceof AppUser) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont like this... from audit point of view, falling back to super user in this case is incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean this makes sense to me since in case the principal is not an AppUser, it'll eventually just throw an exception in the line below when casting.
If you say we shouldn't rely on the superuser when the principal is not an appuser, but rather handle it gracefully with the proper exception, that makes sense to me too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, I’m not even comfortable with the existing logic that falls back to the superuser under any circumstances, but this might not be the right moment to fix everything.
Back to the main issue: the (now deprecated) self-service module allows anyone to perform operations during “self-registration,” and in those cases, all audit entries are recorded under the superuser account.
In the future, if for any reason the authentication principal becomes something other than an AppUser
, Fineract would effectively use the “system” user for all audit entries, which, in my view, is incorrect behaviour. I would rather introduce a new AppUser (selfService) and that to be used for any of these operations instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in two cases the principal won't be an AppUser
, the public non-auth endpoints (self-service in this case) or any scheduler/worker related cases where chances are principal being empty or a string anonymousUser
. I feel it's better to fallback on system user instead of admin user. I see there's a already a TODO comment on line#50 which happens to be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will allow this in for now... but i dont think this falling back to "mifos" / "system" user is correct approach, but it's out of scope of this bug ticket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont like this... from audit point of view, falling back to super user in this case is incorrect.
Description
Now checking for AppUser type before casting Authentication Principal to avoid
java.lang.ClassCastException
ingetCurrentAuditor
.Ignore if these details are present on the associated Apache Fineract JIRA ticket.
Checklist
Please make sure these boxes are checked before submitting your pull request - thanks!
FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.