don't construct json manually

This commit is contained in:
Carol Alexandru 2021-10-13 12:01:12 +02:00
parent 519ad5a9f8
commit 1449de217c

View file

@ -9,6 +9,8 @@
package ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl.olat; package ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl.olat;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -68,13 +70,12 @@ public class OlatLmsRestTemplate extends RestTemplate {
// Authenticate with OLAT and store the received X-OLAT-TOKEN // Authenticate with OLAT and store the received X-OLAT-TOKEN
this.token = "authenticating"; this.token = "authenticating";
final String authUrl = this.details.getAccessTokenUri(); final String authUrl = this.details.getAccessTokenUri();
final String credentials = String.format( final Map<String, String> credentials = new HashMap<>();
"{\"username\": \"%s\", \"password\": \"%s\"}", credentials.put("username", this.details.getClientId());
this.details.getClientId(), credentials.put("password", this.details.getClientSecret());
this.details.getClientSecret());
final HttpHeaders httpHeaders = new HttpHeaders(); final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("content-type", "application/json"); httpHeaders.set("content-type", "application/json");
final HttpEntity<String> requestEntity = new HttpEntity<>(credentials, httpHeaders); final HttpEntity<Map<String,String>> requestEntity = new HttpEntity<>(credentials, httpHeaders);
try { try {
final ResponseEntity<String> response = this.postForEntity(authUrl, requestEntity, String.class); final ResponseEntity<String> response = this.postForEntity(authUrl, requestEntity, String.class);
final HttpHeaders responseHeaders = response.getHeaders(); final HttpHeaders responseHeaders = response.getHeaders();