Fix #1494 - Avoid NPE in RuleBuilder

This commit is contained in:
James Agnew 2019-09-20 08:56:25 -04:00
parent 20d33afb6f
commit 72d1c9e737
3 changed files with 16 additions and 3 deletions

View File

@ -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<IAuthRuleTester> 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);

View File

@ -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();
}
}

View File

@ -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 "/".
</action>
<action type="fix" issue="1495">
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!
</action>
</release>
<release version="4.0.3" date="2019-09-03" description="Igloo (Point Release)">
<action type="fix">