Commit f3e74372 authored by Begnini StopCovid's avatar Begnini StopCovid Committed by Deniro StopCovid

delete register (v1) , captcha (v1) , report (v1) , unregister (v1) ,...

delete register (v1) , captcha (v1) , report (v1) , unregister (v1) , deleteHistory (v1) and all tests
parent 2a287c85
......@@ -13,10 +13,10 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import fr.gouv.stopc.robertserver.ws.dto.CaptchaInternalCreationDto;
import fr.gouv.stopc.robertserver.ws.dto.CaptchaCreationDto;
import fr.gouv.stopc.robertserver.ws.exception.RobertServerException;
import fr.gouv.stopc.robertserver.ws.utils.UriConstants;
import fr.gouv.stopc.robertserver.ws.vo.CaptchaInternalCreationVo;
import fr.gouv.stopc.robertserver.ws.vo.CaptchaCreationVo;
@RestController
@RequestMapping(value = {"${controller.path.prefix}" + UriConstants.API_V2})
......@@ -25,8 +25,8 @@ public interface ICaptchaController {
@PostMapping(value = UriConstants.CAPTCHA)
@Consumes(MediaType.APPLICATION_JSON_VALUE)
@Produces(MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<CaptchaInternalCreationDto> createCaptcha(
@Valid @RequestBody(required=true) CaptchaInternalCreationVo captchaInternalCreationVo)
ResponseEntity<CaptchaCreationDto> createCaptcha(
@Valid @RequestBody(required=true) CaptchaCreationVo captchaCreationVo)
throws RobertServerException;
@GetMapping(value = UriConstants.CAPTCHA + "/{captchaId}/image")
......
......@@ -17,7 +17,7 @@ import fr.gouv.stopc.robertserver.ws.utils.UriConstants;
import fr.gouv.stopc.robertserver.ws.vo.DeleteHistoryRequestVo;
@RestController
@RequestMapping(value = {"${controller.path.prefix}" + UriConstants.API_V1, "${controller.path.prefix}" + UriConstants.API_V2,
@RequestMapping(value = {"${controller.path.prefix}" + UriConstants.API_V2,
"${controller.path.prefix}" + UriConstants.API_V3 })
@Consumes(MediaType.APPLICATION_JSON_VALUE)
@Produces(MediaType.APPLICATION_JSON_VALUE)
......
......@@ -4,6 +4,7 @@ import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import fr.gouv.stopc.robertserver.ws.vo.RegisterVo;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -14,10 +15,9 @@ import org.springframework.web.bind.annotation.RestController;
import fr.gouv.stopc.robertserver.ws.dto.RegisterResponseDto;
import fr.gouv.stopc.robertserver.ws.exception.RobertServerException;
import fr.gouv.stopc.robertserver.ws.utils.UriConstants;
import fr.gouv.stopc.robertserver.ws.vo.RegisterVo;
@RestController
@RequestMapping(value = "${controller.path.prefix}" + UriConstants.API_V1)
@RequestMapping(value = {"${controller.path.prefix}" + UriConstants.API_V2, "${controller.path.prefix}" + UriConstants.API_V3})
@Consumes(MediaType.APPLICATION_JSON_VALUE)
@Produces(MediaType.APPLICATION_JSON_VALUE)
public interface IRegisterController {
......
package fr.gouv.stopc.robertserver.ws.controller;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import fr.gouv.stopc.robertserver.ws.dto.RegisterResponseDto;
import fr.gouv.stopc.robertserver.ws.exception.RobertServerException;
import fr.gouv.stopc.robertserver.ws.utils.UriConstants;
import fr.gouv.stopc.robertserver.ws.vo.RegisterInternalVo;
@RestController
@RequestMapping(value = {"${controller.path.prefix}" + UriConstants.API_V2, "${controller.path.prefix}" + UriConstants.API_V3})
@Consumes(MediaType.APPLICATION_JSON_VALUE)
@Produces(MediaType.APPLICATION_JSON_VALUE)
public interface IRegisterInternalController {
@PostMapping(value = UriConstants.REGISTER)
ResponseEntity<RegisterResponseDto> register(@Valid @RequestBody(required=true) RegisterInternalVo registervo)
throws RobertServerException;
}
......@@ -17,7 +17,7 @@ import fr.gouv.stopc.robertserver.ws.utils.UriConstants;
import fr.gouv.stopc.robertserver.ws.vo.ReportBatchRequestVo;
@RestController
@RequestMapping(value = {"${controller.path.prefix}" + UriConstants.API_V1, "${controller.path.prefix}" + UriConstants.API_V2,
@RequestMapping(value = {"${controller.path.prefix}" + UriConstants.API_V2,
"${controller.path.prefix}" + UriConstants.API_V3})
@Consumes(MediaType.APPLICATION_JSON_VALUE)
@Produces(MediaType.APPLICATION_JSON_VALUE)
......
......@@ -16,7 +16,7 @@ import fr.gouv.stopc.robertserver.ws.utils.UriConstants;
import fr.gouv.stopc.robertserver.ws.vo.UnregisterRequestVo;
@RestController
@RequestMapping(value = {"${controller.path.prefix}" + UriConstants.API_V1, "${controller.path.prefix}" + UriConstants.API_V2,
@RequestMapping(value = {"${controller.path.prefix}" + UriConstants.API_V2,
"${controller.path.prefix}" + UriConstants.API_V3})
@Consumes(MediaType.APPLICATION_JSON_VALUE)
@Produces(MediaType.APPLICATION_JSON_VALUE)
......
package fr.gouv.stopc.robertserver.ws.controller.impl;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.bson.internal.Base64;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import com.google.protobuf.ByteString;
import fr.gouv.stopc.robert.crypto.grpc.server.client.service.ICryptoServerGrpcClient;
import fr.gouv.stopc.robert.crypto.grpc.server.messaging.CreateRegistrationRequest;
import fr.gouv.stopc.robert.crypto.grpc.server.messaging.CreateRegistrationResponse;
import fr.gouv.stopc.robert.server.common.service.IServerConfigurationService;
import fr.gouv.stopc.robert.server.common.utils.TimeUtils;
import fr.gouv.stopc.robertserver.database.model.ApplicationConfigurationModel;
import fr.gouv.stopc.robertserver.database.model.Registration;
import fr.gouv.stopc.robertserver.database.service.IApplicationConfigService;
import fr.gouv.stopc.robertserver.database.service.IRegistrationService;
import fr.gouv.stopc.robertserver.ws.config.WsServerConfiguration;
import fr.gouv.stopc.robertserver.ws.dto.ClientConfigDto;
import fr.gouv.stopc.robertserver.ws.dto.RegisterResponseDto;
import fr.gouv.stopc.robertserver.ws.exception.RobertServerException;
import fr.gouv.stopc.robertserver.ws.service.IRestApiService;
import fr.gouv.stopc.robertserver.ws.utils.MessageConstants;
import fr.gouv.stopc.robertserver.ws.vo.RegisterVo;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class AbstractRegisterControllerImpl {
protected IRegistrationService registrationService;
protected IServerConfigurationService serverConfigurationService;
protected IApplicationConfigService applicationConfigService;
protected ICryptoServerGrpcClient cryptoServerClient;
protected IRestApiService restApiService;
protected WsServerConfiguration wsServerConfiguration;
protected ResponseEntity<RegisterResponseDto> postCheckRegister(RegisterVo registerVo) throws RobertServerException {
byte[] clientPublicECDHKey = Base64.decode(registerVo.getClientPublicECDHKey());
byte[] serverCountryCode = new byte[1];
serverCountryCode[0] = this.serverConfigurationService.getServerCountryCode();
CreateRegistrationRequest request = CreateRegistrationRequest.newBuilder()
.setClientPublicKey(ByteString.copyFrom(clientPublicECDHKey))
.setNumberOfDaysForEpochBundles(this.wsServerConfiguration.getEpochBundleDurationInDays())
.setServerCountryCode(ByteString.copyFrom(serverCountryCode))
.setFromEpochId(TimeUtils.getCurrentEpochFrom(this.serverConfigurationService.getServiceTimeStart()))
.build();
Optional<CreateRegistrationResponse> response = this.cryptoServerClient.createRegistration(request);
if(!response.isPresent() || response.get().hasError()) {
log.error("Unable to generate an identity for the client");
throw new RobertServerException(MessageConstants.ERROR_OCCURED);
}
CreateRegistrationResponse identity = response.get();
Registration registration = Registration.builder()
.permanentIdentifier(identity.getIdA().toByteArray())
.build();
Optional<Registration> registered = this.registrationService.saveRegistration(registration);
if (registered.isPresent()) {
RegisterResponseDto registerResponseDto = new RegisterResponseDto();
List<ApplicationConfigurationModel> serverConf = this.applicationConfigService.findAll();
if (CollectionUtils.isEmpty(serverConf)) {
registerResponseDto.setConfig(Collections.emptyList());
} else {
registerResponseDto.setConfig(serverConf
.stream()
.map(item -> ClientConfigDto.builder().name(item.getName()).value(item.getValue()).build())
.collect(Collectors.toList()));
}
registerResponseDto.setTuples(Base64.encode(identity.getTuples().toByteArray()));
registerResponseDto.setTimeStart(this.serverConfigurationService.getServiceTimeStart());
Optional.ofNullable(registerVo.getPushInfo()).ifPresent(this.restApiService::registerPushNotif);
return ResponseEntity.status(HttpStatus.CREATED).body(registerResponseDto);
}
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
}
}
......@@ -16,15 +16,15 @@ import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import fr.gouv.stopc.robertserver.ws.controller.ICaptchaController;
import fr.gouv.stopc.robertserver.ws.dto.CaptchaInternalCreationDto;
import fr.gouv.stopc.robertserver.ws.dto.CaptchaCreationDto;
import fr.gouv.stopc.robertserver.ws.exception.RobertServerException;
import fr.gouv.stopc.robertserver.ws.utils.PropertyLoader;
import fr.gouv.stopc.robertserver.ws.vo.CaptchaInternalCreationVo;
import fr.gouv.stopc.robertserver.ws.vo.CaptchaCreationVo;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
@ConditionalOnProperty("captcha.internal.gateway.enabled")
@ConditionalOnProperty("captcha.gateway.enabled")
  • @begnini-stopcovid Can you explain a bit where this variable is read from? The properties files seem to still mention captcha.internal.gateway.enabled. Thanks!

  • It is from the application.properties, file being inside src/main/resources.

Please register or sign in to reply
public class CaptchaControllerImpl implements ICaptchaController {
private final RestTemplate restTemplate;
......@@ -38,21 +38,21 @@ public class CaptchaControllerImpl implements ICaptchaController {
}
@Override
public ResponseEntity<CaptchaInternalCreationDto> createCaptcha(
@Valid CaptchaInternalCreationVo captchaInternalCreationVo) throws RobertServerException {
public ResponseEntity<CaptchaCreationDto> createCaptcha(
@Valid CaptchaCreationVo captchaCreationVo) throws RobertServerException {
ResponseEntity<CaptchaInternalCreationDto> response = null;
ResponseEntity<CaptchaCreationDto> response = null;
try {
response = restTemplate.postForEntity(
UriComponentsBuilder.fromHttpUrl(
this.propertyLoader.getCaptchaInternalHostname() + "/private/api/v1/captcha").build().toUri(),
captchaInternalCreationVo,
CaptchaInternalCreationDto.class);
this.propertyLoader.getCaptchaHostname() + "/private/api/v1/captcha").build().toUri(),
captchaCreationVo,
CaptchaCreationDto.class);
log.info("Captcha creation response: {}", response);
} catch (RestClientException e) {
log.error("Could not create captcha with type {} and locale {}; {}",
captchaInternalCreationVo.getType(),
captchaInternalCreationVo.getLocale(),
captchaCreationVo.getType(),
captchaCreationVo.getLocale(),
e.getMessage());
return ResponseEntity.badRequest().build();
}
......@@ -76,7 +76,7 @@ public class CaptchaControllerImpl implements ICaptchaController {
try {
URI uri = UriComponentsBuilder.fromHttpUrl(
this.propertyLoader.getCaptchaInternalHostname() + "/public/api/v1/captcha/{captchaId}." + (mediaType == "audio" ? "wav" : "png"))
this.propertyLoader.getCaptchaHostname() + "/public/api/v1/captcha/{captchaId}." + (mediaType == "audio" ? "wav" : "png"))
.build(uriVariables);
log.info("Getting captcha from URL: {}", uri);
......
package fr.gouv.stopc.robertserver.ws.controller.impl;
import javax.inject.Inject;
import javax.validation.Valid;
import com.google.protobuf.ByteString;
import fr.gouv.stopc.robert.crypto.grpc.server.messaging.CreateRegistrationRequest;
import fr.gouv.stopc.robert.crypto.grpc.server.messaging.CreateRegistrationResponse;
import fr.gouv.stopc.robert.server.common.utils.TimeUtils;
import fr.gouv.stopc.robertserver.database.model.ApplicationConfigurationModel;
import fr.gouv.stopc.robertserver.database.model.Registration;
import fr.gouv.stopc.robertserver.ws.dto.ClientConfigDto;
import fr.gouv.stopc.robertserver.ws.utils.MessageConstants;
import fr.gouv.stopc.robertserver.ws.vo.RegisterVo;
import lombok.extern.slf4j.Slf4j;
import org.bson.internal.Base64;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
......@@ -16,21 +28,36 @@ import fr.gouv.stopc.robertserver.ws.dto.RegisterResponseDto;
import fr.gouv.stopc.robertserver.ws.exception.RobertServerException;
import fr.gouv.stopc.robertserver.ws.service.CaptchaService;
import fr.gouv.stopc.robertserver.ws.service.IRestApiService;
import fr.gouv.stopc.robertserver.ws.vo.RegisterVo;
import org.springframework.util.CollectionUtils;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Slf4j
@Service
public class RegisterControllerImpl extends AbstractRegisterControllerImpl implements IRegisterController {
public class RegisterControllerImpl implements IRegisterController {
private IRegistrationService registrationService;
private IServerConfigurationService serverConfigurationService;
private IApplicationConfigService applicationConfigService;
private ICryptoServerGrpcClient cryptoServerClient;
private IRestApiService restApiService;
private WsServerConfiguration wsServerConfiguration;
private final CaptchaService captchaService;
@Inject
public RegisterControllerImpl(final IRegistrationService registrationService,
final IServerConfigurationService serverConfigurationService,
final IApplicationConfigService applicationConfigService,
final CaptchaService captchaService,
final ICryptoServerGrpcClient cryptoServerClient,
final IRestApiService restApiService,
final WsServerConfiguration wsServerConfiguration) {
final IServerConfigurationService serverConfigurationService,
final IApplicationConfigService applicationConfigService,
final CaptchaService captchaService,
final ICryptoServerGrpcClient cryptoServerClient,
final IRestApiService restApiService,
final WsServerConfiguration wsServerConfiguration) {
this.registrationService = registrationService;
this.serverConfigurationService = serverConfigurationService;
......@@ -41,13 +68,67 @@ public class RegisterControllerImpl extends AbstractRegisterControllerImpl imple
this.wsServerConfiguration = wsServerConfiguration;
}
@Override
public ResponseEntity<RegisterResponseDto> register(RegisterVo registerVo) throws RobertServerException {
@Override
public ResponseEntity<RegisterResponseDto> register(@Valid RegisterVo registerVo)
throws RobertServerException {
if (!this.captchaService.verifyCaptcha(registerVo)) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
return postCheckRegister(registerVo);
}
private ResponseEntity<RegisterResponseDto> postCheckRegister(RegisterVo registerVo) throws RobertServerException {
byte[] clientPublicECDHKey = Base64.decode(registerVo.getClientPublicECDHKey());
byte[] serverCountryCode = new byte[1];
serverCountryCode[0] = this.serverConfigurationService.getServerCountryCode();
CreateRegistrationRequest request = CreateRegistrationRequest.newBuilder()
.setClientPublicKey(ByteString.copyFrom(clientPublicECDHKey))
.setNumberOfDaysForEpochBundles(this.wsServerConfiguration.getEpochBundleDurationInDays())
.setServerCountryCode(ByteString.copyFrom(serverCountryCode))
.setFromEpochId(TimeUtils.getCurrentEpochFrom(this.serverConfigurationService.getServiceTimeStart()))
.build();
Optional<CreateRegistrationResponse> response = this.cryptoServerClient.createRegistration(request);
if(!response.isPresent() || response.get().hasError()) {
log.error("Unable to generate an identity for the client");
throw new RobertServerException(MessageConstants.ERROR_OCCURED);
}
CreateRegistrationResponse identity = response.get();
Registration registration = Registration.builder()
.permanentIdentifier(identity.getIdA().toByteArray())
.build();
Optional<Registration> registered = this.registrationService.saveRegistration(registration);
if (registered.isPresent()) {
RegisterResponseDto registerResponseDto = new RegisterResponseDto();
List<ApplicationConfigurationModel> serverConf = this.applicationConfigService.findAll();
if (CollectionUtils.isEmpty(serverConf)) {
registerResponseDto.setConfig(Collections.emptyList());
} else {
registerResponseDto.setConfig(serverConf
.stream()
.map(item -> ClientConfigDto.builder().name(item.getName()).value(item.getValue()).build())
.collect(Collectors.toList()));
}
registerResponseDto.setTuples(Base64.encode(identity.getTuples().toByteArray()));
registerResponseDto.setTimeStart(this.serverConfigurationService.getServiceTimeStart());
Optional.ofNullable(registerVo.getPushInfo()).ifPresent(this.restApiService::registerPushNotif);
return ResponseEntity.status(HttpStatus.CREATED).body(registerResponseDto);
}
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
}
}
package fr.gouv.stopc.robertserver.ws.controller.impl;
import javax.inject.Inject;
import javax.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import fr.gouv.stopc.robert.crypto.grpc.server.client.service.ICryptoServerGrpcClient;
import fr.gouv.stopc.robert.server.common.service.IServerConfigurationService;
import fr.gouv.stopc.robertserver.database.service.IApplicationConfigService;
import fr.gouv.stopc.robertserver.database.service.IRegistrationService;
import fr.gouv.stopc.robertserver.ws.config.WsServerConfiguration;
import fr.gouv.stopc.robertserver.ws.controller.IRegisterInternalController;
import fr.gouv.stopc.robertserver.ws.dto.RegisterResponseDto;
import fr.gouv.stopc.robertserver.ws.exception.RobertServerException;
import fr.gouv.stopc.robertserver.ws.service.CaptchaInternalService;
import fr.gouv.stopc.robertserver.ws.service.IRestApiService;
import fr.gouv.stopc.robertserver.ws.vo.RegisterInternalVo;
@Service
public class RegisterInternalControllerImpl extends AbstractRegisterControllerImpl implements IRegisterInternalController {
private final CaptchaInternalService captchaInternalService;
@Inject
public RegisterInternalControllerImpl(final IRegistrationService registrationService,
final IServerConfigurationService serverConfigurationService,
final IApplicationConfigService applicationConfigService,
final CaptchaInternalService captchaInternalService,
final ICryptoServerGrpcClient cryptoServerClient,
final IRestApiService restApiService,
final WsServerConfiguration wsServerConfiguration) {
this.registrationService = registrationService;
this.serverConfigurationService = serverConfigurationService;
this.applicationConfigService = applicationConfigService;
this.captchaInternalService = captchaInternalService;
this.cryptoServerClient = cryptoServerClient;
this.restApiService = restApiService;
this.wsServerConfiguration = wsServerConfiguration;
}
@Override
public ResponseEntity<RegisterResponseDto> register(@Valid RegisterInternalVo registerVo)
throws RobertServerException {
if (!this.captchaInternalService.verifyCaptcha(registerVo)) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
return postCheckRegister(registerVo);
}
}
......@@ -13,7 +13,7 @@ import javax.validation.constraints.NotNull;
@AllArgsConstructor
@Data
@Builder
public class CaptchaInternalCreationDto {
public class CaptchaCreationDto {
@JsonProperty("id")
@NotNull
private String captchaId;
......
package fr.gouv.stopc.robertserver.ws.dto;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
......@@ -19,17 +13,16 @@ import lombok.NoArgsConstructor;
@Builder
public class CaptchaDto {
@NotNull
private boolean success;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
@JsonProperty("challenge_ts")
private Date challengeTimestamp;
/** Present only if the request has been completed successfully */
@JsonProperty("result")
private String result;
@NotNull
private String hostname;
/** Present, along with {@link #errorMessage}, only if the request had some issue */
@JsonProperty("code")
private String errorCode;
@JsonProperty("error-codes")
private List<String> errorCodes;
/** Present, along with {@link #errorCode}, only if the request had some issue */
@JsonProperty("message")
private String errorMessage;
}
package fr.gouv.stopc.robertserver.ws.dto;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
public class CaptchaImageDto {
@NotNull
private String format;
@NotNull
private Integer value;
@NotNull
private String data;
}
package fr.gouv.stopc.robertserver.ws.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
public class CaptchaInternalDto {