Skip to content

Commit 942076b

Browse files
committed
TRUNK-6466: Restore proxies as list
Turns out we were using the list `remove()` function guarantee of only removing a single result at a time
1 parent a634f78 commit 942076b

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

api/src/main/java/org/openmrs/api/context/UserContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.util.Arrays;
1515
import java.util.Collections;
1616
import java.util.HashSet;
17-
import java.util.LinkedHashSet;
17+
import java.util.List;
1818
import java.util.Locale;
1919
import java.util.Objects;
2020
import java.util.Set;
@@ -61,7 +61,7 @@ public class UserContext implements Serializable {
6161
/**
6262
* User's permission proxies
6363
*/
64-
private final Set<String> proxies = Collections.synchronizedSet(new LinkedHashSet<>());
64+
private final List<String> proxies = Collections.synchronizedList(new ArrayList<>());
6565

6666
/**
6767
* User's locale

api/src/test/java/org/openmrs/api/context/UserContextTest.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import org.springframework.beans.factory.annotation.Autowired;
2323

2424
import static org.hamcrest.MatcherAssert.assertThat;
25-
import static org.hamcrest.Matchers.contains;
26-
import static org.hamcrest.Matchers.empty;
2725
import static org.hamcrest.Matchers.equalTo;
2826
import static org.hamcrest.Matchers.is;
2927
import static org.hamcrest.Matchers.nullValue;
@@ -168,4 +166,42 @@ void removeProxyPrivilege_shouldHandleNullArrayGracefully() {
168166
// assert - should still have the privilege since null was passed
169167
assertThat(userContext.hasPrivilege("Privilege1"), is(true));
170168
}
169+
170+
@Test
171+
void removeProxyPrivilege_shouldHandleNonExistentPrivilegeGracefully() {
172+
// arrange
173+
UserContext userContext = new UserContext(new TestUsernameAuthenticationScheme());
174+
175+
// act
176+
userContext.removeProxyPrivilege("Privilege 1");
177+
178+
// assert - no error thrown
179+
}
180+
181+
@Test
182+
void proxyPrivileges_shouldStackCorrectly() {
183+
// arrange
184+
UserContext userContext = new UserContext(new TestUsernameAuthenticationScheme());
185+
186+
// act - deep nesting
187+
userContext.addProxyPrivilege("Privilege1");
188+
try {
189+
userContext.addProxyPrivilege("Privilege1");
190+
try {
191+
userContext.addProxyPrivilege("Privilege1");
192+
try {
193+
userContext.addProxyPrivilege("Privilege1");
194+
} finally {
195+
userContext.removeProxyPrivilege("Privilege1");
196+
}
197+
} finally {
198+
userContext.removeProxyPrivilege("Privilege1");
199+
}
200+
} finally {
201+
userContext.removeProxyPrivilege("Privilege1");
202+
}
203+
204+
// assert
205+
assertThat(userContext.hasPrivilege("Privilege1"), is(true));
206+
}
171207
}

0 commit comments

Comments
 (0)