@Test void testSpaceDevelopersCacheNegativeResult() { setUpMocks(true, true, null); when(client.getSpaceDevelopers(Mockito.eq(UUID.fromString(THIRD_SPACE_ID)))).thenReturn(Collections.singletonList(USER_ID)); assertTrue(authorizationChecker.checkPermissions(userInfo, THIRD_SPACE_ID, false)); Mockito.verify(client, Mockito.times(1)) .getSpaceDevelopers(Mockito.eq(UUID.fromString(THIRD_SPACE_ID))); UUID newUserId = UUID.fromString("6c02b5bc-b9b1-38d7-b332-1dfdb2ba85a0"); UserInfo negativeUser = new UserInfo(newUserId.toString(), "newUser", userInfo.getToken()); when(client.getSpaceDevelopers(Mockito.eq(UUID.fromString(THIRD_SPACE_ID)))).thenReturn(List.of(USER_ID, newUserId)); when(clientProvider.getControllerClient(negativeUser.getName())).thenReturn(client); assertTrue(authorizationChecker.checkPermissions(negativeUser, THIRD_SPACE_ID, false)); Mockito.verify(client, Mockito.times(2)) .getSpaceDevelopers(Mockito.eq(UUID.fromString(THIRD_SPACE_ID))); }
boolean checkPermissions(UserInfo userInfo, String orgName, String spaceName, boolean readOnly) { if (hasAdminScope(userInfo)) { return true; } CloudControllerClient client = clientProvider.getControllerClient(userInfo.getName()); UUID userGuid = UUID.fromString(userInfo.getId()); return hasPermissions(client, userGuid, orgName, spaceName, readOnly) && hasAccess(client, orgName, spaceName); }
AuthorizationChecker { boolean checkPermissions(UserInfo userInfo, String orgName, String spaceName, boolean readOnly) { if (hasAdminScope(userInfo)) { return true; } CloudControllerClient client = clientProvider.getControllerClient(userInfo.getName()); UUID userGuid = UUID.fromString(userInfo.getId()); return hasPermissions(client, userGuid, orgName, spaceName, readOnly) && hasAccess(client, orgName, spaceName); } }
AuthorizationChecker { boolean checkPermissions(UserInfo userInfo, String orgName, String spaceName, boolean readOnly) { if (hasAdminScope(userInfo)) { return true; } CloudControllerClient client = clientProvider.getControllerClient(userInfo.getName()); UUID userGuid = UUID.fromString(userInfo.getId()); return hasPermissions(client, userGuid, orgName, spaceName, readOnly) && hasAccess(client, orgName, spaceName); } @Inject  AuthorizationChecker(CloudControllerClientProvider clientProvider, ApplicationConfiguration applicationConfiguration); }
AuthorizationChecker { boolean checkPermissions(UserInfo userInfo, String orgName, String spaceName, boolean readOnly) { if (hasAdminScope(userInfo)) { return true; } CloudControllerClient client = clientProvider.getControllerClient(userInfo.getName()); UUID userGuid = UUID.fromString(userInfo.getId()); return hasPermissions(client, userGuid, orgName, spaceName, readOnly) && hasAccess(client, orgName, spaceName); } @Inject  AuthorizationChecker(CloudControllerClientProvider clientProvider, ApplicationConfiguration applicationConfiguration); void ensureUserIsAuthorized(HttpServletRequest request, UserInfo userInfo, CloudTarget target, String action); void ensureUserIsAuthorized(HttpServletRequest request, UserInfo userInfo, String spaceGuid, String action); ClientHelper getClientHelper(CloudControllerClient client); }
AuthorizationChecker { boolean checkPermissions(UserInfo userInfo, String orgName, String spaceName, boolean readOnly) { if (hasAdminScope(userInfo)) { return true; } CloudControllerClient client = clientProvider.getControllerClient(userInfo.getName()); UUID userGuid = UUID.fromString(userInfo.getId()); return hasPermissions(client, userGuid, orgName, spaceName, readOnly) && hasAccess(client, orgName, spaceName); } @Inject  AuthorizationChecker(CloudControllerClientProvider clientProvider, ApplicationConfiguration applicationConfiguration); void ensureUserIsAuthorized(HttpServletRequest request, UserInfo userInfo, CloudTarget target, String action); void ensureUserIsAuthorized(HttpServletRequest request, UserInfo userInfo, String spaceGuid, String action); ClientHelper getClientHelper(CloudControllerClient client);  }