Search in sources :

Example 1 with API_HOSTNAME

use of de.tum.in.tumcampusapp.utils.Const.API_HOSTNAME in project TumCampusApp by TCA-Team.

the class Helper method getOkClient.

public static OkHttpClient getOkClient(Context c) {
    if (client != null) {
        return client;
    }
    final CertificatePinner certificatePinner = new CertificatePinner.Builder().add(API_HOSTNAME, // Fakultaet fuer Informatik
    "sha256/dVphPQ9xG7woPpEKXrNalw4eMUQ4Fw9r3OXTzxfuL5A=").add(API_HOSTNAME, // Technische Universitaet Muenchen
    "sha256/SwdQoHL7SB/6o12XsIhbQJ9bANVnbrJoHTLzlu/qXT0=").add(API_HOSTNAME, // DFN-Verein PCA Global
    "sha256/VzL+FtAKvzb4N5igmFJyv83GD7CBK7Yyw+R6XdRRfmg=").add(API_HOSTNAME, // Deutsche Telekom Root CA 2
    "sha256/0d4q5hyN8vpiOWYWPUxz1GC/xCjldYW+a/65pWMj0bY=").add(API_HOSTNAME, // Let's Encrypt Authority X3
    "sha256/YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg=").add(API_HOSTNAME, // LE Cross Sign: DST Root CA X3
    "sha256/Vjs8r4z+80wjNcr1YKepWQboSIRi63WsWXhIMN+eWys=").add(API_HOSTNAME_NEW, // Fakultaet fuer Informatik
    "sha256/dVphPQ9xG7woPpEKXrNalw4eMUQ4Fw9r3OXTzxfuL5A=").add(API_HOSTNAME_NEW, // Technische Universitaet Muenchen
    "sha256/SwdQoHL7SB/6o12XsIhbQJ9bANVnbrJoHTLzlu/qXT0=").add(API_HOSTNAME_NEW, // DFN-Verein PCA Global
    "sha256/VzL+FtAKvzb4N5igmFJyv83GD7CBK7Yyw+R6XdRRfmg=").add(API_HOSTNAME_NEW, // Deutsche Telekom Root CA 2
    "sha256/0d4q5hyN8vpiOWYWPUxz1GC/xCjldYW+a/65pWMj0bY=").add(API_HOSTNAME_NEW, // Let's Encrypt Authority X3
    "sha256/YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg=").add(API_HOSTNAME_NEW, // LE Cross Sign: DST Root CA X3
    "sha256/Vjs8r4z+80wjNcr1YKepWQboSIRi63WsWXhIMN+eWys=").add(STUDYROOM_HOST, // wwwv2.tum.de
    "sha256/dVphPQ9xG7woPpEKXrNalw4eMUQ4Fw9r3OXTzxfuL5A=").add(STUDYROOM_HOST, // wwwv4.tum.de
    "sha256/K64RzAqr/RSxwfpHN6fe0DcmdaIVmzAyi511ufYaK1s=").add(STUDYROOM_HOST, // Zertifizierungsstelle der TUM
    "sha256/SwdQoHL7SB/6o12XsIhbQJ9bANVnbrJoHTLzlu/qXT0=").add(STUDYROOM_HOST, // DFN-Verein PCA Global - G01
    "sha256/VzL+FtAKvzb4N5igmFJyv83GD7CBK7Yyw+R6XdRRfmg=").add(STUDYROOM_HOST, // Deutsche Telekom Root CA 2
    "sha256/0d4q5hyN8vpiOWYWPUxz1GC/xCjldYW+a/65pWMj0bY=").build();
    // We want to persist our cookies through app session
    ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(c));
    // Start building the http client
    OkHttpClient.Builder builder = new OkHttpClient.Builder().cookieJar(cookieJar).certificatePinner(certificatePinner);
    // Add the device identifying header
    builder.addInterceptor(Helper.getDeviceInterceptor(c));
    builder.connectTimeout(Helper.HTTP_TIMEOUT, TimeUnit.MILLISECONDS);
    builder.readTimeout(Helper.HTTP_TIMEOUT, TimeUnit.MILLISECONDS);
    builder.addNetworkInterceptor(new TumHttpLoggingInterceptor(message -> Utils.logwithTag(TAG, message)));
    // Save it to the static handle and return
    client = builder.build();
    return client;
}
Also used : Context(android.content.Context) Interceptor(okhttp3.Interceptor) SetCookieCache(com.franmontiel.persistentcookiejar.cache.SetCookieCache) Request(okhttp3.Request) PersistentCookieJar(com.franmontiel.persistentcookiejar.PersistentCookieJar) API_HOSTNAME_NEW(de.tum.in.tumcampusapp.utils.Const.API_HOSTNAME_NEW) PackageManager(android.content.pm.PackageManager) SharedPrefsCookiePersistor(com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor) STUDYROOM_HOST(de.tum.in.tumcampusapp.component.ui.studyroom.StudyRoomGroupManager.STUDYROOM_HOST) UrlEscapers(com.google.common.net.UrlEscapers) CertificatePinner(okhttp3.CertificatePinner) ClearableCookieJar(com.franmontiel.persistentcookiejar.ClearableCookieJar) TimeUnit(java.util.concurrent.TimeUnit) OkHttpClient(okhttp3.OkHttpClient) Utils(de.tum.in.tumcampusapp.utils.Utils) API_HOSTNAME(de.tum.in.tumcampusapp.utils.Const.API_HOSTNAME) Build(android.os.Build) ClearableCookieJar(com.franmontiel.persistentcookiejar.ClearableCookieJar) OkHttpClient(okhttp3.OkHttpClient) PersistentCookieJar(com.franmontiel.persistentcookiejar.PersistentCookieJar) CertificatePinner(okhttp3.CertificatePinner) SetCookieCache(com.franmontiel.persistentcookiejar.cache.SetCookieCache) SharedPrefsCookiePersistor(com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor)

Aggregations

Context (android.content.Context)1 PackageManager (android.content.pm.PackageManager)1 Build (android.os.Build)1 ClearableCookieJar (com.franmontiel.persistentcookiejar.ClearableCookieJar)1 PersistentCookieJar (com.franmontiel.persistentcookiejar.PersistentCookieJar)1 SetCookieCache (com.franmontiel.persistentcookiejar.cache.SetCookieCache)1 SharedPrefsCookiePersistor (com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor)1 UrlEscapers (com.google.common.net.UrlEscapers)1 STUDYROOM_HOST (de.tum.in.tumcampusapp.component.ui.studyroom.StudyRoomGroupManager.STUDYROOM_HOST)1 API_HOSTNAME (de.tum.in.tumcampusapp.utils.Const.API_HOSTNAME)1 API_HOSTNAME_NEW (de.tum.in.tumcampusapp.utils.Const.API_HOSTNAME_NEW)1 Utils (de.tum.in.tumcampusapp.utils.Utils)1 TimeUnit (java.util.concurrent.TimeUnit)1 CertificatePinner (okhttp3.CertificatePinner)1 Interceptor (okhttp3.Interceptor)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1