use of com.openshift.restclient.authorization.IAuthorizationContext in project jbosstools-openshift by jbosstools.
the class Connection method isAuthorized.
/**
* Computes authorization state of connection. May be a long running operation.
* @return
*/
public boolean isAuthorized(IProgressMonitor monitor) {
try {
IAuthorizationContext context = client.getAuthorizationContext();
boolean result = context.isAuthorized();
if (result) {
// being true, promises that connect will go smoothly.
return connect();
}
return result;
} catch (UnauthorizedException e) {
return false;
}
}
use of com.openshift.restclient.authorization.IAuthorizationContext in project jbosstools-openshift by jbosstools.
the class Connection method setPassword.
@Override
public void setPassword(String password) {
IAuthorizationContext authContext = client.getAuthorizationContext();
String old = authContext.getPassword();
authContext.setPassword(password);
firePropertyChange(PROPERTY_PASSWORD, old, password);
this.passwordLoaded = true;
}
use of com.openshift.restclient.authorization.IAuthorizationContext in project jbosstools-openshift by jbosstools.
the class ConnectionTest method should_prompt_when_connecting_while_being_unauthorized.
@Test
public void should_prompt_when_connecting_while_being_unauthorized() throws Exception {
// given no or outdated token
IClient client = createClient("username", "token", "https://ahost");
IAuthorizationContext authorizationContext = mock(IAuthorizationContext.class);
when(client.getAuthorizationContext()).thenReturn(authorizationContext);
doThrow(UnauthorizedException.class).when(authorizationContext).isAuthorized();
testableConnection = createTestableConnection("token", client, prompter);
testableConnection.enablePromptCredentials(true);
// when
testableConnection.connect();
// then
verify(prompter).promptAndAuthenticate(eq(testableConnection), any(IAuthorizationContext.class));
}
use of com.openshift.restclient.authorization.IAuthorizationContext in project jbosstools-openshift by jbosstools.
the class Connection method update.
@Override
public void update(IConnection connection) {
Assert.isLegal(connection instanceof Connection);
Connection otherConnection = (Connection) connection;
this.client = otherConnection.client;
this.credentialsPrompter = otherConnection.credentialsPrompter;
this.rememberToken = otherConnection.rememberToken;
this.rememberPassword = otherConnection.rememberPassword;
this.tokenLoaded = otherConnection.tokenLoaded;
this.rememberPassword = otherConnection.rememberPassword;
this.extendedProperties = otherConnection.getExtendedProperties();
IAuthorizationContext otherContext = otherConnection.client.getAuthorizationContext();
IAuthorizationContext context = this.client.getAuthorizationContext();
context.setUserName(otherContext.getUserName());
context.setPassword(otherContext.getPassword());
context.setToken(otherContext.getToken());
}
use of com.openshift.restclient.authorization.IAuthorizationContext in project jbosstools-openshift by jbosstools.
the class Connection method setUsername.
@Override
public void setUsername(String userName) {
IAuthorizationContext authContext = client.getAuthorizationContext();
String old = authContext.getUserName();
authContext.setUserName(userName);
firePropertyChange(PROPERTY_USERNAME, old, userName);
}
Aggregations