Search in sources :

Example 1 with CredentialAttributes

use of com.intellij.credentialStore.CredentialAttributes in project intellij-plugins by StepicOrg.

the class CookieStore method save.

void save() {
    CredentialAttributes attributes;
    String serviceName = getClass().getName();
    attributes = new CredentialAttributes(serviceName, "cookies", getClass(), false);
    Map<String, Set<Cookie>> cookies = new HashMap<>();
    buckets.forEach((key, value) -> cookies.put(key, new HashSet<>(value.values())));
    String serialized = gson.toJson(cookies, bucketsType);
    Credentials credentials = new Credentials(attributes.getUserName(), serialized);
    PasswordSafe.getInstance().set(attributes, credentials);
}
Also used : CredentialAttributes(com.intellij.credentialStore.CredentialAttributes) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Credentials(com.intellij.credentialStore.Credentials) HashSet(java.util.HashSet)

Example 2 with CredentialAttributes

use of com.intellij.credentialStore.CredentialAttributes in project intellij-plugins by StepicOrg.

the class CookieStore method loadCookies.

@NotNull
private Map<String, Map<Cookie, Cookie>> loadCookies() {
    CredentialAttributes attributes;
    String serviceName = this.getClass().getName();
    attributes = new CredentialAttributes(serviceName, "cookies", getClass(), false);
    Credentials credentials = PasswordSafe.getInstance().get(attributes);
    String json = credentials != null ? credentials.getPasswordAsString() : null;
    Map<String, Set<Cookie>> cookies = new HashMap<>();
    if (json != null) {
        try {
            cookies = gson.fromJson(json, bucketsType);
        } catch (JsonSyntaxException e) {
            logger.warn(e);
        }
    }
    Map<String, Map<Cookie, Cookie>> buckets = new HashMap<>();
    cookies.forEach((key, value) -> {
        Map<Cookie, Cookie> bucket = new HashMap<>();
        value.forEach(cookie -> bucket.put(cookie, cookie));
        buckets.put(key, bucket);
    });
    return buckets;
}
Also used : CredentialAttributes(com.intellij.credentialStore.CredentialAttributes) Set(java.util.Set) HashSet(java.util.HashSet) JsonSyntaxException(com.google.gson.JsonSyntaxException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Credentials(com.intellij.credentialStore.Credentials) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CredentialAttributes

use of com.intellij.credentialStore.CredentialAttributes in project intellij-plugins by StepicOrg.

the class StepikAuthManager method setTokenInfo.

private static void setTokenInfo(long userId, @NotNull final TokenInfo tokenInfo) {
    String serviceName = StepikProjectManager.class.getName();
    String userName = String.valueOf(userId);
    CredentialAttributes attributes;
    attributes = new CredentialAttributes(serviceName, userName, StepikProjectManager.class, false);
    String serializedAuthInfo = stepikApiClient.getJsonConverter().toJson(tokenInfo);
    Credentials credentials = new Credentials(attributes.getUserName(), serializedAuthInfo);
    PasswordSafe.getInstance().set(attributes, credentials);
    setLastUser(userId);
}
Also used : CredentialAttributes(com.intellij.credentialStore.CredentialAttributes) StepikProjectManager(org.stepik.core.StepikProjectManager) Credentials(com.intellij.credentialStore.Credentials)

Example 4 with CredentialAttributes

use of com.intellij.credentialStore.CredentialAttributes in project intellij-plugins by StepicOrg.

the class StepikAuthManager method getTokenInfo.

@NotNull
private static TokenInfo getTokenInfo(long userId, StepikApiClient client) {
    if (userId == 0) {
        return new TokenInfo();
    }
    String serviceName = StepikProjectManager.class.getName();
    CredentialAttributes attributes = new CredentialAttributes(serviceName, String.valueOf(userId), StepikProjectManager.class, false);
    Credentials credentials = PasswordSafe.getInstance().get(attributes);
    TokenInfo authInfo = null;
    if (credentials != null) {
        String password = credentials.getPasswordAsString();
        authInfo = client.getJsonConverter().fromJson(password, TokenInfo.class);
    }
    if (authInfo == null) {
        return new TokenInfo();
    }
    return authInfo;
}
Also used : CredentialAttributes(com.intellij.credentialStore.CredentialAttributes) TokenInfo(org.stepik.api.objects.auth.TokenInfo) Credentials(com.intellij.credentialStore.Credentials) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CredentialAttributes (com.intellij.credentialStore.CredentialAttributes)4 Credentials (com.intellij.credentialStore.Credentials)4 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Set (java.util.Set)2 NotNull (org.jetbrains.annotations.NotNull)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 Map (java.util.Map)1 TokenInfo (org.stepik.api.objects.auth.TokenInfo)1 StepikProjectManager (org.stepik.core.StepikProjectManager)1