Skip to content

Commit

Permalink
[bugfix] guard against NPE in securitymanager
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico Verwer authored and line-o committed Dec 11, 2023
1 parent 1029a51 commit 3af9c32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,18 @@ private org.exist.dom.memtree.DocumentImpl functionId() {

builder.startElement(new QName("id", SecurityManagerModule.NAMESPACE_URI, SecurityManagerModule.PREFIX), null);

builder.startElement(new QName("real", SecurityManagerModule.NAMESPACE_URI, SecurityManagerModule.PREFIX), null);
subjectToXml(builder, context.getRealUser());
builder.endElement();
final Subject realUser = context.getRealUser();
if (realUser != null) {
builder.startElement(new QName("real", SecurityManagerModule.NAMESPACE_URI, SecurityManagerModule.PREFIX), null);
subjectToXml(builder, realUser);
builder.endElement();
}

if (!sameUserWithSameGroups(context.getRealUser(), context.getEffectiveUser())) {
final Subject effectiveUser = context.getEffectiveUser();
if (effectiveUser != null && (
realUser == null || !sameUserWithSameGroups(realUser, effectiveUser))) {
builder.startElement(new QName("effective", SecurityManagerModule.NAMESPACE_URI, SecurityManagerModule.PREFIX), null);
subjectToXml(builder, context.getEffectiveUser());
subjectToXml(builder, effectiveUser);
builder.endElement();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ public void differingByGroupRealAndEffectiveUsers() throws XPathException, Xpath
expect(mckContext.getDocumentBuilder()).andReturn(new MemTreeBuilder());
mckContext.popDocumentContext();
expectLastCall().once();
expect(mckContext.getRealUser()).andReturn(mckRealUser).times(2);
expect(mckContext.getRealUser()).andReturn(mckRealUser);
expect(mckRealUser.getName()).andReturn(realUsername);
expect(mckRealUser.getGroups()).andReturn(new String[]{"realGroup1"});
expect(mckRealUser.getId()).andReturn(101);
expect(mckRealUser.getGroupIds()).andReturn(new int[] {101});

final Subject mckEffectiveUser = EasyMock.createMock(Subject.class);
final String effectiveUsername = "user1";
expect(mckContext.getEffectiveUser()).andReturn(mckEffectiveUser).times(2);
expect(mckContext.getEffectiveUser()).andReturn(mckEffectiveUser);
expect(mckEffectiveUser.getId()).andReturn(101);
expect(mckEffectiveUser.getName()).andReturn(effectiveUsername);
expect(mckEffectiveUser.getGroups()).andReturn(new String[]{"realGroup1", "effectiveGroup1"});
Expand Down

0 comments on commit 3af9c32

Please sign in to comment.