From e6a68d60391584b4967b58697bb2ea962500b309 Mon Sep 17 00:00:00 2001 From: Max Shaposhnik Date: Tue, 1 Mar 2016 11:54:58 +0200 Subject: [PATCH 1/2] 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; From 5f9026eebf91ecc1dd28aadf2104d3ae5a10addd Mon Sep 17 00:00:00 2001 From: Max Shaposhnik Date: Tue, 1 Mar 2016 12:15:42 +0200 Subject: [PATCH 2/2] CODENVY-170 rename autghorize method to authenticate Signed-off-by: Max Shaposhnik --- .../ide/api/oauth/OAuth2Authenticator.java | 4 +-- .../oauth/DefaultOAuthAuthenticatorImpl.java | 4 +-- .../projectimport/wizard/ProjectImporter.java | 32 +++++++++---------- .../GitHubAuthenticatorImpl.java | 4 +-- .../page/GithubImporterPagePresenter.java | 4 +-- .../GitHubAuthenticatorImplTest.java | 10 +++--- .../page/GithubImporterPagePresenterTest.java | 4 +-- 7 files changed, 31 insertions(+), 31 deletions(-) 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 bbd14ebc2b..0bcffea5f6 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 @@ -20,9 +20,9 @@ import org.eclipse.che.security.oauth.OAuthStatus; */ public interface OAuth2Authenticator { - void authorize(String authenticatorUrl, AsyncCallback callback); + void authenticate(String authenticationUrl, AsyncCallback callback); - Promise authorize(String authenticationUrl); + Promise authenticate(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 f717696567..ca82283427 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 @@ -49,13 +49,13 @@ public class DefaultOAuthAuthenticatorImpl implements OAuth2Authenticator, OAuth } @Override - public void authorize(String authenticationUrl, @NotNull final AsyncCallback callback) { + public void authenticate(String authenticationUrl, @NotNull final AsyncCallback callback) { this.authenticationUrl = authenticationUrl; this.callback = callback; showDialog(); } - public Promise authorize(String authenticationUrl) { + public Promise authenticate(String authenticationUrl) { this.authenticationUrl = authenticationUrl; return AsyncPromiseHelper.createFromAsyncRequest(new AsyncPromiseHelper.RequestCall() { diff --git a/core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/projectimport/wizard/ProjectImporter.java b/core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/projectimport/wizard/ProjectImporter.java index 10655aa70f..375178f2d8 100644 --- a/core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/projectimport/wizard/ProjectImporter.java +++ b/core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/projectimport/wizard/ProjectImporter.java @@ -175,23 +175,23 @@ public class ProjectImporter extends AbstractImporter { if(authenticator == null) { authenticator = oAuth2AuthenticatorRegistry.getAuthenticator("default"); } - authenticator.authorize(OAuth2AuthenticatorUrlProvider.get(restContext, authenticateUrl), - new AsyncCallback() { - @Override - public void onFailure(Throwable caught) { - callback.onFailure(new Exception(caught.getMessage())); - } + authenticator.authenticate(OAuth2AuthenticatorUrlProvider.get(restContext, authenticateUrl), + new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + callback.onFailure(new Exception(caught.getMessage())); + } - @Override - public void onSuccess(OAuthStatus result) { - if (!result.equals(OAuthStatus.NOT_PERFORMED)) { - doImport(pathToProject, projectName, sourceStorage); - } else { - subscriber.onFailure("Authentication cancelled"); - callback.onCompleted(); - } - } - }); + @Override + public void onSuccess(OAuthStatus result) { + if (!result.equals(OAuthStatus.NOT_PERFORMED)) { + doImport(pathToProject, projectName, sourceStorage); + } else { + subscriber.onFailure("Authentication cancelled"); + callback.onCompleted(); + } + } + }); } 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 751f2d4438..eb73f56e83 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 @@ -82,13 +82,13 @@ public class GitHubAuthenticatorImpl implements OAuth2Authenticator, OAuthCallba } @Override - public void authorize(String authenticationUrl, @NotNull final AsyncCallback callback) { + public void authenticate(String authenticationUrl, @NotNull final AsyncCallback callback) { this.authenticationUrl = authenticationUrl; this.callback = callback; view.showDialog(); } - public Promise authorize(String authenticationUrl) { + public Promise authenticate(String authenticationUrl) { this.authenticationUrl = authenticationUrl; return AsyncPromiseHelper.createFromAsyncRequest(new AsyncPromiseHelper.RequestCall() { diff --git a/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/importer/page/GithubImporterPagePresenter.java b/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/importer/page/GithubImporterPagePresenter.java index 5a0ec38c82..888638d4ae 100644 --- a/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/importer/page/GithubImporterPagePresenter.java +++ b/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/importer/page/GithubImporterPagePresenter.java @@ -282,9 +282,9 @@ public class GithubImporterPagePresenter extends AbstractWizardPage() { @Override public void onFailure(Throwable caught) { diff --git a/plugins/plugin-github/che-plugin-github-ext-github/src/test/java/org/eclipse/che/ide/ext/github/client/authenticator/GitHubAuthenticatorImplTest.java b/plugins/plugin-github/che-plugin-github-ext-github/src/test/java/org/eclipse/che/ide/ext/github/client/authenticator/GitHubAuthenticatorImplTest.java index 503de8c444..79881714fd 100644 --- a/plugins/plugin-github/che-plugin-github-ext-github/src/test/java/org/eclipse/che/ide/ext/github/client/authenticator/GitHubAuthenticatorImplTest.java +++ b/plugins/plugin-github/che-plugin-github-ext-github/src/test/java/org/eclipse/che/ide/ext/github/client/authenticator/GitHubAuthenticatorImplTest.java @@ -128,7 +128,7 @@ public class GitHubAuthenticatorImplTest { @Test public void dialogShouldBeShow() throws Exception { AsyncCallback callback = getCallBack(); - gitHubAuthenticator.authorize(null, callback); + gitHubAuthenticator.authenticate(null, callback); verify(view).showDialog(); assertThat(gitHubAuthenticator.callback, is(callback)); @@ -171,7 +171,7 @@ public class GitHubAuthenticatorImplTest { when(user.getProfile()).thenReturn(profile); when(profile.getId()).thenReturn(userId); - gitHubAuthenticator.authorize(null, getCallBack()); + gitHubAuthenticator.authenticate(null, getCallBack()); gitHubAuthenticator.onAuthenticated(authStatus); verify(view).isGenerateKeysSelected(); @@ -198,7 +198,7 @@ public class GitHubAuthenticatorImplTest { when(user.getProfile()).thenReturn(profile); when(profile.getId()).thenReturn(userId); - gitHubAuthenticator.authorize(null, getCallBack()); + gitHubAuthenticator.authenticate(null, getCallBack()); gitHubAuthenticator.onAuthenticated(authStatus); verify(keyProvider).uploadKey(eq(userId), generateKeyCallbackCaptor.capture()); @@ -229,7 +229,7 @@ public class GitHubAuthenticatorImplTest { when(profile.getId()).thenReturn(userId); when(dialogFactory.createMessageDialog(anyString(), anyString(), Matchers.anyObject())).thenReturn(messageDialog); - gitHubAuthenticator.authorize(null, getCallBack()); + gitHubAuthenticator.authenticate(null, getCallBack()); gitHubAuthenticator.onAuthenticated(authStatus); verify(keyProvider).uploadKey(eq(userId), generateKeyCallbackCaptor.capture()); @@ -266,7 +266,7 @@ public class GitHubAuthenticatorImplTest { when(pair.getName()).thenReturn(GITHUB_HOST); when(pair.getService()).thenReturn(SshKeyManagerPresenter.GIT_SSH_SERVICE); - gitHubAuthenticator.authorize(null, getCallBack()); + gitHubAuthenticator.authenticate(null, getCallBack()); gitHubAuthenticator.onAuthenticated(authStatus); verify(keyUploader).uploadKey(eq(userId), generateKeyCallbackCaptor.capture()); diff --git a/plugins/plugin-github/che-plugin-github-ext-github/src/test/java/org/eclipse/che/ide/ext/github/client/importer/page/GithubImporterPagePresenterTest.java b/plugins/plugin-github/che-plugin-github-ext-github/src/test/java/org/eclipse/che/ide/ext/github/client/importer/page/GithubImporterPagePresenterTest.java index a3a715cb44..929931100c 100644 --- a/plugins/plugin-github/che-plugin-github-ext-github/src/test/java/org/eclipse/che/ide/ext/github/client/importer/page/GithubImporterPagePresenterTest.java +++ b/plugins/plugin-github/che-plugin-github-ext-github/src/test/java/org/eclipse/che/ide/ext/github/client/importer/page/GithubImporterPagePresenterTest.java @@ -420,7 +420,7 @@ public class GithubImporterPagePresenterTest { verify(gitHubClientService).getUserInfo(); verify(gitHubClientService).getOrganizations(); - verify(gitHubAuthenticator).authorize(anyString(), asyncCallbackCaptor.capture()); + verify(gitHubAuthenticator).authenticate(anyString(), asyncCallbackCaptor.capture()); AsyncCallback asyncCallback = asyncCallbackCaptor.getValue(); asyncCallback.onFailure(exception); @@ -463,7 +463,7 @@ public class GithubImporterPagePresenterTest { verify(gitHubClientService).getUserInfo(); verify(gitHubClientService).getOrganizations(); - verify(gitHubAuthenticator).authorize(anyString(), asyncCallbackCaptor.capture()); + verify(gitHubAuthenticator).authenticate(anyString(), asyncCallbackCaptor.capture()); AsyncCallback asyncCallback = asyncCallbackCaptor.getValue(); asyncCallback.onSuccess(null);