Search in sources :

Example 1 with IConnection

use of org.jboss.tools.openshift.common.core.connection.IConnection in project jbosstools-openshift by jbosstools.

the class ConnectionValidatorFactory method createBasicAuthenticationValidator.

/**
 * Returns new validator that checks that there is no connection other than the selected one
 * with host and username provided by the observable values.
 * @param pageModel
 * @param usernameObservable
 * @param urlObservable
 * @return
 */
public static MultiValidator createBasicAuthenticationValidator(ConnectionWizardPageModel pageModel, IObservableValue usernameObservable, IObservableValue<?> urlObservable) {
    return new MultiValidator() {

        @Override
        protected IStatus validate() {
            String user1 = (String) usernameObservable.getValue();
            String mHost = (String) urlObservable.getValue();
            IConnection current = pageModel.getSelectedConnection();
            for (Connection c : ConnectionsRegistrySingleton.getInstance().getAll(Connection.class)) {
                if (c != current && IAuthorizationContext.AUTHSCHEME_BASIC.equals(c.getAuthScheme())) {
                    String host = c.getHost();
                    String user = c.getUsername();
                    if (host != null && host.equals(mHost) && user != null && user.equals(user1)) {
                        return ValidationStatus.error("Connection for the server with this username already exists.");
                    }
                }
            }
            return ValidationStatus.ok();
        }
    };
}
Also used : IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator)

Example 2 with IConnection

use of org.jboss.tools.openshift.common.core.connection.IConnection in project jbosstools-openshift by jbosstools.

the class ConnectionEditor method onSelectedConnectionChanged.

@Override
protected void onSelectedConnectionChanged(IObservableValue selectedConnection) {
    IConnection conn = (IConnection) selectedConnection.getValue();
    detailViewModel.setSelectedConnection(conn);
}
Also used : IConnection(org.jboss.tools.openshift.common.core.connection.IConnection)

Example 3 with IConnection

use of org.jboss.tools.openshift.common.core.connection.IConnection in project jbosstools-openshift by jbosstools.

the class ConnectionValidatorFactory method createOAuthAuthenticationValidator.

/**
 * Returns new validator that checks that there is no connection other than the selected one
 * with host and token provided by the observable values.
 * @param pageModel
 * @param tokenObservable
 * @param urlObservable
 * @return
 */
public static MultiValidator createOAuthAuthenticationValidator(ConnectionWizardPageModel pageModel, IObservableValue tokenObservable, IObservableValue<?> urlObservable) {
    return new MultiValidator() {

        @Override
        protected IStatus validate() {
            String token1 = (String) tokenObservable.getValue();
            String mHost = (String) urlObservable.getValue();
            IConnection current = pageModel.getSelectedConnection();
            for (Connection c : ConnectionsRegistrySingleton.getInstance().getAll(Connection.class)) {
                if (c != current && IAuthorizationContext.AUTHSCHEME_OAUTH.equals(c.getAuthScheme())) {
                    String host = c.getHost();
                    String token = c.getToken();
                    if (host != null && host.equals(mHost) && token != null && token.equals(token1)) {
                        return ValidationStatus.error("Connection for the server with this token already exists.");
                    }
                }
            }
            return ValidationStatus.ok();
        }
    };
}
Also used : IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator)

Example 4 with IConnection

use of org.jboss.tools.openshift.common.core.connection.IConnection in project jbosstools-openshift by jbosstools.

the class BasicAuthenticationDetailView method setSelectedConnection.

@Override
public void setSelectedConnection(IConnection conn) {
    if (conn instanceof Connection) {
        Connection selectedConnection = (Connection) conn;
        usernameObservable.setValue(selectedConnection.getUsername());
        passwordObservable.setValue(selectedConnection.getPassword());
        rememberPasswordObservable.setValue(selectedConnection.isRememberPassword());
    } else if (conn instanceof NewConnectionMarker) {
        usernameObservable.setValue(null);
        passwordObservable.setValue(null);
    }
}
Also used : NewConnectionMarker(org.jboss.tools.openshift.common.core.connection.NewConnectionMarker) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection)

Example 5 with IConnection

use of org.jboss.tools.openshift.common.core.connection.IConnection in project jbosstools-openshift by jbosstools.

the class ServerResourceViewModelWithDeploymentConfigTest method shouldReturnConnection.

@Test
public void shouldReturnConnection() {
    // given
    // when
    IConnection connection = model.getConnection();
    // then
    assertThat(connection).isEqualTo(this.connection);
}
Also used : IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Test(org.junit.Test)

Aggregations

IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)40 Test (org.junit.Test)13 Connection (org.jboss.tools.openshift.core.connection.Connection)9 IStatus (org.eclipse.core.runtime.IStatus)5 IServer (org.eclipse.wst.server.core.IServer)5 CDKOpenshiftUtility (org.jboss.tools.openshift.cdk.server.core.internal.listeners.CDKOpenshiftUtility)5 ServiceManagerEnvironment (org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironment)5 ArrayList (java.util.ArrayList)3 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)3 Label (org.eclipse.swt.widgets.Label)3 IRoute (com.openshift.restclient.model.route.IRoute)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)2 ISelection (org.eclipse.jface.viewers.ISelection)2 ConnectionsRegistry (org.jboss.tools.openshift.common.core.connection.ConnectionsRegistry)2 NewConnectionMarker (org.jboss.tools.openshift.common.core.connection.NewConnectionMarker)2 IClient (com.openshift.restclient.IClient)1 ResourceKind (com.openshift.restclient.ResourceKind)1 IAuthorizationContext (com.openshift.restclient.authorization.IAuthorizationContext)1