refactor basic authentication and session management#186
Conversation
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.
MikeNeilson
left a comment
There was a problem hiding this comment.
Looks reasonable to me. Haven't been able to test it, of course.
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/sec/basicauth/TokenAuthenticatorFilter.java
Outdated
Show resolved
Hide resolved
|
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. |
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/hydrojson/DbInterface.java
Outdated
Show resolved
Hide resolved
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/sec/basicauth/TokenManager.java
Outdated
Show resolved
Hide resolved
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/sec/basicauth/TokenManager.java
Outdated
Show resolved
Hide resolved
MikeNeilson
left a comment
There was a problem hiding this comment.
just marking for future diffs.
replace system properties with web.xml parameters
MikeNeilson
left a comment
There was a problem hiding this comment.
Definitely looking more flexible.
Some notes, nothing that really needs to be taken care of.
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/hydrojson/DbInterface.java
Outdated
Show resolved
Hide resolved
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/res/LrgsResources.java
Show resolved
Hide resolved
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/sec/SecurityFilter.java
Outdated
Show resolved
Hide resolved
MikeNeilson
left a comment
There was a problem hiding this comment.
Just marking.. again.
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/res/RestServices.java
Outdated
Show resolved
Hide resolved
mock objects are used in place of integration tests at the moment. Once infrastructure is in place, full integration tests can replace the mocks.
MikeNeilson
left a comment
There was a problem hiding this comment.
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.
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/dao/ApiAuthorizationDAI.java
Outdated
Show resolved
Hide resolved
|
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 |
rma-psmorris
left a comment
There was a problem hiding this comment.
Finished review from sec on.
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/sec/basicauth/BasicAuthResource.java
Show resolved
Hide resolved
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/sec/cwms/CwmsAuthorizationDAO.java
Outdated
Show resolved
Hide resolved
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/sec/cwms/CwmsAuthorizationDAO.java
Outdated
Show resolved
Hide resolved
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/sec/cwms/CwmsAuthorizationDAO.java
Outdated
Show resolved
Hide resolved
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/sec/cwms/CwmsAuthorizationDAO.java
Outdated
Show resolved
Hide resolved
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/sec/cwms/CwmsAuthorizationDAO.java
Outdated
Show resolved
Hide resolved
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/sec/SecurityFilter.java
Outdated
Show resolved
Hide resolved
logging updates consolidate edipi check into username check use CWMS_20 schema prefix
MikeNeilson
left a comment
There was a problem hiding this comment.
Marking for next batch.
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/lrgsclient/ClientConnectionCache.java
Show resolved
Hide resolved
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/sec/cwms/CwmsAuthorizationDAO.java
Show resolved
Hide resolved
|
rma-psmorris
left a comment
There was a problem hiding this comment.
Approved, no further comments
|
Oh right that particular colulm is populated by the user managmemt system
and not used in CWMS.
…On Mon, Sep 30, 2024, 1:58 PM Adam Korynta ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
opendcs-rest-api/src/main/java/org/opendcs/odcsapi/sec/cwms/CwmsAuthorizationDAO.java
<#186 (comment)>:
> @@ -44,11 +44,18 @@ public Set<OpenDcsApiRoles> getRoles(String username) throws DbException
{
Set<OpenDcsApiRoles> roles = EnumSet.noneOf(OpenDcsApiRoles.class);
roles.add(OpenDcsApiRoles.ODCS_API_GUEST);
- String q = "SELECT user_group_id" +
- " FROM av_sec_users" +
- " WHERE db_office_code = cwms_util.get_db_office_code(?)" +
- " AND username = ?" +
- " AND is_member = 'T'";
+ String q = "select user_group_id " +
+ "from cwms_20.av_sec_users " +
+ "where db_office_code = cwms_20.cwms_util.get_db_office_code(:input_db_office_code) " +
+ " and upper(username) = case " +
+ " when instr(:username_str, '.', -1) > 0 then " +
+ " (select userid " +
+ " from cwms_20.at_sec_cwms_users " +
+ " where edipi = substr(:username_str, instr(:username_str, '.', -1) + 1)) " +
av_sec_users is the one with the office code, at_sec_cwms_users has an
'office' column looks to be used for something else (it's null in our
database exports and 16 bytes).
—
Reply to this email directly, view it on GitHub
<#186 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB44KCF36CIJM3TLSLQGE4DZZG3NXAVCNFSM6AAAAABN7LV2FGVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGMZYGU2TAOJZGE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|



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
-ssecure mode flag given that the insecure query parameters were gated by the flag and have been removedhow 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:
(Formerly called regression tests.)
Relevant discussion page for removing the query parameters: #185