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

TRUNK-6203: Global properties access should be privileged #4562

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Seremba
Copy link
Contributor

@Seremba Seremba commented Feb 16, 2024

Description of what I changed

Issue I worked on

see https://openmrs.atlassian.net/browse/TRUNK-6203

Checklist: I completed these to help reviewers :)

  • My IDE is configured to follow the code style of this project.

    No? Unsure? -> configure your IDE, format the code and add the changes with git add . && git commit --amend

  • I have added tests to cover my changes. (If you refactored
    existing code that was well tested you do not have to add tests)

    No? -> write tests and add them to this commit git add . && git commit --amend

  • I ran mvn clean package right before creating this pull request and
    added all formatting changes to my commit.

    No? -> execute above command

  • All new and existing tests passed.

    No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.

  • My pull request is based on the latest changes of the master branch.

    No? Unsure? -> execute command git pull --rebase upstream master

if (propertyName == null) {
return null;
}
try {
Context.addProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
if (!Context.isAuthenticated()) {
Copy link
Member

Choose a reason for hiding this comment

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

The authentication check is automatically done by the framework. So not need for all this logic here. Not so?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dkayiwa you must be right. Let me remove it

@Seremba
Copy link
Contributor Author

Seremba commented Feb 21, 2024

Hi @dkayiwa , updates made on this PR, kindly review!

@dkayiwa
Copy link
Member

dkayiwa commented Feb 21, 2024

Whenever you are ready for review, you need to change the pull request from draft.

@Seremba Seremba marked this pull request as ready for review February 21, 2024 21:24
@Seremba
Copy link
Contributor Author

Seremba commented Feb 21, 2024

Whenever you are ready for review, you need to change the pull request from draft.

Thank you @dkayiwa, I have done as you suggested.

@dkayiwa
Copy link
Member

dkayiwa commented Feb 21, 2024

Are you able to successfully run openmrs-core with these changes?
If yes, can you also load the legacyui module and confirm that you can log in successfully?

@Seremba
Copy link
Contributor Author

Seremba commented Feb 21, 2024

Yes, I am able to run openmrs-core successfully and I have been able to login into the system. With loading the legacy UI module, do you mean deleting it and uploading its omod file again? As far as I can see, it is already loaded cc @dkayiwa

@dkayiwa
Copy link
Member

dkayiwa commented Feb 21, 2024

Can you run core, with these changes, together with all the reference application 2.x modules?

@Seremba
Copy link
Contributor Author

Seremba commented Feb 21, 2024

Yes! However, there is something I have just discovered. When I run the core with mvn openmrs-sdk:run -DserverId=server things work perfectly well and I am able login into the system and interact with it. But after like 10 to 15 minutes, without doing anything on the system and when still logged in, I get this error on the server logs. It does not affect the UI at all, neither does it affect the openmrs-core. https://pastebin.com/vdCkt50T. When I interact with the system, like say I add a new patient, the error then disappears and everything works normally. The error does not affect any operations thus far but it is there. uhm! cc @dkayiwa

@dkayiwa
Copy link
Member

dkayiwa commented Feb 22, 2024

Clone the addresshierarchy module and add the requested proxy privilege as in the error log. Then compile and update your reference application. Do the errors disappear?

@@ -106,6 +108,7 @@ public interface AdministrationService extends OpenmrsService {
* <strong>Should</strong> return default value if property name does not exist
* <strong>Should</strong> not fail with null default value
*/

Copy link
Member

Choose a reason for hiding this comment

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

Presumably this should also have an @Authorized annotation, right? (I realize that it calls the other getGlobalProperty(), but that's an implementation detail.

if (propertyName == null) {
return null;
}
try {
Context.addProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
Copy link
Member

Choose a reason for hiding this comment

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

Does this work? I would expect, in the actual app, that we've already verified that the context has this privilege, since it's required to get by the @Authorized annotation on the interface method.

Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

Design-wise, I guess a hard-coded list is ok, but it would be even better if modules could actually declare which GP's should be anonymously accessible.


}

String[] anonymousArray = { "owa.appBaseUrl", "login.url", "spa.baseUrl", "timezone.conversions", "default_theme",
Copy link
Member

Choose a reason for hiding this comment

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

All of these should be moved to the top of the file with the remainder of the properties.

String[] anonymousArray = { "owa.appBaseUrl", "login.url", "spa.baseUrl", "timezone.conversions", "default_theme",
"gzip.enabled", "default_locale" };

private final Set<String> anonymouslyAccessibleProperties = new HashSet<>(Arrays.asList(anonymousArray));
Copy link
Member

Choose a reason for hiding this comment

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

It seems kind of silly to create an array, cast it into a list and then a set, when we could just do:

private final static Set<String> anonymouslyAccessibleProperties = new HashSet<>();
static {
  Collections.addAll(anonymouslyAccessibleProperties, "owa.appBaseUrl", "login.url", "spa.baseUrl", "timezone.conversions", "default_theme", "gzip.enabled", "default_locale")
}

@Seremba
Copy link
Contributor Author

Seremba commented Feb 23, 2024

Design-wise, I guess a hard-coded list is ok, but it would be even better if modules could actually declare which GP's should be anonymously accessible.

@ibacher wouldn't this work best if the list was quite big?

@Seremba
Copy link
Contributor Author

Seremba commented Feb 23, 2024

Clone the addresshierarchy module and add the requested proxy privilege as in the error log. Then compile and update your reference application. Do the errors disappear?

Hi @dkayiwa, do I have to make a PR for the changes in addresshierarchy module too? It has been an hour and the error doesn't seem to appear anymore.

@dkayiwa
Copy link
Member

dkayiwa commented Feb 23, 2024

Clone the addresshierarchy module and add the requested proxy privilege as in the error log. Then compile and update your reference application. Do the errors disappear?

Hi @dkayiwa, do I have to make a PR for the changes in addresshierarchy module too? It has been an hour and the error doesn't seem to appear anymore.

Yes create a jira ticket under that project and raise a pull request.

@Seremba
Copy link
Contributor Author

Seremba commented Feb 23, 2024

Unfortunately, the error reappeared after an hour! Wow cc @dkayiwa

@dkayiwa
Copy link
Member

dkayiwa commented Feb 23, 2024

Unfortunately, the error reappeared after an hour! Wow cc @dkayiwa

Welcome to coding. 😊

@Seremba
Copy link
Contributor Author

Seremba commented Feb 27, 2024

Hi @dkayiwa, addresshierarchy module uses <openMRSVersion>1.10.6</openMRSVersion> and it misses Get Global Properties in its PrivilegeConstants file. I can't add it. It is a read-only file. Is there a way you recommend going about this?

@dkayiwa
Copy link
Member

dkayiwa commented Feb 27, 2024

Use the actual string value Get Global Properties instead of the constant.

@Seremba
Copy link
Contributor Author

Seremba commented Feb 27, 2024

Thank you, I had tried that earlier, but the problem still was there! Maybe I had done something wrong. Let me try again

@Seremba
Copy link
Contributor Author

Seremba commented Feb 29, 2024

Clone the addresshierarchy module and add the requested proxy privilege as in the error log. Then compile and update your reference application. Do the errors disappear?

Hi @dkayiwa, do I have to make a PR for the changes in addresshierarchy module too? It has been an hour and the error doesn't seem to appear anymore.

Yes create a jira ticket under that project and raise a pull request.

HI @dkayiwa, here is the PR under addresshierarchy project openmrs/openmrs-module-addresshierarchy#41

@Seremba Seremba force-pushed the TRUNK-6203 branch 2 times, most recently from 531980f to cb6d2d7 Compare March 15, 2024 04:15
@Seremba
Copy link
Contributor Author

Seremba commented Mar 30, 2024

@dkayiwa , @ibacher is there anything more I am still meant to do with this PR?

@Seremba
Copy link
Contributor Author

Seremba commented May 7, 2024

Hi @dkayiwa I am kindly requesting for the review of this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants