Skip to content

Commit

Permalink
TRUNK-6259: Fixing the NullPointerException and ConcurrentModificatio…
Browse files Browse the repository at this point in the history
…nException
  • Loading branch information
wikumChamith committed Oct 8, 2024
1 parent eb2333a commit 6eccd2f
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions api/src/main/java/org/openmrs/api/context/UserContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openmrs.api.LocationService;
import org.openmrs.util.LocaleUtility;
import org.openmrs.util.OpenmrsConstants;
import org.openmrs.util.PrivilegeConstants;
import org.openmrs.util.RoleConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -59,7 +60,7 @@ public class UserContext implements Serializable {
/**
* User's permission proxies
*/
private List<String> proxies = Collections.synchronizedList(new ArrayList<>());
private List<String> proxies = new ArrayList<>();

/**
* User's locale
Expand Down Expand Up @@ -329,25 +330,33 @@ public Set<Role> getAllRoles(User user) throws Exception {
* <strong>Should</strong> not authorize if anonymous user does not have specified privilege
*/
public boolean hasPrivilege(String privilege) {
log.debug("Checking '{}' against proxies: {}", privilege, proxies);
// check proxied privileges
for (String s : new ArrayList<>(proxies)) {
if (s.equals(privilege)) {
notifyPrivilegeListeners(getAuthenticatedUser(), privilege, true);
if (StringUtils.equals(privilege, PrivilegeConstants.GET_ROLES)) {
if (proxies.contains(privilege)) {
return true;
}
}

// if a user has logged in, check their privileges
if (isAuthenticated()
&& (getAuthenticatedUser().hasPrivilege(privilege) || getAuthenticatedRole().hasPrivilege(privilege))) {

// check user's privileges
notifyPrivilegeListeners(getAuthenticatedUser(), privilege, true);
return true;


}

log.debug("Checking '{}' against proxies: {}", privilege, proxies);
// check proxied privileges
for (String s : new ArrayList<>(proxies)) {
if (s.equals(privilege)) {
notifyPrivilegeListeners(getAuthenticatedUser(), privilege, true);
return true;
}
}



if (getAnonymousRole().hasPrivilege(privilege)) {
notifyPrivilegeListeners(getAuthenticatedUser(), privilege, true);
return true;
Expand Down

0 comments on commit 6eccd2f

Please sign in to comment.