Search in sources :

Example 21 with PolicyDecision

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());
}
Also used : PolicyDecision(org.simbasecurity.api.service.thrift.PolicyDecision) AuthorizationRequestContext(org.simbasecurity.core.service.AuthorizationRequestContext) Test(org.junit.Test)

Example 22 with PolicyDecision

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());
}
Also used : PolicyDecision(org.simbasecurity.api.service.thrift.PolicyDecision) AuthorizationRequestContext(org.simbasecurity.core.service.AuthorizationRequestContext) Test(org.junit.Test)

Example 23 with PolicyDecision

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());
}
Also used : PolicyDecision(org.simbasecurity.api.service.thrift.PolicyDecision) AuthorizationRequestContext(org.simbasecurity.core.service.AuthorizationRequestContext) Test(org.junit.Test)

Example 24 with PolicyDecision

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());
}
Also used : PolicyDecision(org.simbasecurity.api.service.thrift.PolicyDecision) AuthorizationRequestContext(org.simbasecurity.core.service.AuthorizationRequestContext) Test(org.junit.Test)

Example 25 with PolicyDecision

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());
}
Also used : PolicyDecision(org.simbasecurity.api.service.thrift.PolicyDecision) AuthorizationRequestContext(org.simbasecurity.core.service.AuthorizationRequestContext) Test(org.junit.Test)

Aggregations

PolicyDecision (org.simbasecurity.api.service.thrift.PolicyDecision)25 Test (org.junit.Test)19 AuthorizationRequestContext (org.simbasecurity.core.service.AuthorizationRequestContext)12 AuditLogEvent (org.simbasecurity.core.audit.AuditLogEvent)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 THttpClient (org.apache.thrift.transport.THttpClient)1 AuthorizationService (org.simbasecurity.api.service.thrift.AuthorizationService)1 ResourceRule (org.simbasecurity.core.domain.ResourceRule)1 URLRule (org.simbasecurity.core.domain.URLRule)1