Merge branch 'dev-lms-open-olat' into dev-1.2
This commit is contained in:
commit
5cf2547b86
1 changed files with 11 additions and 5 deletions
|
@ -9,9 +9,12 @@
|
||||||
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;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpRequest;
|
import org.springframework.http.HttpRequest;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
@ -66,12 +69,15 @@ public class OlatLmsRestTemplate extends RestTemplate {
|
||||||
private void authenticate() {
|
private void authenticate() {
|
||||||
// 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 = String.format("%s%s?password=%s",
|
final String authUrl = this.details.getAccessTokenUri();
|
||||||
this.details.getAccessTokenUri(),
|
final Map<String, String> credentials = new HashMap<>();
|
||||||
this.details.getClientId(),
|
credentials.put("username", this.details.getClientId());
|
||||||
this.details.getClientSecret());
|
credentials.put("password", this.details.getClientSecret());
|
||||||
|
final HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.set("content-type", "application/json");
|
||||||
|
final HttpEntity<Map<String,String>> requestEntity = new HttpEntity<>(credentials, httpHeaders);
|
||||||
try {
|
try {
|
||||||
final ResponseEntity<String> response = this.getForEntity(authUrl, String.class);
|
final ResponseEntity<String> response = this.postForEntity(authUrl, requestEntity, String.class);
|
||||||
final HttpHeaders responseHeaders = response.getHeaders();
|
final HttpHeaders responseHeaders = response.getHeaders();
|
||||||
log.debug("OLAT [authenticate] {} Headers: {}", response.getStatusCode(), responseHeaders);
|
log.debug("OLAT [authenticate] {} Headers: {}", response.getStatusCode(), responseHeaders);
|
||||||
this.token = responseHeaders.getFirst("X-OLAT-TOKEN");
|
this.token = responseHeaders.getFirst("X-OLAT-TOKEN");
|
||||||
|
|
Loading…
Reference in a new issue