@Test public void testAuthorize() throws RemoteApiException, AuthorizationException { doReturn(integration).when(integrationBridge).getIntegrationById(CONFIGURATION_ID); doReturn(MOCK_SESSION).when(authenticationProxy).getSessionToken(INTEGRATION_TYPE); Enumeration parameters = new StringTokenizer("param1\tparam2"); doReturn(parameters).when(httpRequest).getParameterNames(); doReturn("value").when(httpRequest).getParameter(anyString()); Enumeration headers = new StringTokenizer("param1\tparam2"); doReturn(headers).when(httpRequest).getHeaderNames(); doReturn("value").when(httpRequest).getHeader(anyString()); applicationAuthorizationResource.authorize(CONFIGURATION_ID, httpRequest, null); }
@RequestMapping(value = "/authorize") public ResponseEntity authorize(@PathVariable String configurationId, HttpServletRequest request, @RequestBody(required = false) String body) throws RemoteApiException { AuthorizedIntegration authIntegration = getAuthorizedIntegration(configurationId); AuthorizationPayload authPayload = getAuthorizationPayload(request, body); String url; try { authIntegration.authorize(authPayload); url = authIntegration.getAuthorizationRedirectUrl(); } catch (OAuth1MissingParametersException e) { ErrorResponse response = new ErrorResponse( HttpStatus.BAD_REQUEST.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); } catch (OAuth1IntegrationNotFoundException e) { ErrorResponse response = new ErrorResponse( HttpStatus.NOT_FOUND.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.NOT_FOUND).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); } if (StringUtils.isNotEmpty(url)) { return ResponseEntity.status(HttpStatus.MOVED_PERMANENTLY).header("Location", url).build(); } return ResponseEntity.ok().build(); }
ApplicationAuthorizationResource { @RequestMapping(value = "/authorize") public ResponseEntity authorize(@PathVariable String configurationId, HttpServletRequest request, @RequestBody(required = false) String body) throws RemoteApiException { AuthorizedIntegration authIntegration = getAuthorizedIntegration(configurationId); AuthorizationPayload authPayload = getAuthorizationPayload(request, body); String url; try { authIntegration.authorize(authPayload); url = authIntegration.getAuthorizationRedirectUrl(); } catch (OAuth1MissingParametersException e) { ErrorResponse response = new ErrorResponse( HttpStatus.BAD_REQUEST.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); } catch (OAuth1IntegrationNotFoundException e) { ErrorResponse response = new ErrorResponse( HttpStatus.NOT_FOUND.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.NOT_FOUND).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); } if (StringUtils.isNotEmpty(url)) { return ResponseEntity.status(HttpStatus.MOVED_PERMANENTLY).header("Location", url).build(); } return ResponseEntity.ok().build(); } }
ApplicationAuthorizationResource { @RequestMapping(value = "/authorize") public ResponseEntity authorize(@PathVariable String configurationId, HttpServletRequest request, @RequestBody(required = false) String body) throws RemoteApiException { AuthorizedIntegration authIntegration = getAuthorizedIntegration(configurationId); AuthorizationPayload authPayload = getAuthorizationPayload(request, body); String url; try { authIntegration.authorize(authPayload); url = authIntegration.getAuthorizationRedirectUrl(); } catch (OAuth1MissingParametersException e) { ErrorResponse response = new ErrorResponse( HttpStatus.BAD_REQUEST.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); } catch (OAuth1IntegrationNotFoundException e) { ErrorResponse response = new ErrorResponse( HttpStatus.NOT_FOUND.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.NOT_FOUND).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); } if (StringUtils.isNotEmpty(url)) { return ResponseEntity.status(HttpStatus.MOVED_PERMANENTLY).header("Location", url).build(); } return ResponseEntity.ok().build(); } ApplicationAuthorizationResource(IntegrationBridge integrationBridge,
      LogMessageSource logMessage, JwtAuthentication jwtAuthentication); }
ApplicationAuthorizationResource { @RequestMapping(value = "/authorize") public ResponseEntity authorize(@PathVariable String configurationId, HttpServletRequest request, @RequestBody(required = false) String body) throws RemoteApiException { AuthorizedIntegration authIntegration = getAuthorizedIntegration(configurationId); AuthorizationPayload authPayload = getAuthorizationPayload(request, body); String url; try { authIntegration.authorize(authPayload); url = authIntegration.getAuthorizationRedirectUrl(); } catch (OAuth1MissingParametersException e) { ErrorResponse response = new ErrorResponse( HttpStatus.BAD_REQUEST.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); } catch (OAuth1IntegrationNotFoundException e) { ErrorResponse response = new ErrorResponse( HttpStatus.NOT_FOUND.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.NOT_FOUND).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); } if (StringUtils.isNotEmpty(url)) { return ResponseEntity.status(HttpStatus.MOVED_PERMANENTLY).header("Location", url).build(); } return ResponseEntity.ok().build(); } 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 { @RequestMapping(value = "/authorize") public ResponseEntity authorize(@PathVariable String configurationId, HttpServletRequest request, @RequestBody(required = false) String body) throws RemoteApiException { AuthorizedIntegration authIntegration = getAuthorizedIntegration(configurationId); AuthorizationPayload authPayload = getAuthorizationPayload(request, body); String url; try { authIntegration.authorize(authPayload); url = authIntegration.getAuthorizationRedirectUrl(); } catch (OAuth1MissingParametersException e) { ErrorResponse response = new ErrorResponse( HttpStatus.BAD_REQUEST.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); } catch (OAuth1IntegrationNotFoundException e) { ErrorResponse response = new ErrorResponse( HttpStatus.NOT_FOUND.value(), e.getMessage()); return ResponseEntity.status(HttpStatus.NOT_FOUND).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); } if (StringUtils.isNotEmpty(url)) { return ResponseEntity.status(HttpStatus.MOVED_PERMANENTLY).header("Location", url).build(); } return ResponseEntity.ok().build(); } 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);  }