From e6a68d60391584b4967b58697bb2ea962500b309 Mon Sep 17 00:00:00 2001 From: Max Shaposhnik Date: Tue, 1 Mar 2016 11:54:58 +0200 Subject: [PATCH] CODENVY-170 add promise-based authorization method to OAUth authenticators; prevent project synchronizing when factory used Signed-off-by: Max Shaposhnik --- .../che/ide/api/oauth/OAuth2Authenticator.java | 3 +++ .../oauth/DefaultOAuthAuthenticatorImpl.java | 17 +++++++++++++++++ .../ProjectConfigSynchronizationListener.java | 3 +++ .../authenticator/GitHubAuthenticatorImpl.java | 14 ++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/core/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/oauth/OAuth2Authenticator.java b/core/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/oauth/OAuth2Authenticator.java index 9b7420c738..bbd14ebc2b 100644 --- a/core/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/oauth/OAuth2Authenticator.java +++ b/core/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/oauth/OAuth2Authenticator.java @@ -12,6 +12,7 @@ package org.eclipse.che.ide.api.oauth; import com.google.gwt.user.client.rpc.AsyncCallback; +import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.security.oauth.OAuthStatus; /** @@ -21,5 +22,7 @@ public interface OAuth2Authenticator { void authorize(String authenticatorUrl, AsyncCallback callback); + Promise authorize(String authenticationUrl); + String getProviderName(); } diff --git a/core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/oauth/DefaultOAuthAuthenticatorImpl.java b/core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/oauth/DefaultOAuthAuthenticatorImpl.java index b89315ae2a..f717696567 100644 --- a/core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/oauth/DefaultOAuthAuthenticatorImpl.java +++ b/core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/oauth/DefaultOAuthAuthenticatorImpl.java @@ -10,9 +10,14 @@ *******************************************************************************/ package org.eclipse.che.ide.oauth; +import com.google.gwt.core.client.Callback; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.inject.Inject; +import org.eclipse.che.api.promises.client.Promise; +import org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper; +import org.eclipse.che.api.promises.client.callback.CallbackPromiseHelper; +import org.eclipse.che.api.promises.client.js.Promises; import org.eclipse.che.ide.CoreLocalizationConstant; import org.eclipse.che.ide.api.oauth.OAuth2Authenticator; import org.eclipse.che.ide.ui.dialogs.CancelCallback; @@ -50,6 +55,18 @@ public class DefaultOAuthAuthenticatorImpl implements OAuth2Authenticator, OAuth showDialog(); } + public Promise authorize(String authenticationUrl) { + this.authenticationUrl = authenticationUrl; + + return AsyncPromiseHelper.createFromAsyncRequest(new AsyncPromiseHelper.RequestCall() { + @Override + public void makeCall(AsyncCallback callback) { + DefaultOAuthAuthenticatorImpl.this.callback = callback; + showDialog(); + } + }); + } + private void showDialog() { dialogFactory.createConfirmDialog(localizationConstant.authorizationDialogTitle(), localizationConstant.authorizationDialogText(), new ConfirmCallback() { @Override diff --git a/core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/synchronize/ProjectConfigSynchronizationListener.java b/core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/synchronize/ProjectConfigSynchronizationListener.java index 5a96727072..f0004afcf5 100644 --- a/core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/synchronize/ProjectConfigSynchronizationListener.java +++ b/core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/synchronize/ProjectConfigSynchronizationListener.java @@ -101,6 +101,9 @@ public class ProjectConfigSynchronizationListener implements BeforeExpandNodeEve @Override public void onBeforeExpand(final BeforeExpandNodeEvent event) { + if (appContext.getFactory() != null) { + return; + } Node expandedNode = event.getNode(); if (!(expandedNode instanceof ProjectNode)) { diff --git a/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/authenticator/GitHubAuthenticatorImpl.java b/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/authenticator/GitHubAuthenticatorImpl.java index e66c9c9f50..751f2d4438 100644 --- a/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/authenticator/GitHubAuthenticatorImpl.java +++ b/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/authenticator/GitHubAuthenticatorImpl.java @@ -17,7 +17,9 @@ import com.google.inject.Inject; import org.eclipse.che.api.promises.client.Operation; import org.eclipse.che.api.promises.client.OperationException; +import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.api.promises.client.PromiseError; +import org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper; import org.eclipse.che.api.ssh.gwt.client.SshServiceClient; import org.eclipse.che.api.ssh.shared.dto.SshPairDto; import org.eclipse.che.ide.api.app.AppContext; @@ -86,6 +88,18 @@ public class GitHubAuthenticatorImpl implements OAuth2Authenticator, OAuthCallba view.showDialog(); } + public Promise authorize(String authenticationUrl) { + this.authenticationUrl = authenticationUrl; + + return AsyncPromiseHelper.createFromAsyncRequest(new AsyncPromiseHelper.RequestCall() { + @Override + public void makeCall(AsyncCallback callback) { + GitHubAuthenticatorImpl.this.callback = callback; + view.showDialog(); + } + }); + } + @Override public String getProviderName() { return GITHUB;