Skip to content

Commit e6a68d6

Browse files
author
Max Shaposhnik
committed
CODENVY-170 add promise-based authorization method to OAUth authenticators; prevent project synchronizing when factory used
Signed-off-by: Max Shaposhnik <mshaposhnik@codenvy.com>
1 parent 83b066a commit e6a68d6

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

core/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/oauth/OAuth2Authenticator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import com.google.gwt.user.client.rpc.AsyncCallback;
1414

15+
import org.eclipse.che.api.promises.client.Promise;
1516
import org.eclipse.che.security.oauth.OAuthStatus;
1617

1718
/**
@@ -21,5 +22,7 @@ public interface OAuth2Authenticator {
2122

2223
void authorize(String authenticatorUrl, AsyncCallback<OAuthStatus> callback);
2324

25+
Promise<OAuthStatus> authorize(String authenticationUrl);
26+
2427
String getProviderName();
2528
}

core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/oauth/DefaultOAuthAuthenticatorImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
*******************************************************************************/
1111
package org.eclipse.che.ide.oauth;
1212

13+
import com.google.gwt.core.client.Callback;
1314
import com.google.gwt.user.client.rpc.AsyncCallback;
1415
import com.google.inject.Inject;
1516

17+
import org.eclipse.che.api.promises.client.Promise;
18+
import org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper;
19+
import org.eclipse.che.api.promises.client.callback.CallbackPromiseHelper;
20+
import org.eclipse.che.api.promises.client.js.Promises;
1621
import org.eclipse.che.ide.CoreLocalizationConstant;
1722
import org.eclipse.che.ide.api.oauth.OAuth2Authenticator;
1823
import org.eclipse.che.ide.ui.dialogs.CancelCallback;
@@ -50,6 +55,18 @@ public void authorize(String authenticationUrl, @NotNull final AsyncCallback<OAu
5055
showDialog();
5156
}
5257

58+
public Promise<OAuthStatus> authorize(String authenticationUrl) {
59+
this.authenticationUrl = authenticationUrl;
60+
61+
return AsyncPromiseHelper.createFromAsyncRequest(new AsyncPromiseHelper.RequestCall<OAuthStatus>() {
62+
@Override
63+
public void makeCall(AsyncCallback<OAuthStatus> callback) {
64+
DefaultOAuthAuthenticatorImpl.this.callback = callback;
65+
showDialog();
66+
}
67+
});
68+
}
69+
5370
private void showDialog() {
5471
dialogFactory.createConfirmDialog(localizationConstant.authorizationDialogTitle(), localizationConstant.authorizationDialogText(), new ConfirmCallback() {
5572
@Override

core/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/synchronize/ProjectConfigSynchronizationListener.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public void cancelled() {
101101

102102
@Override
103103
public void onBeforeExpand(final BeforeExpandNodeEvent event) {
104+
if (appContext.getFactory() != null) {
105+
return;
106+
}
104107
Node expandedNode = event.getNode();
105108

106109
if (!(expandedNode instanceof ProjectNode)) {

plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/authenticator/GitHubAuthenticatorImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
import org.eclipse.che.api.promises.client.Operation;
1919
import org.eclipse.che.api.promises.client.OperationException;
20+
import org.eclipse.che.api.promises.client.Promise;
2021
import org.eclipse.che.api.promises.client.PromiseError;
22+
import org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper;
2123
import org.eclipse.che.api.ssh.gwt.client.SshServiceClient;
2224
import org.eclipse.che.api.ssh.shared.dto.SshPairDto;
2325
import org.eclipse.che.ide.api.app.AppContext;
@@ -86,6 +88,18 @@ public void authorize(String authenticationUrl, @NotNull final AsyncCallback<OAu
8688
view.showDialog();
8789
}
8890

91+
public Promise<OAuthStatus> authorize(String authenticationUrl) {
92+
this.authenticationUrl = authenticationUrl;
93+
94+
return AsyncPromiseHelper.createFromAsyncRequest(new AsyncPromiseHelper.RequestCall<OAuthStatus>() {
95+
@Override
96+
public void makeCall(AsyncCallback<OAuthStatus> callback) {
97+
GitHubAuthenticatorImpl.this.callback = callback;
98+
view.showDialog();
99+
}
100+
});
101+
}
102+
89103
@Override
90104
public String getProviderName() {
91105
return GITHUB;

0 commit comments

Comments
 (0)