Skip to content

JASPER-551: Implement a mapping field in JASPER that can be used to derive the PCSS user details (PART 2)#458

Merged
ronaldo-macapobre merged 9 commits intomasterfrom
feature/JASPER-551
Aug 28, 2025
Merged

JASPER-551: Implement a mapping field in JASPER that can be used to derive the PCSS user details (PART 2)#458
ronaldo-macapobre merged 9 commits intomasterfrom
feature/JASPER-551

Conversation

@ronaldo-macapobre
Copy link
Contributor

@ronaldo-macapobre ronaldo-macapobre commented Aug 28, 2025

Pull Request for JIRA Ticket: JASPER-551

Issue ticket number and link

https://jira.justice.gov.bc.ca/browse/JASPER-551

Description

  • Add UserGuid, NativeGuid and JudgeId to User and UserDto objects. UserGuid is populated automatically with idir_user_guid from Keycloak while NativeGuid and JudgeId will be populated manually which will help JASPER locate the PCSS User info of the currently logged on user.
  • Create OnPostAuthSuccess function to determine the appropriate judgeId and homeLocationId to load depending on the authenticated user.

Type of change-

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Local

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@ronaldo-macapobre ronaldo-macapobre self-assigned this Aug 28, 2025
@ronaldo-macapobre ronaldo-macapobre added enhancement New feature or request .NET Pull requests that update .net code labels Aug 28, 2025
@ronaldo-macapobre ronaldo-macapobre marked this pull request as ready for review August 28, 2025 01:22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of what's contained in this code is related to what Devin is doing here; #457. So there might be some co-ordination required.

It's fine to populate the user account in JASPER with some basic information regarding a user authenticated by KeyCloak, but we still need to verify and validate (authorize) their access to JASPER before providing any access.

Short term:

  • If the user is not assigned to one of the known, expected, KeyCloak groups - then access denied.

Long term:

  • Existing account - access granted based on their account status (enabled/disabled), and assigned roles and permissions.
  • First time login - Populate basic account info (only if they request access or have a PCSS account), then verify and validate the request
    • Check with PCSS (if/when possible) - User has a valid account, configure their JASPER account accordingly and grant them equivalent access to JASPER.
    • No existing PCSS account - Provide the user with the option to request access.
      • Regardless of whether the user requests access - Notify an admin there was a failed login attempt.
      • User requests access - Notify an admin of the request and provide link the pre-populated account info for review and approval.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Wade, Ronnie and I talked about this, and we think this is logic is consistent with the goals you've listed above. Primarily, this is because Ronnie is only creating a skeleton user during login here - the logic surrounding the judge assignment as well as roles and permissions will not execute unless there is corresponding data in PCSS/Mongo.

However, Ronnie will need to update this to set the skeleton user to disabled.

So when a user logs in for the first time, this logic will run, the skeleton user gets created (which allows an admin to track failed authorization attempts). Next the frontend will redirect the user to the access request page, where they have the option of requesting access. This will allow the user to set a flag indicating their request for admin review.

Of course, the missing part here is the PCSS role synchronization, but that will come in its own PR.

LastName = context.Principal.FindFirstValue(ClaimTypes.Surname),
Email = context.Principal.Email(),
UserGuid = context.Principal.UserGuid(),
IsActive = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed, this should be false.

@sonarqubecloud
Copy link

@ronaldo-macapobre ronaldo-macapobre merged commit 084ecf7 into master Aug 28, 2025
8 checks passed
@ronaldo-macapobre ronaldo-macapobre deleted the feature/JASPER-551 branch August 28, 2025 18:06
try
{
var userService = context.HttpContext.RequestServices.GetRequiredService<IUserService>();
var userDto = await userService.GetWithPermissionsAsync(context.Principal.Email());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ronaldo-macapobre Looking through this again and I'm not sure this is safe, as this will create a new user if the user's email changes. I think in most cases email is stable but may not always be - I know in the case of sso standard they recommend that the preferred_username guid is used instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for catching that. I only used the email for duplicate checking as a quick safeguard, but we can definitely update it. I’ll switch the code to use preferred_username when I pick up a future story that involves this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request .NET Pull requests that update .net code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants