use of org.simbasecurity.api.service.thrift.PolicyDecision in project simba-os by cegeka.
the class AuthorizationServiceImplTest method policyAppliesAnd2ndRuleAllowedReturnsDecisionTrue_1stPolicyDoesNotApply.
@Test
public void policyAppliesAnd2ndRuleAllowedReturnsDecisionTrue_1stPolicyDoesNotApply() {
when(mockRuleRepository.findResourceRules(USERNAME, RESOURCE_NAME)).thenReturn(Arrays.asList(mockResourceRule, mock2ndResourceRule));
when(mockPolicy.applies(any(AuthorizationRequestContext.class))).thenReturn(false);
when(mock2ndPolicy.applies(any(AuthorizationRequestContext.class))).thenReturn(true);
when(mock2ndResourceRule.isAllowed(ResourceOperationType.resolve(RESOURCE_OPERATION))).thenReturn(true);
PolicyDecision decision = authorizationServiceImpl.isResourceRuleAllowed(USERNAME, RESOURCE_NAME, RESOURCE_OPERATION);
assertEquals(EXPIRATION_TIMESTAMP_2, decision.getExpirationTimestamp());
assertTrue(decision.isAllowed());
}
use of org.simbasecurity.api.service.thrift.PolicyDecision in project simba-os by cegeka.
the class AuthorizationServiceImplTest method policyAppliesAnd2ndRuleDisallowedReturnsDecisionFalse_1stPolicyDoesNotApply.
@Test
public void policyAppliesAnd2ndRuleDisallowedReturnsDecisionFalse_1stPolicyDoesNotApply() {
when(mockRuleRepository.findResourceRules(USERNAME, RESOURCE_NAME)).thenReturn(Arrays.asList(mockResourceRule, mock2ndResourceRule));
when(mockPolicy.applies(any(AuthorizationRequestContext.class))).thenReturn(false);
when(mock2ndPolicy.applies(any(AuthorizationRequestContext.class))).thenReturn(true);
when(mock2ndResourceRule.isAllowed(ResourceOperationType.resolve(RESOURCE_OPERATION))).thenReturn(false);
PolicyDecision decision = authorizationServiceImpl.isResourceRuleAllowed(USERNAME, RESOURCE_NAME, RESOURCE_OPERATION);
assertFalse(decision.isAllowed());
assertEquals(EXPIRATION_TIMESTAMP_1, decision.getExpirationTimestamp());
}
use of org.simbasecurity.api.service.thrift.PolicyDecision in project simba-os by cegeka.
the class AuthorizationServiceImplTest method policyAppliesAndRuleAllowedReturnsDecisionTrue.
@Test
public void policyAppliesAndRuleAllowedReturnsDecisionTrue() {
when(mockRuleRepository.findResourceRules(USERNAME, RESOURCE_NAME)).thenReturn(Collections.singleton(mockResourceRule));
when(mockPolicy.applies(any(AuthorizationRequestContext.class))).thenReturn(true);
when(mockResourceRule.isAllowed(ResourceOperationType.resolve(RESOURCE_OPERATION))).thenReturn(true);
PolicyDecision decision = authorizationServiceImpl.isResourceRuleAllowed(USERNAME, RESOURCE_NAME, RESOURCE_OPERATION);
assertTrue(decision.isAllowed());
assertEquals(EXPIRATION_TIMESTAMP_1, decision.getExpirationTimestamp());
}
use of org.simbasecurity.api.service.thrift.PolicyDecision in project simba-os by cegeka.
the class AuthorizationServiceImplTest method policyDoesNotApplyReturnsDecisionFalse.
@Test
public void policyDoesNotApplyReturnsDecisionFalse() {
when(mockRuleRepository.findResourceRules(USERNAME, RESOURCE_NAME)).thenReturn(Collections.singleton(mockResourceRule));
when(mockPolicy.applies(any(AuthorizationRequestContext.class))).thenReturn(false);
PolicyDecision decision = authorizationServiceImpl.isResourceRuleAllowed(USERNAME, RESOURCE_NAME, RESOURCE_OPERATION);
assertFalse(decision.isAllowed());
assertEquals(EXPIRATION_TIMESTAMP_1, decision.getExpirationTimestamp());
}
use of org.simbasecurity.api.service.thrift.PolicyDecision in project simba-os by cegeka.
the class AuthorizationServiceImplTest method policyAppliesAnd2ndRuleAllowedReturnsDecisionTrue_1stRuleDisallowed.
@Test
public void policyAppliesAnd2ndRuleAllowedReturnsDecisionTrue_1stRuleDisallowed() {
when(mockRuleRepository.findResourceRules(USERNAME, RESOURCE_NAME)).thenReturn(Arrays.asList(mockResourceRule, mock2ndResourceRule));
when(mockPolicy.applies(any(AuthorizationRequestContext.class))).thenReturn(true);
when(mockResourceRule.isAllowed(ResourceOperationType.resolve(RESOURCE_OPERATION))).thenReturn(false);
when(mock2ndPolicy.applies(any(AuthorizationRequestContext.class))).thenReturn(true);
when(mock2ndResourceRule.isAllowed(ResourceOperationType.resolve(RESOURCE_OPERATION))).thenReturn(true);
PolicyDecision decision = authorizationServiceImpl.isResourceRuleAllowed(USERNAME, RESOURCE_NAME, RESOURCE_OPERATION);
assertTrue(decision.isAllowed());
assertEquals(EXPIRATION_TIMESTAMP_2, decision.getExpirationTimestamp());
}
Aggregations