Search in sources :

Example 1 with IAccount

use of org.jboss.tools.openshift.io.core.model.IAccount in project jbosstools-openshift by jbosstools.

the class AccountService method createAccount.

IAccount createAccount(ICluster cluster, LoginResponse response) {
    String id = OSIOUtils.decodeEmailFromToken(response.getAccessToken());
    IAccount newAccount = cluster.createAccount(id);
    updateAccount(response, newAccount);
    cluster.addAccount(newAccount);
    return newAccount;
}
Also used : IAccount(org.jboss.tools.openshift.io.core.model.IAccount)

Example 2 with IAccount

use of org.jboss.tools.openshift.io.core.model.IAccount in project jbosstools-openshift by jbosstools.

the class AccountServiceTest method checkLoginIsRequiredIfNoAccessToken.

@Test
public void checkLoginIsRequiredIfNoAccessToken() {
    IAccount account = cluster.createAccount("myid");
    AccountStatus status = service.getStatus(account);
    assertEquals(AccountStatus.NEEDS_LOGIN, status);
}
Also used : IAccount(org.jboss.tools.openshift.io.core.model.IAccount) Test(org.junit.Test)

Example 3 with IAccount

use of org.jboss.tools.openshift.io.core.model.IAccount in project jbosstools-openshift by jbosstools.

the class AccountServiceTest method checkRefreshIsRequiredIfLastAccessed2DaysAgo.

@Test
public void checkRefreshIsRequiredIfLastAccessed2DaysAgo() {
    IAccount account = cluster.createAccount("myid");
    account.setAccessToken("at");
    account.setRefreshToken("rt");
    account.setLastRefreshedTime(System.currentTimeMillis() - 24 * 3600 * 2 * 1000);
    AccountStatus status = service.getStatus(account);
    assertEquals(AccountStatus.NEEDS_REFRESH, status);
}
Also used : IAccount(org.jboss.tools.openshift.io.core.model.IAccount) Test(org.junit.Test)

Example 4 with IAccount

use of org.jboss.tools.openshift.io.core.model.IAccount in project jbosstools-openshift by jbosstools.

the class AccountService method getToken.

public String getToken(IResource t) {
    String token = null;
    ICluster cluster = getModel().getClusters().get(0);
    List<IAccount> identities = cluster.getAccounts();
    if (identities.isEmpty()) {
        token = performLogin(cluster, null);
    } else {
        IAccount account = identities.get(0);
        AccountStatus status = getStatus(account);
        switch(status) {
            case VALID:
                token = account.getAccessToken();
                break;
            case NEEDS_REFRESH:
                token = performRefresh(account);
                break;
            case NEEDS_LOGIN:
                token = performLogin(cluster, account);
                break;
        }
    }
    return token;
}
Also used : IAccount(org.jboss.tools.openshift.io.core.model.IAccount) ICluster(org.jboss.tools.openshift.io.core.model.ICluster)

Example 5 with IAccount

use of org.jboss.tools.openshift.io.core.model.IAccount in project jbosstools-openshift by jbosstools.

the class MainPreferencePage method performOk.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
	 */
@Override
public boolean performOk() {
    if (removed) {
        ICluster cluster = AccountService.getDefault().getModel().getClusters().get(0);
        if (!cluster.getAccounts().isEmpty()) {
            IAccount account = cluster.getAccounts().get(0);
            cluster.removeAccount(account);
            cluster.save();
        }
    }
    return true;
}
Also used : IAccount(org.jboss.tools.openshift.io.core.model.IAccount) ICluster(org.jboss.tools.openshift.io.core.model.ICluster)

Aggregations

IAccount (org.jboss.tools.openshift.io.core.model.IAccount)9 Test (org.junit.Test)5 ICluster (org.jboss.tools.openshift.io.core.model.ICluster)3 AccountModelAdapter (org.jboss.tools.openshift.io.core.model.AccountModelAdapter)1 IAccountModel (org.jboss.tools.openshift.io.core.model.IAccountModel)1 IAccountModelListener (org.jboss.tools.openshift.io.core.model.IAccountModelListener)1