Skip to content

Commit

Permalink
Add doPrivileged change
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Oct 19, 2023
1 parent 5251e28 commit 3cbc910
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@ public OnBehalfOfAuthenticator(Settings settings, String clusterName) {
String oboEnabledSetting = settings.get("enabled", "true");
oboEnabled = Boolean.parseBoolean(oboEnabledSetting);
encryptionKey = settings.get("encryption_key");
JwtParserBuilder builder = initParserBuilder(settings.get("signing_key"));
jwtParser = builder.build();

final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new SpecialPermission());
}
jwtParser = AccessController.doPrivileged(new PrivilegedAction<JwtParser>() {
@Override
public JwtParser run() {
JwtParserBuilder builder = initParserBuilder(settings.get("signing_key"));
return builder.build();
}
});

this.clusterName = clusterName;
this.encryptionUtil = new EncryptionDecryptionUtil(encryptionKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public void testSecurityManagerCheck() {
System.setSecurityManager(null);
}

verify(mockSecurityManager, times(2)).checkPermission(any(SpecialPermission.class));
verify(mockSecurityManager, times(3)).checkPermission(any(SpecialPermission.class));
}

@Test
Expand Down

0 comments on commit 3cbc910

Please sign in to comment.