@Test public void testValidateTokensInvalid() { doReturn(false).when(jwtAuthentication).isValidTokenPair(CONFIGURATION_ID, MOCK_APP_TOKEN, MOCK_SYMPHONY_TOKEN); ResponseEntity response = appAuthenticationResource.validateTokens(CONFIGURATION_ID, REQUEST_VALIDATE_TOKENS); ErrorResponse errorResponse = (ErrorResponse) response.getBody(); assertEquals(HttpStatus.UNAUTHORIZED.value(), errorResponse.getStatus()); }
@PostMapping(value = "/tokens/validate") public ResponseEntity validateTokens(@PathVariable String configurationId, @RequestBody String body) { JsonNode node = getJsonNode(APPLICATION_TOKEN, VALIDATE_TOKENS, body); String applicationToken = node.path(APPLICATION_TOKEN).asText(); String symphonyToken = node.path(SYMPHONY_TOKEN).asText(); validateRequiredParameter(applicationToken, APPLICATION_TOKEN, VALIDATE_TOKENS); validateRequiredParameter(symphonyToken, SYMPHONY_TOKEN, VALIDATE_TOKENS); boolean isValid = jwtAuthentication.isValidTokenPair(configurationId, applicationToken, symphonyToken); if (isValid) { String component = getIntegrationComponent(configurationId); AppToken appToken = new AppToken(component, applicationToken, symphonyToken); return ResponseEntity.ok().body(appToken); } ErrorResponse response = new ErrorResponse( HttpStatus.UNAUTHORIZED.value(), logMessage.getMessage(UNAUTHORIZED_PAIR, applicationToken, symphonyToken)); return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response); }
ApplicationAuthenticationResource { @PostMapping(value = "/tokens/validate") public ResponseEntity validateTokens(@PathVariable String configurationId, @RequestBody String body) { JsonNode node = getJsonNode(APPLICATION_TOKEN, VALIDATE_TOKENS, body); String applicationToken = node.path(APPLICATION_TOKEN).asText(); String symphonyToken = node.path(SYMPHONY_TOKEN).asText(); validateRequiredParameter(applicationToken, APPLICATION_TOKEN, VALIDATE_TOKENS); validateRequiredParameter(symphonyToken, SYMPHONY_TOKEN, VALIDATE_TOKENS); boolean isValid = jwtAuthentication.isValidTokenPair(configurationId, applicationToken, symphonyToken); if (isValid) { String component = getIntegrationComponent(configurationId); AppToken appToken = new AppToken(component, applicationToken, symphonyToken); return ResponseEntity.ok().body(appToken); } ErrorResponse response = new ErrorResponse( HttpStatus.UNAUTHORIZED.value(), logMessage.getMessage(UNAUTHORIZED_PAIR, applicationToken, symphonyToken)); return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response); } }
ApplicationAuthenticationResource { @PostMapping(value = "/tokens/validate") public ResponseEntity validateTokens(@PathVariable String configurationId, @RequestBody String body) { JsonNode node = getJsonNode(APPLICATION_TOKEN, VALIDATE_TOKENS, body); String applicationToken = node.path(APPLICATION_TOKEN).asText(); String symphonyToken = node.path(SYMPHONY_TOKEN).asText(); validateRequiredParameter(applicationToken, APPLICATION_TOKEN, VALIDATE_TOKENS); validateRequiredParameter(symphonyToken, SYMPHONY_TOKEN, VALIDATE_TOKENS); boolean isValid = jwtAuthentication.isValidTokenPair(configurationId, applicationToken, symphonyToken); if (isValid) { String component = getIntegrationComponent(configurationId); AppToken appToken = new AppToken(component, applicationToken, symphonyToken); return ResponseEntity.ok().body(appToken); } ErrorResponse response = new ErrorResponse( HttpStatus.UNAUTHORIZED.value(), logMessage.getMessage(UNAUTHORIZED_PAIR, applicationToken, symphonyToken)); return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response); }  }
ApplicationAuthenticationResource { @PostMapping(value = "/tokens/validate") public ResponseEntity validateTokens(@PathVariable String configurationId, @RequestBody String body) { JsonNode node = getJsonNode(APPLICATION_TOKEN, VALIDATE_TOKENS, body); String applicationToken = node.path(APPLICATION_TOKEN).asText(); String symphonyToken = node.path(SYMPHONY_TOKEN).asText(); validateRequiredParameter(applicationToken, APPLICATION_TOKEN, VALIDATE_TOKENS); validateRequiredParameter(symphonyToken, SYMPHONY_TOKEN, VALIDATE_TOKENS); boolean isValid = jwtAuthentication.isValidTokenPair(configurationId, applicationToken, symphonyToken); if (isValid) { String component = getIntegrationComponent(configurationId); AppToken appToken = new AppToken(component, applicationToken, symphonyToken); return ResponseEntity.ok().body(appToken); } ErrorResponse response = new ErrorResponse( HttpStatus.UNAUTHORIZED.value(), logMessage.getMessage(UNAUTHORIZED_PAIR, applicationToken, symphonyToken)); return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response); }  @PostMapping(value = "/authenticate") ResponseEntity authenticate(@PathVariable String configurationId,
      @RequestBody String body); @PostMapping(value = "/validate") ResponseEntity validate(@PathVariable String configurationId, @RequestBody String body); @PostMapping(value = "/tokens/validate") ResponseEntity validateTokens(@PathVariable String configurationId,
      @RequestBody String body); }
ApplicationAuthenticationResource { @PostMapping(value = "/tokens/validate") public ResponseEntity validateTokens(@PathVariable String configurationId, @RequestBody String body) { JsonNode node = getJsonNode(APPLICATION_TOKEN, VALIDATE_TOKENS, body); String applicationToken = node.path(APPLICATION_TOKEN).asText(); String symphonyToken = node.path(SYMPHONY_TOKEN).asText(); validateRequiredParameter(applicationToken, APPLICATION_TOKEN, VALIDATE_TOKENS); validateRequiredParameter(symphonyToken, SYMPHONY_TOKEN, VALIDATE_TOKENS); boolean isValid = jwtAuthentication.isValidTokenPair(configurationId, applicationToken, symphonyToken); if (isValid) { String component = getIntegrationComponent(configurationId); AppToken appToken = new AppToken(component, applicationToken, symphonyToken); return ResponseEntity.ok().body(appToken); } ErrorResponse response = new ErrorResponse( HttpStatus.UNAUTHORIZED.value(), logMessage.getMessage(UNAUTHORIZED_PAIR, applicationToken, symphonyToken)); return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response); }  @PostMapping(value = "/authenticate") ResponseEntity authenticate(@PathVariable String configurationId,
      @RequestBody String body); @PostMapping(value = "/validate") ResponseEntity validate(@PathVariable String configurationId, @RequestBody String body); @PostMapping(value = "/tokens/validate") ResponseEntity validateTokens(@PathVariable String configurationId,
      @RequestBody String body);  }