2211 |
arthur |
1 |
package org.tela_botanica.del.client.services;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.del.client.modeles.Utilisateur;
|
|
|
4 |
|
|
|
5 |
import com.google.gwt.http.client.RequestBuilder;
|
|
|
6 |
|
|
|
7 |
public class RequestBuilderWithCredentials extends RequestBuilder {
|
|
|
8 |
|
|
|
9 |
/**
|
|
|
10 |
* Envoie une requête avec les headers "Credentials" (CORS) et "Authorization" (SSO)
|
|
|
11 |
*/
|
|
|
12 |
public RequestBuilderWithCredentials(Method httpMethod, String url) {
|
|
|
13 |
this(httpMethod, url, true);
|
|
|
14 |
}
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Envoie une requête avec un header "Credentials" pour CORS (ajax.io); si
|
|
|
18 |
* authorizationHeader vaut true, envoie aussi le jeton SSO (s'il existe) dans
|
|
|
19 |
* le header "Authorization"
|
|
|
20 |
*/
|
|
|
21 |
public RequestBuilderWithCredentials(Method httpMethod, String url, boolean authorizationHeader) {
|
|
|
22 |
super(httpMethod, url);
|
|
|
23 |
if(authorizationHeader && Utilisateur.getJeton() != null && ! Utilisateur.getJeton().isEmpty()) {
|
|
|
24 |
this.setHeader("Authorization", Utilisateur.getJeton());
|
|
|
25 |
}
|
|
|
26 |
this.setIncludeCredentials(true);
|
|
|
27 |
}
|
|
|
28 |
}
|