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