Search in sources :

Example 11 with ForbiddenAccessException

use of io.gravitee.rest.api.service.exceptions.ForbiddenAccessException in project gravitee-management-rest-api by gravitee-io.

the class PermissionFilterTest method shouldThrowForbiddenExceptionWhenNoApplicationPermissions.

@Test(expected = ForbiddenAccessException.class)
public void shouldThrowForbiddenExceptionWhenNoApplicationPermissions() {
    ApplicationEntity application = initApplicationMocks();
    when(roleService.hasPermission(any(), any(), any())).thenReturn(false);
    try {
        permissionFilter.filter(permissions, containerRequestContext);
    } catch (ForbiddenAccessException e) {
        verify(applicationService, times(1)).findById(application.getId());
        verify(apiService, never()).findById(any());
        verify(roleService, times(1)).hasPermission(any(), any(), any());
        verify(membershipService, times(1)).getUserMemberPermissions(application, USERNAME);
        verify(membershipService, never()).getRoles(any(), any(), any(), any());
        throw e;
    }
    Assert.fail("Should throw a ForbiddenAccessException");
}
Also used : ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) ForbiddenAccessException(io.gravitee.rest.api.service.exceptions.ForbiddenAccessException) Test(org.junit.Test)

Aggregations

ForbiddenAccessException (io.gravitee.rest.api.service.exceptions.ForbiddenAccessException)11 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)4 Test (org.junit.Test)4 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)3 SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)3 RolePermission (io.gravitee.rest.api.model.permissions.RolePermission)3 RolePermissionAction (io.gravitee.rest.api.model.permissions.RolePermissionAction)3 Subscription (io.gravitee.rest.api.portal.rest.model.Subscription)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 Context (javax.ws.rs.core.Context)3 MediaType (io.gravitee.common.http.MediaType)2 SubscriptionQuery (io.gravitee.rest.api.model.subscription.SubscriptionQuery)2 Key (io.gravitee.rest.api.portal.rest.model.Key)2 io.swagger.annotations (io.swagger.annotations)2 ResourceContext (javax.ws.rs.container.ResourceContext)2 UserDetails (io.gravitee.rest.api.idp.api.authentication.UserDetails)1 Permission (io.gravitee.rest.api.management.rest.security.Permission)1 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)1 HttpHeadersUtil (io.gravitee.rest.api.management.rest.utils.HttpHeadersUtil)1