mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-03-09 14:33:32 +00:00
Prevent a nullpointerexception in AuthorizationInterceptor
This commit is contained in:
parent
39f2062802
commit
b2c7a2003e
@ -407,7 +407,13 @@ public class AuthorizationInterceptor extends ServerOperationInterceptorAdapter
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
||||||
b.append("rule", myDecidingRule.getName());
|
String ruleName;
|
||||||
|
if (myDecidingRule != null) {
|
||||||
|
ruleName = myDecidingRule.getName();
|
||||||
|
} else {
|
||||||
|
ruleName = "(none)";
|
||||||
|
}
|
||||||
|
b.append("rule", ruleName);
|
||||||
b.append("decision", myDecision.name());
|
b.append("decision", myDecision.name());
|
||||||
return b.build();
|
return b.build();
|
||||||
}
|
}
|
||||||
|
@ -645,6 +645,13 @@ public class AuthorizationInterceptorDstu3Test {
|
|||||||
.denyAll("Default Rule")
|
.denyAll("Default Rule")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleDeny(Verdict decision) {
|
||||||
|
// Make sure the toString() method on Verdict never fails
|
||||||
|
ourLog.info("Denying with decision: {}", decision);
|
||||||
|
super.handleDeny(decision);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
HttpGet httpGet;
|
HttpGet httpGet;
|
||||||
@ -688,6 +695,65 @@ public class AuthorizationInterceptorDstu3Test {
|
|||||||
assertFalse(ourHitMethod);
|
assertFalse(ourHitMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDenyAllByDefault() throws Exception {
|
||||||
|
ourServlet.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) {
|
||||||
|
@Override
|
||||||
|
public List<IAuthRule> buildRuleList(RequestDetails theRequestDetails) {
|
||||||
|
return new RuleBuilder()
|
||||||
|
.allow().read().resourcesOfType(Patient.class).withAnyId().andThen()
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleDeny(Verdict decision) {
|
||||||
|
// Make sure the toString() method on Verdict never fails
|
||||||
|
ourLog.info("Denying with decision: {}", decision);
|
||||||
|
super.handleDeny(decision);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
HttpGet httpGet;
|
||||||
|
HttpResponse status;
|
||||||
|
String response;
|
||||||
|
|
||||||
|
ourHitMethod = false;
|
||||||
|
ourReturn = Collections.singletonList(createPatient(2));
|
||||||
|
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1");
|
||||||
|
status = ourClient.execute(httpGet);
|
||||||
|
extractResponseAndClose(status);
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
assertTrue(ourHitMethod);
|
||||||
|
|
||||||
|
ourHitMethod = false;
|
||||||
|
ourReturn = Collections.singletonList(createObservation(10, "Patient/2"));
|
||||||
|
httpGet = new HttpGet("http://localhost:" + ourPort + "/Observation/10");
|
||||||
|
status = ourClient.execute(httpGet);
|
||||||
|
response = extractResponseAndClose(status);
|
||||||
|
ourLog.info(response);
|
||||||
|
assertThat(response, containsString("Access denied by default policy"));
|
||||||
|
assertEquals(403, status.getStatusLine().getStatusCode());
|
||||||
|
assertFalse(ourHitMethod);
|
||||||
|
|
||||||
|
ourHitMethod = false;
|
||||||
|
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1/$validate");
|
||||||
|
status = ourClient.execute(httpGet);
|
||||||
|
response = extractResponseAndClose(status);
|
||||||
|
ourLog.info(response);
|
||||||
|
assertThat(response, containsString("Access denied by default policy"));
|
||||||
|
assertEquals(403, status.getStatusLine().getStatusCode());
|
||||||
|
assertFalse(ourHitMethod);
|
||||||
|
|
||||||
|
ourHitMethod = false;
|
||||||
|
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1/$opName");
|
||||||
|
status = ourClient.execute(httpGet);
|
||||||
|
response = extractResponseAndClose(status);
|
||||||
|
ourLog.info(response);
|
||||||
|
assertThat(response, containsString("Access denied by default policy"));
|
||||||
|
assertEquals(403, status.getStatusLine().getStatusCode());
|
||||||
|
assertFalse(ourHitMethod);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* #528
|
* #528
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user