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-6259: Fixing the NullPointerException and ConcurrentModificationException #4778

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 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,23 +330,27 @@ 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)) {
Expand Down
Loading