Tabnine Logo
HasPermissionInterceptor
Code IndexAdd Tabnine to your IDE (free)

How to use
HasPermissionInterceptor
in
ch.puzzle.itc.mobiliar.business.security.interceptor

Best Java code snippets using ch.puzzle.itc.mobiliar.business.security.interceptor.HasPermissionInterceptor (Showing top 12 results out of 315)

origin: liimaorg/liima

private static boolean hasResourceSpecific(InvocationContext context) {
  HasPermission permissionMethodAnnotation = getMethodPermissionAnnotation(context);
  return permissionMethodAnnotation != null && permissionMethodAnnotation.resourceSpecific();
}
origin: liimaorg/liima

@AroundInvoke
public Object roleCall(InvocationContext context) throws Exception {
  List<Permission> permissions = getRequiredPermission(context);
  List<Action> actions = getRequiredAction(context);
  boolean resourceSpecific = hasResourceSpecific(context);
  ResourceGroupEntity resourceGroup = null;
origin: liimaorg/liima

@Test
public void shouldCallPermissionServiceWithEveryAnnotatedPermissionAndEveryAnnotatedActions() throws Exception {
  //given
  when(context.getMethod()).thenReturn(TestBoundary.class.getMethod("deployOrCopyFromPermissionActionCreateOrUpdateNeeded"));
  //when
  hasPermissionInterceptor.roleCall(context);
  //then
  verify(hasPermissionInterceptor.permissionService, times(4)).hasPermission(any(Permission.class),
      any(ContextEntity.class), any(Action.class), any(ResourceGroupEntity.class), any(ResourceTypeEntity.class));
  verify(hasPermissionInterceptor.permissionService, times(1)).throwNotAuthorizedException(null);
}
origin: liimaorg/liima

@Test
public void shouldCallPermissionServiceWithPermissionAndEveryAnnotatedActions() throws Exception {
  //given
  when(context.getMethod()).thenReturn(TestBoundary.class.getMethod("deployPermissionActionCreateOrUpdateNeeded"));
  //when
  hasPermissionInterceptor.roleCall(context);
  //then
  verify(hasPermissionInterceptor.permissionService, times(2)).hasPermission(any(Permission.class),
      any(ContextEntity.class), any(Action.class), any(ResourceGroupEntity.class), any(ResourceTypeEntity.class));
  verify(hasPermissionInterceptor.permissionService, times(1)).throwNotAuthorizedException(null);
}
origin: liimaorg/liima

@Test
public void shouldNotCallPermissionService() throws Exception {
  //given
  when(context.getMethod()).thenReturn(TestBoundary.class.getMethod("noPermissionNeeded"));
  //when
  hasPermissionInterceptor.roleCall(context);
  //then
  verify(hasPermissionInterceptor.permissionService, never()).hasPermission(any(Permission.class),
      any(ContextEntity.class), any(Action.class), any(ResourceGroupEntity.class), any(ResourceTypeEntity.class));
  verify(hasPermissionInterceptor.permissionService, never()).throwNotAuthorizedException(null);
}
origin: liimaorg/liima

private static List<Action> getRequiredAction(InvocationContext context) {
  HasPermission permissionMethodAnnotation = getMethodPermissionAnnotation(context);
  List<Action> actions = new ArrayList<>();
  if (permissionMethodAnnotation != null) {
    if (!permissionMethodAnnotation.action().equals(Action.NULL)) {
      actions.add(permissionMethodAnnotation.action());
    }
    if (permissionMethodAnnotation.oneOfAction().length > 0) {
      Collections.addAll(actions, permissionMethodAnnotation.oneOfAction());
    }
  }
  return actions;
}
origin: liimaorg/liima

@Test
public void shouldCallPermissionServiceWithPermission() throws Exception {
  //given
  when(context.getMethod()).thenReturn(TestBoundary.class.getMethod("deployPermissionNeeded"));
  //when
  hasPermissionInterceptor.roleCall(context);
  //then
  verify(hasPermissionInterceptor.permissionService, times(1)).hasPermission(Permission.DEPLOYMENT, null, null ,null, null);
  verify(hasPermissionInterceptor.permissionService, times(1)).throwNotAuthorizedException(null);
}
origin: liimaorg/liima

private static List<Permission> getRequiredPermission(InvocationContext context) {
  HasPermission permissionMethodAnnotation = getMethodPermissionAnnotation(context);
  List<Permission> permissions = new ArrayList<>();
  if (permissionMethodAnnotation != null) {
    if (!permissionMethodAnnotation.permission().equals(Permission.DEFAULT)) {
      permissions.add(permissionMethodAnnotation.permission());
    }
    if (permissionMethodAnnotation.oneOfPermission().length > 0) {
      Collections.addAll(permissions, permissionMethodAnnotation.oneOfPermission());
    }
  }
  return permissions;
}
origin: liimaorg/liima

@Test
public void shouldCallPermissionServiceWithPermissionAndAction() throws Exception {
  //given
  when(context.getMethod()).thenReturn(TestBoundary.class.getMethod("deployPermissionActionCreateNeeded"));
  //when
  hasPermissionInterceptor.roleCall(context);
  //then
  verify(hasPermissionInterceptor.permissionService, times(1)).hasPermission(Permission.DEPLOYMENT, null, Action.CREATE, null, null);
  verify(hasPermissionInterceptor.permissionService, times(1)).throwNotAuthorizedException(null);
}
origin: liimaorg/liima

@Test
public void shouldCallPermissionServiceWithPermissionAndActionButSkipAsSoonAsACheckReturnsTrue() throws Exception {
  //given
  when(context.getMethod()).thenReturn(TestBoundary.class.getMethod("deployPermissionActionCreateOrUpdateNeeded"));
  when(hasPermissionInterceptor.permissionService.hasPermission(Permission.DEPLOYMENT, null, Action.CREATE, null, null)).thenReturn(true);
  //when
  hasPermissionInterceptor.roleCall(context);
  //then
  verify(hasPermissionInterceptor.permissionService, times(1)).hasPermission(Permission.DEPLOYMENT, null, Action.CREATE, null, null);
  verify(hasPermissionInterceptor.permissionService, never()).hasPermission(Permission.DEPLOYMENT, null, Action.UPDATE, null, null);
  verify(hasPermissionInterceptor.permissionService, never()).throwNotAuthorizedException(null);
}
origin: liimaorg/liima

@Test
public void shouldCallPermissionServiceWithMultipleAnnotatedPermissionsAndActionsButSkipAsSoonACheckReturnsTrue() throws Exception {
  //given
  when(context.getMethod()).thenReturn(TestBoundary.class.getMethod("deployOrCopyFromPermissionActionCreateOrUpdateNeeded"));
  when(hasPermissionInterceptor.permissionService.hasPermission(Permission.RESOURCE_RELEASE_COPY_FROM_RESOURCE, null, Action.UPDATE, null, null)).thenReturn(true);
  //when
  hasPermissionInterceptor.roleCall(context);
  //then
  verify(hasPermissionInterceptor.permissionService, times(1)).hasPermission(Permission.RESOURCE_RELEASE_COPY_FROM_RESOURCE, null, Action.CREATE, null, null);
  verify(hasPermissionInterceptor.permissionService, times(1)).hasPermission(Permission.RESOURCE_RELEASE_COPY_FROM_RESOURCE, null, Action.UPDATE, null, null);
  verify(hasPermissionInterceptor.permissionService, never()).hasPermission(Permission.DEPLOYMENT, null, Action.CREATE, null, null);
  verify(hasPermissionInterceptor.permissionService, never()).hasPermission(Permission.DEPLOYMENT, null, Action.UPDATE, null, null);
  verify(hasPermissionInterceptor.permissionService, never()).throwNotAuthorizedException(null);
}
origin: liimaorg/liima

@Test
public void shouldCallPermissionServiceWithPermissionsAndResource() throws Exception {
  //given
  ResourceEntity resource = new ResourceEntity();
  ResourceGroupEntity resGroup = new ResourceGroupEntity();
  resource.setResourceGroup(resGroup);
  ResourceEntity[] resources = {resource};
  context.setParameters(resources);
  when(context.getMethod()).thenReturn(TestBoundary.class.getMethod("deployPermissionActionCreateForSpecificResourceNeeded"));
  when(context.getParameters()).thenReturn(resources);
  when(hasPermissionInterceptor.permissionService.hasPermission(Permission.DEPLOYMENT, null, Action.CREATE, resGroup, null)).thenReturn(true);
  //when
  hasPermissionInterceptor.roleCall(context);
  //then
  verify(hasPermissionInterceptor.permissionService, times(1)).hasPermission(Permission.DEPLOYMENT, null, Action.CREATE, resGroup, null);
  verify(hasPermissionInterceptor.permissionService, never()).throwNotAuthorizedException(null);
}
ch.puzzle.itc.mobiliar.business.security.interceptorHasPermissionInterceptor

Most used methods

  • getMethodPermissionAnnotation
  • getRequiredAction
  • getRequiredPermission
  • hasResourceSpecific
  • roleCall

Popular in Java

  • Updating database using SQL prepared statement
  • onCreateOptionsMenu (Activity)
  • setScale (BigDecimal)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now