-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMalwareURLController.java
67 lines (61 loc) · 2.55 KB
/
MalwareURLController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.cisco.exercise.web;
import com.cisco.exercise.domain.exception.InvalidURLException;
import com.cisco.exercise.service.MalwareURLService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/urlinfo")
@Slf4j
public class MalwareURLController {
private final MalwareURLService malwareURLService;
@Autowired
public MalwareURLController(MalwareURLService malwareURLService) {
this.malwareURLService = malwareURLService;
}
/**
* API endpoint to check whether input URL is present in Malware database
* @param domain Domain name along with port
* @param originalPath Resource path of original URL.
* @param queryParameters Query parameters of original URL.
* @return Response entity with HTTP status 200(OK) if input URL is not part of Malware database otherwise
* 403(Forbidden)
*/
@GetMapping(value = {"/1/{domain}", "/1/{domain}/{originalPath}"})
@ResponseBody
public ResponseEntity validateURL(
@PathVariable @NonNull String domain,
@PathVariable(required = false) String originalPath,
@RequestParam final MultiValueMap<String, String> queryParameters
) {
log.info("Domain: {} and Resource Path: {}", domain, originalPath);
malwareURLService.validateURL(domain, originalPath, queryParameters);
return new ResponseEntity(HttpStatus.OK);
}
/**
* Exception handler for InvalidURLException
* @param e
* @return Response entity with HTTP status 403(Forbidden)
*/
@ExceptionHandler
@ResponseStatus(HttpStatus.FORBIDDEN)
@ResponseBody
public ResponseEntity handleException(final InvalidURLException e) {
return new ResponseEntity(HttpStatus.FORBIDDEN);
}
@PostMapping(value = {"/1/{domain}", "/1/{domain}/{originalPath}"})
@ResponseBody
public ResponseEntity addURL(
@PathVariable @NonNull String domain,
@PathVariable(required = false) String originalPath,
@RequestParam final MultiValueMap<String, String> queryParameters
) {
log.info("Domain: {} and Resource Path: {}", domain, originalPath);
malwareURLService.addURL(domain, originalPath, queryParameters);
return new ResponseEntity(HttpStatus.CREATED);
}
}