Search in sources :

Example 6 with Credentials

use of com.intellij.credentialStore.Credentials 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 7 with Credentials

use of com.intellij.credentialStore.Credentials 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

Credentials (com.intellij.credentialStore.Credentials)7 CredentialAttributes (com.intellij.credentialStore.CredentialAttributes)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 OneTimeString (com.intellij.credentialStore.OneTimeString)1 Map (java.util.Map)1 Nullable (org.jetbrains.annotations.Nullable)1 TokenInfo (org.stepik.api.objects.auth.TokenInfo)1 StepikProjectManager (org.stepik.core.StepikProjectManager)1