]> git.basschouten.com Git - openhab-addons.git/blob
3e8fbd012d8ba39443e423b288d468c0a42ce8b3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.linky.internal.handler;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import okhttp3.Cookie;
19 import okhttp3.CookieJar;
20 import okhttp3.HttpUrl;
21
22 /**
23  * The {@link LinkyCookieJar} is responsible to holds cookies
24  * during API session
25  *
26  * @author GaĆ«l L'hopital - Initial contribution
27  */
28 public class LinkyCookieJar implements CookieJar {
29
30     private static final String LOGIN_URL_PATH = "/auth/UI/Login";
31
32     private List<Cookie> cookies = new ArrayList<>();
33
34     @Override
35     public void saveFromResponse(final HttpUrl url, final List<Cookie> cookies) {
36         this.cookies.addAll(cookies);
37     }
38
39     @Override
40     public List<Cookie> loadForRequest(final HttpUrl url) {
41         if (LOGIN_URL_PATH.equals(url.url().getPath())) {
42             cookies = new ArrayList<>();
43         }
44         return cookies;
45     }
46 }