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;
}
use of org.simbasecurity.api.service.thrift.PolicyDecision in project simba-os by cegeka.
the class AuthorizationServiceClient method isURLRuleAllowed.
@Override
public PolicyDecision isURLRuleAllowed(String username, String resourcename, String method) throws TException {
AuthorizationKey authorizationKey = new AuthorizationKey(username, resourcename, method);
PolicyDecision policyDecision = urlRuleCache.get(authorizationKey);
if (policyDecision == null || PolicyDecisionHelper.isExpired(policyDecision)) {
policyDecision = getAuthorizationServiceClient().isURLRuleAllowed(username, resourcename, method);
urlRuleCache.put(authorizationKey, policyDecision);
}
return policyDecision;
}
use of org.simbasecurity.api.service.thrift.PolicyDecision in project simba-os by cegeka.
the class SimbaAuthorizationCachingServiceTest method shouldCallAuthorizationServiceWhenResourceRuleCachedButExpired.
@Test
public void shouldCallAuthorizationServiceWhenResourceRuleCachedButExpired() throws Exception {
when(authorizationServiceMock.isResourceRuleAllowed(NOT_RELEVANT, NOT_RELEVANT, NOT_RELEVANT)).thenReturn(new PolicyDecision(true, EXPIRED_TIMESTAMP)).thenReturn(new PolicyDecision(false, VALID_TIMESTAMP));
// Call once to fill cache
cachingService.isResourceRuleAllowed(NOT_RELEVANT, NOT_RELEVANT, NOT_RELEVANT);
PolicyDecision decision = cachingService.isResourceRuleAllowed(NOT_RELEVANT, NOT_RELEVANT, NOT_RELEVANT);
assertFalse(decision.isAllowed());
verify(authorizationServiceMock, times(2)).isResourceRuleAllowed(NOT_RELEVANT, NOT_RELEVANT, NOT_RELEVANT);
}
use of org.simbasecurity.api.service.thrift.PolicyDecision in project simba-os by cegeka.
the class SimbaAuthorizationCachingServiceTest method shouldCallAuthorizationServiceWhenURLRuleCachedButExpired.
@Test
public void shouldCallAuthorizationServiceWhenURLRuleCachedButExpired() throws Exception {
when(authorizationServiceMock.isURLRuleAllowed(NOT_RELEVANT, NOT_RELEVANT, NOT_RELEVANT)).thenReturn(new PolicyDecision(true, EXPIRED_TIMESTAMP)).thenReturn(new PolicyDecision(false, VALID_TIMESTAMP));
// Call once to fill cache
cachingService.isURLRuleAllowed(NOT_RELEVANT, NOT_RELEVANT, NOT_RELEVANT);
PolicyDecision decision = cachingService.isURLRuleAllowed(NOT_RELEVANT, NOT_RELEVANT, NOT_RELEVANT);
assertFalse(decision.isAllowed());
verify(authorizationServiceMock, times(2)).isURLRuleAllowed(NOT_RELEVANT, NOT_RELEVANT, NOT_RELEVANT);
}
use of org.simbasecurity.api.service.thrift.PolicyDecision in project simba-os by cegeka.
the class SimbaAuthorizationCachingServiceTest method shouldNotCallAuthorizationServiceWhenURLRuleCached.
@Test
public void shouldNotCallAuthorizationServiceWhenURLRuleCached() throws Exception {
when(authorizationServiceMock.isURLRuleAllowed(NOT_RELEVANT, NOT_RELEVANT, NOT_RELEVANT)).thenReturn(new PolicyDecision(true, VALID_TIMESTAMP));
// Call once to fill cache
cachingService.isURLRuleAllowed(NOT_RELEVANT, NOT_RELEVANT, NOT_RELEVANT);
PolicyDecision decision = cachingService.isURLRuleAllowed(NOT_RELEVANT, NOT_RELEVANT, NOT_RELEVANT);
assertTrue(decision.isAllowed());
verify(authorizationServiceMock).isURLRuleAllowed(NOT_RELEVANT, NOT_RELEVANT, NOT_RELEVANT);
verifyNoMoreInteractions(authorizationServiceMock);
}
Aggregations