Search in sources :

Example 1 with IClient

use of com.openshift.restclient.IClient in project jbosstools-openshift by jbosstools.

the class OpenShiftConnectionRequirement method createConnectionWithCredentials.

private Connection createConnectionWithCredentials(String server, String username, String password) {
    IClient client = createClient(server);
    Connection connection = new Connection(client, null);
    connection.setAuthScheme(IAuthorizationContext.AUTHSCHEME_BASIC);
    connection.setUsername(username);
    connection.setPassword(password);
    return connection;
}
Also used : RequiredBasicConnection(org.jboss.tools.openshift.reddeer.requirement.OpenShiftConnectionRequirement.RequiredBasicConnection) Connection(org.jboss.tools.openshift.core.connection.Connection) IClient(com.openshift.restclient.IClient)

Example 2 with IClient

use of com.openshift.restclient.IClient in project jbosstools-openshift by jbosstools.

the class OpenShiftConnectionRequirement method createConnectionWithToken.

private Connection createConnectionWithToken(String server, String token) {
    IClient client = createClient(server);
    Connection connection = new Connection(client, null);
    connection.setAuthScheme(IAuthorizationContext.AUTHSCHEME_OAUTH);
    connection.setUsername(connection.getUsername());
    connection.setToken(token);
    connection.refresh();
    return connection;
}
Also used : RequiredBasicConnection(org.jboss.tools.openshift.reddeer.requirement.OpenShiftConnectionRequirement.RequiredBasicConnection) Connection(org.jboss.tools.openshift.core.connection.Connection) IClient(com.openshift.restclient.IClient)

Example 3 with IClient

use of com.openshift.restclient.IClient 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 IClient

use of com.openshift.restclient.IClient in project jbosstools-openshift by jbosstools.

the class Connection method clone.

@Override
public IConnection clone() {
    IClient clone = client.clone();
    Connection connection = new Connection(clone, credentialsPrompter);
    connection.passwordLoaded = this.passwordLoaded;
    connection.tokenLoaded = this.tokenLoaded;
    connection.rememberPassword = this.rememberPassword;
    connection.rememberToken = this.rememberToken;
    connection.promptCredentialsEnabled = promptCredentialsEnabled;
    return connection;
}
Also used : IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IClient(com.openshift.restclient.IClient)

Example 5 with IClient

use of com.openshift.restclient.IClient in project jbosstools-openshift by jbosstools.

the class ConnectionTest method givenAResourceThatAcceptsAVisitorForIClientCapability.

@SuppressWarnings("unchecked")
private Map<String, Object> givenAResourceThatAcceptsAVisitorForIClientCapability(IClient client) {
    final IClientCapability capability = mock(IClientCapability.class);
    when(capability.getClient()).thenReturn(client);
    IResource resource = mock(IResource.class);
    when(resource.accept(any(CapabilityVisitor.class), any())).thenAnswer(new Answer<IClient>() {

        @Override
        public IClient answer(InvocationOnMock invocation) throws Throwable {
            CapabilityVisitor<IClientCapability, IClient> visitor = (CapabilityVisitor<IClientCapability, IClient>) invocation.getArguments()[0];
            return visitor.visit(capability);
        }
    });
    Map<String, Object> mocks = new HashMap<>();
    mocks.put("capability", capability);
    mocks.put("resource", resource);
    return mocks;
}
Also used : IClientCapability(com.openshift.restclient.capability.resources.IClientCapability) HashMap(java.util.HashMap) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IClient(com.openshift.restclient.IClient) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) Matchers.anyString(org.mockito.Matchers.anyString) IResource(com.openshift.restclient.model.IResource)

Aggregations

IClient (com.openshift.restclient.IClient)12 OpenShiftException (com.openshift.restclient.OpenShiftException)4 ClientBuilder (com.openshift.restclient.ClientBuilder)3 IResource (com.openshift.restclient.model.IResource)3 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)3 LazySSLCertificateCallback (org.jboss.tools.openshift.core.LazySSLCertificateCallback)3 Connection (org.jboss.tools.openshift.core.connection.Connection)3 ISSLCertificateCallback (com.openshift.restclient.ISSLCertificateCallback)2 IOException (java.io.IOException)2 TimeoutException (java.util.concurrent.TimeoutException)2 CoreException (org.eclipse.core.runtime.CoreException)2 CommandTimeoutException (org.jboss.tools.openshift.cdk.server.core.internal.adapter.controllers.CommandTimeoutException)2 RequiredBasicConnection (org.jboss.tools.openshift.reddeer.requirement.OpenShiftConnectionRequirement.RequiredBasicConnection)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 IAuthorizationContext (com.openshift.restclient.authorization.IAuthorizationContext)1 CapabilityVisitor (com.openshift.restclient.capability.CapabilityVisitor)1 IClientCapability (com.openshift.restclient.capability.resources.IClientCapability)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1