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);
}
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;
}
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);
}
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;
}
Aggregations