Skip to content

Commit

Permalink
Merge pull request #6 from usdot-jpo-ode/dev
Browse files Browse the repository at this point in the history
jpo-security-svcs-1.0.0
  • Loading branch information
dan-du-car authored Sep 30, 2020
2 parents cbd2146 + dc949a1 commit db1021e
Showing 1 changed file with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ public class SignatureController implements EnvironmentAware {
// public boolean mockResponse;
public boolean useHsm;

public static class Message {
public static class Message{
@JsonProperty("message")
public String msg;

@JsonProperty("sigValidityOverride")
public int sigValidityOverride = 0;
}

private static final Logger logger = LoggerFactory.getLogger(SignatureController.class);
Expand All @@ -73,6 +76,7 @@ public static class Message {
public ResponseEntity<Map<String,String>> sign(@RequestBody Message message) throws URISyntaxException {

logger.info("Received message: {}", message.msg);
logger.info("Received sigValidityOverride: {}", message.sigValidityOverride);

ResponseEntity<Map<String,String>> response;

Expand All @@ -99,7 +103,7 @@ public ResponseEntity<Map<String,String>> sign(@RequestBody Message message) thr
}

logger.debug("After Trimming: cryptoServiceBaseUri={}, cryptoServiceEndpointSignPath={}", cryptoServiceBaseUri, cryptoServiceEndpointSignPath);

String resultString = message.msg;
if (!StringUtils.isEmpty(cryptoServiceBaseUri) && !StringUtils.isEmpty(cryptoServiceEndpointSignPath)) {
logger.info("Sending signature request to external service");
Expand All @@ -108,7 +112,19 @@ public ResponseEntity<Map<String,String>> sign(@RequestBody Message message) thr
JSONObject json = new JSONObject(result.getBody());

resultString = json.getString("message-signed");
response = ResponseEntity.status(HttpStatus.OK).body(Collections.singletonMap("result", resultString));
Map<String, String> mapResult = new HashMap<>();
try
{

mapResult.put("message-expiry", String.valueOf(json.getLong("message-expiry")));

}
catch(Exception e)
{
mapResult.put("message-expiry", "null");
}
mapResult.put("message-signed", resultString);
response = ResponseEntity.status(HttpStatus.OK).body(Collections.singletonMap("result", new JSONObject(mapResult).toString()));
} else {
String msg = "Properties sec.cryptoServiceBaseUri=" + cryptoServiceBaseUri
+ ", sec.cryptoServiceEndpointSignPath=" + cryptoServiceEndpointSignPath
Expand All @@ -120,6 +136,7 @@ public ResponseEntity<Map<String,String>> sign(@RequestBody Message message) thr
response = ResponseEntity.status(HttpStatus.NOT_FOUND).body(result);
}


}

return response;
Expand All @@ -130,9 +147,19 @@ private ResponseEntity<String> forwardMessageToExternalService(Message message)

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

HttpEntity<Map<String, String>> entity = new HttpEntity<>(Collections.singletonMap("message", message.msg), headers);

Map<String,String> map;

if(message.sigValidityOverride > 0)
{
map = new HashMap<>();
map.put("message",message.msg);
map.put("sigValidityOverride", Integer.toString(message.sigValidityOverride));
}
else
{
map = Collections.singletonMap("message", message.msg);
}
HttpEntity<Map<String, String>> entity = new HttpEntity<>(map, headers);
RestTemplate template = new RestTemplate();

logger.debug("Received request: {}", entity);
Expand Down

0 comments on commit db1021e

Please sign in to comment.