@Test public void testRequestIsNotAuthorized() { when(authentication.isAuthenticated()).thenReturn(false); boolean result = underTest.hasPermission(authentication, null, ""); Assert.assertTrue(result); }
@Override public boolean hasPermission(Authentication authentication, Object target, Object permission) { if (!authentication.isAuthenticated()) { return true; } if (target instanceof Optional) { target = ((Optional<?>) target).orElse(null); } if (target == null) { return false; } CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser(); Collection<?> targets = target instanceof Collection ? (Collection<?>) target : Collections.singleton(target); return targets.stream().allMatch(t -> { if (!(t instanceof Clustered)) { return true; } Cluster cluster = ((Clustered) t).getCluster(); if (cluster == null || !cloudbreakUser.getTenant().contentEquals(cluster.getClusterPertain().getTenant())) { return false; } cloudbreakAuthorizationService.hasAccess(cluster.getStackCrn(), cloudbreakUser.getUserId(), cloudbreakUser.getTenant(), permission.toString()); return true; }); }
TenantBasedPermissionEvaluator implements PermissionEvaluator { @Override public boolean hasPermission(Authentication authentication, Object target, Object permission) { if (!authentication.isAuthenticated()) { return true; } if (target instanceof Optional) { target = ((Optional<?>) target).orElse(null); } if (target == null) { return false; } CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser(); Collection<?> targets = target instanceof Collection ? (Collection<?>) target : Collections.singleton(target); return targets.stream().allMatch(t -> { if (!(t instanceof Clustered)) { return true; } Cluster cluster = ((Clustered) t).getCluster(); if (cluster == null || !cloudbreakUser.getTenant().contentEquals(cluster.getClusterPertain().getTenant())) { return false; } cloudbreakAuthorizationService.hasAccess(cluster.getStackCrn(), cloudbreakUser.getUserId(), cloudbreakUser.getTenant(), permission.toString()); return true; }); } }
TenantBasedPermissionEvaluator implements PermissionEvaluator { @Override public boolean hasPermission(Authentication authentication, Object target, Object permission) { if (!authentication.isAuthenticated()) { return true; } if (target instanceof Optional) { target = ((Optional<?>) target).orElse(null); } if (target == null) { return false; } CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser(); Collection<?> targets = target instanceof Collection ? (Collection<?>) target : Collections.singleton(target); return targets.stream().allMatch(t -> { if (!(t instanceof Clustered)) { return true; } Cluster cluster = ((Clustered) t).getCluster(); if (cluster == null || !cloudbreakUser.getTenant().contentEquals(cluster.getClusterPertain().getTenant())) { return false; } cloudbreakAuthorizationService.hasAccess(cluster.getStackCrn(), cloudbreakUser.getUserId(), cloudbreakUser.getTenant(), permission.toString()); return true; }); }  }
TenantBasedPermissionEvaluator implements PermissionEvaluator { @Override public boolean hasPermission(Authentication authentication, Object target, Object permission) { if (!authentication.isAuthenticated()) { return true; } if (target instanceof Optional) { target = ((Optional<?>) target).orElse(null); } if (target == null) { return false; } CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser(); Collection<?> targets = target instanceof Collection ? (Collection<?>) target : Collections.singleton(target); return targets.stream().allMatch(t -> { if (!(t instanceof Clustered)) { return true; } Cluster cluster = ((Clustered) t).getCluster(); if (cluster == null || !cloudbreakUser.getTenant().contentEquals(cluster.getClusterPertain().getTenant())) { return false; } cloudbreakAuthorizationService.hasAccess(cluster.getStackCrn(), cloudbreakUser.getUserId(), cloudbreakUser.getTenant(), permission.toString()); return true; }); }  @Override boolean hasPermission(Authentication authentication, Object target, Object permission); @Override boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission); }
TenantBasedPermissionEvaluator implements PermissionEvaluator { @Override public boolean hasPermission(Authentication authentication, Object target, Object permission) { if (!authentication.isAuthenticated()) { return true; } if (target instanceof Optional) { target = ((Optional<?>) target).orElse(null); } if (target == null) { return false; } CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser(); Collection<?> targets = target instanceof Collection ? (Collection<?>) target : Collections.singleton(target); return targets.stream().allMatch(t -> { if (!(t instanceof Clustered)) { return true; } Cluster cluster = ((Clustered) t).getCluster(); if (cluster == null || !cloudbreakUser.getTenant().contentEquals(cluster.getClusterPertain().getTenant())) { return false; } cloudbreakAuthorizationService.hasAccess(cluster.getStackCrn(), cloudbreakUser.getUserId(), cloudbreakUser.getTenant(), permission.toString()); return true; }); }  @Override boolean hasPermission(Authentication authentication, Object target, Object permission); @Override boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission);  }