Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
parent
47b004f227
commit
4fb528901f
|
@ -14,15 +14,21 @@ package org.openhab.binding.linky.internal;
|
||||||
|
|
||||||
import static org.openhab.binding.linky.internal.LinkyBindingConstants.THING_TYPE_LINKY;
|
import static org.openhab.binding.linky.internal.LinkyBindingConstants.THING_TYPE_LINKY;
|
||||||
|
|
||||||
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.TrustManager;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.eclipse.jetty.client.HttpClient;
|
import org.eclipse.jetty.client.HttpClient;
|
||||||
import org.openhab.binding.linky.internal.handler.LinkyHandler;
|
import org.openhab.binding.linky.internal.handler.LinkyHandler;
|
||||||
import org.openhab.core.i18n.LocaleProvider;
|
import org.openhab.core.i18n.LocaleProvider;
|
||||||
import org.openhab.core.io.net.http.HttpClientFactory;
|
import org.openhab.core.io.net.http.HttpClientFactory;
|
||||||
|
import org.openhab.core.io.net.http.TrustAllTrustManager;
|
||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
import org.openhab.core.thing.ThingTypeUID;
|
import org.openhab.core.thing.ThingTypeUID;
|
||||||
import org.openhab.core.thing.binding.BaseThingHandlerFactory;
|
import org.openhab.core.thing.binding.BaseThingHandlerFactory;
|
||||||
|
@ -70,8 +76,17 @@ public class LinkyHandlerFactory extends BaseThingHandlerFactory {
|
||||||
super.activate(componentContext);
|
super.activate(componentContext);
|
||||||
httpClient.setFollowRedirects(false);
|
httpClient.setFollowRedirects(false);
|
||||||
httpClient.setRequestBufferSize(REQUEST_BUFFER_SIZE);
|
httpClient.setRequestBufferSize(REQUEST_BUFFER_SIZE);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||||
|
sslContext.init(null, new TrustManager[] { TrustAllTrustManager.getInstance() }, null);
|
||||||
|
httpClient.getSslContextFactory().setSslContext(sslContext);
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
logger.warn("An exception occurred while requesting the SSL encryption algorithm : '{}'", e.getMessage(),
|
||||||
|
e);
|
||||||
|
} catch (KeyManagementException e) {
|
||||||
|
logger.warn("An exception occurred while initialising the SSL context : '{}'", e.getMessage(), e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("Unable to start Jetty HttpClient {}", e.getMessage());
|
logger.warn("Unable to start Jetty HttpClient {}", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.linky.internal.api;
|
package org.openhab.binding.linky.internal.api;
|
||||||
|
|
||||||
import java.net.CookieStore;
|
|
||||||
import java.net.HttpCookie;
|
import java.net.HttpCookie;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
@ -71,7 +70,6 @@ public class EnedisHttpApi {
|
||||||
private final Logger logger = LoggerFactory.getLogger(EnedisHttpApi.class);
|
private final Logger logger = LoggerFactory.getLogger(EnedisHttpApi.class);
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
private final HttpClient httpClient;
|
private final HttpClient httpClient;
|
||||||
private final CookieStore cookieStore;
|
|
||||||
private final LinkyConfiguration config;
|
private final LinkyConfiguration config;
|
||||||
|
|
||||||
private boolean connected = false;
|
private boolean connected = false;
|
||||||
|
@ -80,7 +78,6 @@ public class EnedisHttpApi {
|
||||||
this.gson = gson;
|
this.gson = gson;
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClient;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.cookieStore = httpClient.getCookieStore();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() throws LinkyException {
|
public void initialize() throws LinkyException {
|
||||||
|
@ -158,7 +155,7 @@ public class EnedisHttpApi {
|
||||||
result = httpClient.POST(el.attr("action")).content(getFormContent("SAMLResponse", samlInput.attr("value")))
|
result = httpClient.POST(el.attr("action")).content(getFormContent("SAMLResponse", samlInput.attr("value")))
|
||||||
.send();
|
.send();
|
||||||
if (result.getStatus() != 302) {
|
if (result.getStatus() != 302) {
|
||||||
throw new LinkyException("Connection failed step 5");
|
throw new LinkyException("Connection failed step 6");
|
||||||
}
|
}
|
||||||
connected = true;
|
connected = true;
|
||||||
} catch (InterruptedException | TimeoutException | ExecutionException | JsonSyntaxException e) {
|
} catch (InterruptedException | TimeoutException | ExecutionException | JsonSyntaxException e) {
|
||||||
|
@ -178,7 +175,7 @@ public class EnedisHttpApi {
|
||||||
String location = getLocation(httpClient.GET(URL_APPS_LINCS + "/logout"));
|
String location = getLocation(httpClient.GET(URL_APPS_LINCS + "/logout"));
|
||||||
location = getLocation(httpClient.GET(location));
|
location = getLocation(httpClient.GET(location));
|
||||||
getLocation(httpClient.GET(location));
|
getLocation(httpClient.GET(location));
|
||||||
cookieStore.removeAll();
|
httpClient.getCookieStore().removeAll();
|
||||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||||
throw new LinkyException(e, "Error while disconnecting from Enedis webservice");
|
throw new LinkyException(e, "Error while disconnecting from Enedis webservice");
|
||||||
}
|
}
|
||||||
|
@ -197,7 +194,7 @@ public class EnedisHttpApi {
|
||||||
HttpCookie cookie = new HttpCookie(key, value);
|
HttpCookie cookie = new HttpCookie(key, value);
|
||||||
cookie.setDomain(ENEDIS_DOMAIN);
|
cookie.setDomain(ENEDIS_DOMAIN);
|
||||||
cookie.setPath("/");
|
cookie.setPath("/");
|
||||||
cookieStore.add(COOKIE_URI, cookie);
|
httpClient.getCookieStore().add(COOKIE_URI, cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FormContentProvider getFormContent(String fieldName, String fieldValue) {
|
private FormContentProvider getFormContent(String fieldName, String fieldValue) {
|
||||||
|
|
Loading…
Reference in New Issue