diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleBuilder.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleBuilder.java index 9e88726e86e..c99b6105312 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleBuilder.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleBuilder.java @@ -107,11 +107,12 @@ public class RuleBuilder implements IAuthRuleBuilder { private class RuleBuilderFinished implements IAuthRuleFinished, IAuthRuleBuilderRuleOpClassifierFinished, IAuthRuleBuilderRuleOpClassifierFinishedWithTenantId { - private final BaseRule myOpRule; + protected final BaseRule myOpRule; ITenantApplicabilityChecker myTenantApplicabilityChecker; private List myTesters; RuleBuilderFinished(BaseRule theRule) { + assert theRule != null; myOpRule = theRule; } @@ -291,12 +292,12 @@ public class RuleBuilder implements IAuthRuleBuilder { public class RuleBuilderRuleConditionalClassifier extends RuleBuilderFinished implements IAuthRuleBuilderRuleConditionalClassifier { RuleBuilderRuleConditionalClassifier() { - super(null); + super(new RuleImplConditional(myRuleName)); } @Override protected void doBuildRule() { - RuleImplConditional rule = new RuleImplConditional(myRuleName); + RuleImplConditional rule = (RuleImplConditional) myOpRule; rule.setMode(myRuleMode); rule.setOperationType(myOperationType); rule.setAppliesTo(myAppliesTo); diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleBuilderTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleBuilderTest.java index 243d7704d43..625214ce832 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleBuilderTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleBuilderTest.java @@ -9,6 +9,7 @@ import java.util.List; import static org.hamcrest.Matchers.contains; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; public class RuleBuilderTest { @@ -48,4 +49,11 @@ public class RuleBuilderTest { )); } + @Test + public void testNullConditional() { + IAuthRuleBuilder ruleBuilder = new RuleBuilder().allow().metadata().andThen(); + IAuthRuleTester writeAccessTester = mock(IAuthRuleTester.class); + ruleBuilder.allow().createConditional().resourcesOfType("anystring").withTester(writeAccessTester).andThen(); + } + } diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e615b264536..a91dc5d1a65 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -165,6 +165,10 @@ The Testpage Overlay has been upgraded to use FontAwesome 5.x, and now supports being deployed to a servlet path other than "/". + + A NullPointerException when using the AuthorizationInterceptor RuleBuilder to build a conditional + rule with a custom tester has been corrected. Thanks to Tue Toft Nørgård for reporting! +