Search in sources :

Example 1 with IAuthorizationContext

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;
    }
}
Also used : IAuthorizationContext(com.openshift.restclient.authorization.IAuthorizationContext) UnauthorizedException(com.openshift.restclient.authorization.UnauthorizedException)

Example 2 with IAuthorizationContext

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;
}
Also used : IAuthorizationContext(com.openshift.restclient.authorization.IAuthorizationContext)

Example 3 with IAuthorizationContext

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));
}
Also used : IAuthorizationContext(com.openshift.restclient.authorization.IAuthorizationContext) IClient(com.openshift.restclient.IClient) Test(org.junit.Test)

Example 4 with IAuthorizationContext

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());
}
Also used : IAuthorizationContext(com.openshift.restclient.authorization.IAuthorizationContext) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection)

Example 5 with IAuthorizationContext

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);
}
Also used : IAuthorizationContext(com.openshift.restclient.authorization.IAuthorizationContext)

Aggregations

IAuthorizationContext (com.openshift.restclient.authorization.IAuthorizationContext)7 IClient (com.openshift.restclient.IClient)1 UnauthorizedException (com.openshift.restclient.authorization.UnauthorizedException)1 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)1 Test (org.junit.Test)1