Skip to content
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

Bugfix/apikey header capitalization #447

Merged
merged 6 commits into from
Nov 3, 2023

Conversation

MikeNeilson
Copy link
Contributor

User haven't been:

  1. Typing apikey before the actual token when used. So added a note to the description (tried to make it the "scheme" but apparently OpenAPI/Swagger will only accept schemes defined in RFCs)
  2. Uses who did type it mixed case, made check case ingoring compare.
  3. Minor cleanup and updates.

the new setClientInfo on the JDBC connections would end up too long and fail.

Comment on lines +74 to +75
private static String connectionUser = null;
private static String defaultOffice = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Making these static and conditionally setting them in the constructor weirds me out. I can't say exactly why but it feels like asking for trouble. Like if the first request made is for an un-checked get end-point and the request includes office_id will it cause the static value to get assigned to whatever the first request provided? At the very minimum it seems like assigning to AuthDao.defaultOffice shouldn't happen if the set_session_user_direct failed - right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This always uses the office id of the context "e.g. cwms -> hq, spk -> spk" not the context of data.

For the 2nd part I think it just won't get used, but I don't think the additional logic is required just for that state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But the short version is that I'm just trying to avoid creating a new instance of this object on every request since it will be used on a LOT of requests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok. the part about the context makes more sense. Should AuthDao have a static getInstance() and just use it singleton style?

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 considered the use of a singleton, that's going to need more investigation. Since the clientInfo is different for every request i needs the new context on each run so I think for now we do new to just run new on every request since their could be multiple threads. Or synchronize on the object which seems like a terrible idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, after realizing it needs the javalin Context information of the current request so that setClientInfo is correct for tracing instead of a pure singleton I made it a singleton per thread.

}
AuthDao.RETRIEVE_GROUPS_OF_USER = ResourceHelper.getResourceAsString("/cwms/data/sql/user_groups.sql",this.getClass());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason to do this here vs at the variable declaration?

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'm quite sure there was when I initial did the work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that's not a bad idea. Let me chew on that one a bit. It is supposed to be usable by all the possible Auth mechanisms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, that response was to the comment above but I did go ahead and just do this.

rma-rripken
rma-rripken previously approved these changes Oct 31, 2023
@MikeNeilson MikeNeilson merged commit 33caa6c into develop Nov 3, 2023
3 checks passed
@MikeNeilson MikeNeilson deleted the bugfix/apikey_header_capitalization branch November 3, 2023 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hec-approved-W912HQ22F0913-13b only valid if created by @MikeNeilson priority:medium We care, and will try and get to it soon.
Projects
None yet
2 participants