Skip to content

refactor basic authentication and session management#186

Merged
adamkorynta merged 39 commits intomainfrom
feature/authentication_refactor
Sep 30, 2024
Merged

refactor basic authentication and session management#186
adamkorynta merged 39 commits intomainfrom
feature/authentication_refactor

Conversation

@adamkorynta
Copy link
Contributor

@adamkorynta adamkorynta commented Sep 10, 2024

Problem Description

All jax-rs resource endpoints include the user token parameter that is redundant with the authorization header. In order to implement CWMS CAC authentication, all basic authentication needs to get refactored so that it is not enabled in the CWMS/CCP version of the REST API.

Solution

  • Removed query parameter user token. Authorization headers are now the only way to authenticate with the REST API when using basic authentication.
  • Refactored token authentication to a ContainerRequestFilter in order to facilitate a separate implementation for CWMS CAC authentication.
  • The token is now moved into the context session.
  • There is still a thread monitoring for stale ApiEventClient and ApiLddsClients, though they are keyed to session ids so that they can get shutdown when the session is destroyed.
  • removed the -s secure mode flag given that the insecure query parameters were gated by the flag and have been removed
  • Added authorization for JWT and Single Sign-On JSESSIONIDSSO cookie checks.

how you tested the change

Used IntelliJ HTTP client checking authenticated vs non-authenticated endpoints.
Added unit tests with heavy (probably too heavy) usage of Mockito.

Where the following done:

  • Tests. Check all that apply:
    • Unit tests created or modified that run during gradle test.
    • Integration tests created or modified that run during integration testing
      (Formerly called regression tests.)
    • Test procedure descriptions for manual testing
  • Was relevant documentation updated? updated README.md to document the update.
  • Were relevant config element (e.g. XML data) updated as appropriate

Relevant discussion page for removing the query parameters: #185

Removed query parameter user token. Authorization headers are now the only way to authenticate with the REST API when using basic authentication.
Refactored token authentication to a ContainerRequestFilter in order to facilitate a separate implementation for CWMS CAC authentication. The token is now moved into the context session. There is still a thread monitoring for stale ApiEventClient and ApiLddsClients, though they are keyed to session ids so that they can get shutdown when the session is destroyed.
Copy link
Collaborator

@MikeNeilson MikeNeilson left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me. Haven't been able to test it, of course.

@MikeNeilson
Copy link
Collaborator

Oh, there's an additional link here: #18

I think we'll want to go there eventually, but this PR is a solid first step.

Copy link
Collaborator

@MikeNeilson MikeNeilson left a comment

Choose a reason for hiding this comment

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

just marking for future diffs.

@MikeNeilson
Copy link
Collaborator

MikeNeilson commented Sep 13, 2024 via email

Copy link
Collaborator

@MikeNeilson MikeNeilson left a comment

Choose a reason for hiding this comment

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

Definitely looking more flexible.

Some notes, nothing that really needs to be taken care of.

Copy link
Collaborator

@MikeNeilson MikeNeilson left a comment

Choose a reason for hiding this comment

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

Just marking.. again.

Copy link
Collaborator

@MikeNeilson MikeNeilson left a comment

Choose a reason for hiding this comment

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

Overall the change looks good and is in line with what I was thinking.

I was planning to use plain Java ServiceLoader; however, if you think there's a lot of value in the HEC lookup system, and perhaps there is. We should investigate moving the lookup code to github (the HEC one) and make sure the artifact gets to maven central to avoid that coupling to HEC itself.

Copy link
Collaborator

@MikeNeilson MikeNeilson left a comment

Choose a reason for hiding this comment

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

Updated responses.

@adamkorynta
Copy link
Contributor Author

Yeah, I was more referring to trying to keep the DAO's operating with DTO adjacent data types, and keep Principal/sessioning up at a separate layer.

@MikeNeilson
Copy link
Collaborator

Yeah, I was more referring to trying to keep the DAO's operating with DTO adjacent data types, and keep Principal/sessioning up at a separate layer.

Okay, that's what I thought after reading it more, though I would still posit that returning a full javax.security.Principal is reasonable. But I'm not set one it enough to do anything but provide the suggestion. The interface looks nice and generic enough to me know.

Copy link
Collaborator

@rma-psmorris rma-psmorris left a comment

Choose a reason for hiding this comment

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

Finished review from sec on.

logging updates
consolidate edipi check into username check
use CWMS_20 schema prefix
Copy link
Collaborator

@MikeNeilson MikeNeilson left a comment

Choose a reason for hiding this comment

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

Marking for next batch.

@sonarqubecloud
Copy link

Copy link
Collaborator

@rma-psmorris rma-psmorris left a comment

Choose a reason for hiding this comment

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

Approved, no further comments

@MikeNeilson
Copy link
Collaborator

MikeNeilson commented Sep 30, 2024 via email

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

Labels

None yet

Projects

No open projects

4 participants