use of org.simbasecurity.api.service.thrift.PolicyDecision in project simba-os by cegeka.
the class AuthorizationServiceImplTest method policyDecisionNeverWhenNoRule.
@Test
public void policyDecisionNeverWhenNoRule() {
when(mockRuleRepository.findResourceRules(USERNAME, RESOURCE_NAME)).thenReturn(Collections.<ResourceRule>emptySet());
PolicyDecision decision = authorizationServiceImpl.isResourceRuleAllowed(USERNAME, RESOURCE_NAME, RESOURCE_OPERATION);
assertFalse(decision.isAllowed());
assertEquals(Long.MAX_VALUE, decision.getExpirationTimestamp());
verify(mockRuleRepository).findResourceRules(USERNAME, RESOURCE_NAME);
}
use of org.simbasecurity.api.service.thrift.PolicyDecision in project simba-os by cegeka.
the class AuthorizationServiceImplTest method policyAppliesAnd2ndRuleDisallowedReturnsDecisionFalseWithSmallestExpirationStamp_1stRuleDisallowed.
@Test
public void policyAppliesAnd2ndRuleDisallowedReturnsDecisionFalseWithSmallestExpirationStamp_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(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 isURLRuleAllowed_noUrlRuleFound.
@Test
public void isURLRuleAllowed_noUrlRuleFound() {
when(mockRuleRepository.findURLRules(USERNAME)).thenReturn(Collections.<URLRule>emptyList());
PolicyDecision decision = authorizationServiceImpl.isURLRuleAllowed(USERNAME, URL, URL_OPERATION);
assertFalse(decision.isAllowed());
assertEquals(Long.MAX_VALUE, decision.getExpirationTimestamp());
}
use of org.simbasecurity.api.service.thrift.PolicyDecision in project simba-os by cegeka.
the class AuthorizationServiceImplTest method isURLRuleAllowed_urlRuleFoundAndResourcenameMatches.
@Test
public void isURLRuleAllowed_urlRuleFoundAndResourcenameMatches() {
when(mockURLRule.getResourceName()).thenReturn("*/test/*");
when(mockURLRule.isAllowed(URLOperationType.resolve(URL_OPERATION))).thenReturn(true);
when(mockPolicy.applies(any(AuthorizationRequestContext.class))).thenReturn(true);
when(mockRuleRepository.findURLRules(USERNAME)).thenReturn(Collections.singletonList(mockURLRule));
PolicyDecision decision = authorizationServiceImpl.isURLRuleAllowed(USERNAME, URL, URL_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 CheckAdminRoleCommand method execute.
@Override
public State execute(ChainContext context) throws Exception {
PolicyDecision policyDecision = this.authorizationService.isUserInRole(context.getUserName(), configurationService.getValue(SimbaConfigurationParameter.ADMIN_ROLE_NAME));
if (policyDecision.isAllowed()) {
audit.log(auditLogFactory.createEventForAuthorizationForSuccess(context, AuditMessages.USER_HAS_ADMIN_ROLE));
return State.CONTINUE;
}
audit.log(auditLogFactory.createEventForAuthorizationForFailure(context, ACCESS_DENIED + context.getRequestURL()));
context.redirectToAccessDenied();
return State.FINISH;
}
Aggregations