@Test public void testGetAuthorizationUserUnauthorized() throws RemoteApiException, AuthorizationException { doReturn(integration).when(integrationBridge).getIntegrationById(CONFIGURATION_ID); doReturn(MOCK_SESSION).when(authenticationProxy).getSessionToken(INTEGRATION_TYPE); OAuth1HttpRequestException exception = new OAuth1HttpRequestException("Unauthorized", 401); doThrow(exception).when(integration).isUserAuthorized(anyString(), anyLong()); ResponseEntity response = applicationAuthorizationResource.getUserAuthorizationData( CONFIGURATION_ID, INTEGRATION_URL, null, true); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); }
@GetMapping("/userSession") public ResponseEntity getUserAuthorizationData(@PathVariable String configurationId, @RequestParam(name = "integrationUrl") String integrationUrl, @RequestHeader(value = "Authorization", required = false) String authorizationHeader, @RequestParam(name = "initOAuth", defaultValue = "true") boolean initOAuth) throws RemoteApiException { Long userId = jwtAuthentication.getUserIdFromAuthorizationHeader(configurationId, authorizationHeader); UserAuthorizationData data = new UserAuthorizationData(integrationUrl, userId); try { AuthorizedIntegration authIntegration = getAuthorizedIntegration(configurationId); if (!authIntegration.isUserAuthorized(integrationUrl, userId)) { ErrorResponse response = new ErrorResponse(); response.setStatus(HttpStatus.UNAUTHORIZED.value()); if (initOAuth) { String authorizationUrl = authIntegration.getAuthorizationUrl(integrationUrl, userId); Map<String, String> properties = new HashMap<>(); properties.put("authorizationUrl", authorizationUrl); response.setProperties(properties); } return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response); } } catch (OAuth1HttpRequestException e) { int code = e.getCode(); ErrorResponse response = new ErrorResponse(code, e.getMessage()); return ResponseEntity.status(code).body(response); } catch (AuthorizationException e) { ErrorResponse response = new ErrorResponse( HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } return ResponseEntity.ok().body(data); }
ApplicationAuthorizationResource { @GetMapping("/userSession") public ResponseEntity getUserAuthorizationData(@PathVariable String configurationId, @RequestParam(name = "integrationUrl") String integrationUrl, @RequestHeader(value = "Authorization", required = false) String authorizationHeader, @RequestParam(name = "initOAuth", defaultValue = "true") boolean initOAuth) throws RemoteApiException { Long userId = jwtAuthentication.getUserIdFromAuthorizationHeader(configurationId, authorizationHeader); UserAuthorizationData data = new UserAuthorizationData(integrationUrl, userId); try { AuthorizedIntegration authIntegration = getAuthorizedIntegration(configurationId); if (!authIntegration.isUserAuthorized(integrationUrl, userId)) { ErrorResponse response = new ErrorResponse(); response.setStatus(HttpStatus.UNAUTHORIZED.value()); if (initOAuth) { String authorizationUrl = authIntegration.getAuthorizationUrl(integrationUrl, userId); Map<String, String> properties = new HashMap<>(); properties.put("authorizationUrl", authorizationUrl); response.setProperties(properties); } return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response); } } catch (OAuth1HttpRequestException e) { int code = e.getCode(); ErrorResponse response = new ErrorResponse(code, e.getMessage()); return ResponseEntity.status(code).body(response); } catch (AuthorizationException e) { ErrorResponse response = new ErrorResponse( HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } return ResponseEntity.ok().body(data); } }
ApplicationAuthorizationResource { @GetMapping("/userSession") public ResponseEntity getUserAuthorizationData(@PathVariable String configurationId, @RequestParam(name = "integrationUrl") String integrationUrl, @RequestHeader(value = "Authorization", required = false) String authorizationHeader, @RequestParam(name = "initOAuth", defaultValue = "true") boolean initOAuth) throws RemoteApiException { Long userId = jwtAuthentication.getUserIdFromAuthorizationHeader(configurationId, authorizationHeader); UserAuthorizationData data = new UserAuthorizationData(integrationUrl, userId); try { AuthorizedIntegration authIntegration = getAuthorizedIntegration(configurationId); if (!authIntegration.isUserAuthorized(integrationUrl, userId)) { ErrorResponse response = new ErrorResponse(); response.setStatus(HttpStatus.UNAUTHORIZED.value()); if (initOAuth) { String authorizationUrl = authIntegration.getAuthorizationUrl(integrationUrl, userId); Map<String, String> properties = new HashMap<>(); properties.put("authorizationUrl", authorizationUrl); response.setProperties(properties); } return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response); } } catch (OAuth1HttpRequestException e) { int code = e.getCode(); ErrorResponse response = new ErrorResponse(code, e.getMessage()); return ResponseEntity.status(code).body(response); } catch (AuthorizationException e) { ErrorResponse response = new ErrorResponse( HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } return ResponseEntity.ok().body(data); } ApplicationAuthorizationResource(IntegrationBridge integrationBridge,
      LogMessageSource logMessage, JwtAuthentication jwtAuthentication); }
ApplicationAuthorizationResource { @GetMapping("/userSession") public ResponseEntity getUserAuthorizationData(@PathVariable String configurationId, @RequestParam(name = "integrationUrl") String integrationUrl, @RequestHeader(value = "Authorization", required = false) String authorizationHeader, @RequestParam(name = "initOAuth", defaultValue = "true") boolean initOAuth) throws RemoteApiException { Long userId = jwtAuthentication.getUserIdFromAuthorizationHeader(configurationId, authorizationHeader); UserAuthorizationData data = new UserAuthorizationData(integrationUrl, userId); try { AuthorizedIntegration authIntegration = getAuthorizedIntegration(configurationId); if (!authIntegration.isUserAuthorized(integrationUrl, userId)) { ErrorResponse response = new ErrorResponse(); response.setStatus(HttpStatus.UNAUTHORIZED.value()); if (initOAuth) { String authorizationUrl = authIntegration.getAuthorizationUrl(integrationUrl, userId); Map<String, String> properties = new HashMap<>(); properties.put("authorizationUrl", authorizationUrl); response.setProperties(properties); } return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response); } } catch (OAuth1HttpRequestException e) { int code = e.getCode(); ErrorResponse response = new ErrorResponse(code, e.getMessage()); return ResponseEntity.status(code).body(response); } catch (AuthorizationException e) { ErrorResponse response = new ErrorResponse( HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } return ResponseEntity.ok().body(data); } ApplicationAuthorizationResource(IntegrationBridge integrationBridge,
      LogMessageSource logMessage, JwtAuthentication jwtAuthentication); @GetMapping ResponseEntity<AppAuthorizationModel> getAuthorizationProperties(
      @PathVariable String configurationId); @GetMapping("/userSession") ResponseEntity getUserAuthorizationData(@PathVariable String configurationId,
      @RequestParam(name = "integrationUrl") String integrationUrl,
      @RequestHeader(value = "Authorization", required = false) String authorizationHeader,
      @RequestParam(name = "initOAuth", defaultValue = "true") boolean initOAuth); @RequestMapping(value = "/authorize") ResponseEntity authorize(@PathVariable String configurationId, HttpServletRequest request,
      @RequestBody(required = false) String body); }
ApplicationAuthorizationResource { @GetMapping("/userSession") public ResponseEntity getUserAuthorizationData(@PathVariable String configurationId, @RequestParam(name = "integrationUrl") String integrationUrl, @RequestHeader(value = "Authorization", required = false) String authorizationHeader, @RequestParam(name = "initOAuth", defaultValue = "true") boolean initOAuth) throws RemoteApiException { Long userId = jwtAuthentication.getUserIdFromAuthorizationHeader(configurationId, authorizationHeader); UserAuthorizationData data = new UserAuthorizationData(integrationUrl, userId); try { AuthorizedIntegration authIntegration = getAuthorizedIntegration(configurationId); if (!authIntegration.isUserAuthorized(integrationUrl, userId)) { ErrorResponse response = new ErrorResponse(); response.setStatus(HttpStatus.UNAUTHORIZED.value()); if (initOAuth) { String authorizationUrl = authIntegration.getAuthorizationUrl(integrationUrl, userId); Map<String, String> properties = new HashMap<>(); properties.put("authorizationUrl", authorizationUrl); response.setProperties(properties); } return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response); } } catch (OAuth1HttpRequestException e) { int code = e.getCode(); ErrorResponse response = new ErrorResponse(code, e.getMessage()); return ResponseEntity.status(code).body(response); } catch (AuthorizationException e) { ErrorResponse response = new ErrorResponse( HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } return ResponseEntity.ok().body(data); } ApplicationAuthorizationResource(IntegrationBridge integrationBridge,
      LogMessageSource logMessage, JwtAuthentication jwtAuthentication); @GetMapping ResponseEntity<AppAuthorizationModel> getAuthorizationProperties(
      @PathVariable String configurationId); @GetMapping("/userSession") ResponseEntity getUserAuthorizationData(@PathVariable String configurationId,
      @RequestParam(name = "integrationUrl") String integrationUrl,
      @RequestHeader(value = "Authorization", required = false) String authorizationHeader,
      @RequestParam(name = "initOAuth", defaultValue = "true") boolean initOAuth); @RequestMapping(value = "/authorize") ResponseEntity authorize(@PathVariable String configurationId, HttpServletRequest request,
      @RequestBody(required = false) String body);  }