package adt.mainnode.controller; import adt.mainnode.dto.Asset; import adt.mainnode.entity.Credentials; import adt.mainnode.entity.PortDetection; import adt.mainnode.repository.CredentialsRepository; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; @RestController @RequestMapping("sniffing") @Api( value = "/sniffing", tags = {"Add data to sniffing snapshots"} ) @Slf4j public class NewPortController { private final CredentialsRepository credentialsRepository; @Autowired public NewPortController(CredentialsRepository credentialsRepository) { this.credentialsRepository = credentialsRepository; } @CrossOrigin @ApiOperation(value = "Save a new set of a list of new ports", response = Long.class) @ResponseStatus(HttpStatus.CREATED) @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) Long saveAssets(HttpServletResponse response, @RequestBody Asset asset, @RequestParam String token) { Credentials credential = credentialsRepository.findByToken(token); if(credential != null && credential.getStatus().equals("OPERATIVE")) { if(credential.getAvailableEndpoint().contains("(POST) sniffing/")) { log.info("New assets received"); //Guardar la lista return null; } } try { response.sendError(400, "Unrecognized token. Access denied."); }catch(IOException ioe){ // } return null; } }