CODENVY-170 add promise-based authorization method to OAUth authenticators; prevent project synchronizing when factory used

Signed-off-by: Max Shaposhnik <mshaposhnik@codenvy.com>
6.19.x
Max Shaposhnik 2016-03-01 11:54:58 +02:00
parent 83b066aa6c
commit e6a68d6039
4 changed files with 37 additions and 0 deletions

View File

@ -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<OAuthStatus> callback);
Promise<OAuthStatus> authorize(String authenticationUrl);
String getProviderName();
}

View File

@ -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<OAuthStatus> authorize(String authenticationUrl) {
this.authenticationUrl = authenticationUrl;
return AsyncPromiseHelper.createFromAsyncRequest(new AsyncPromiseHelper.RequestCall<OAuthStatus>() {
@Override
public void makeCall(AsyncCallback<OAuthStatus> callback) {
DefaultOAuthAuthenticatorImpl.this.callback = callback;
showDialog();
}
});
}
private void showDialog() {
dialogFactory.createConfirmDialog(localizationConstant.authorizationDialogTitle(), localizationConstant.authorizationDialogText(), new ConfirmCallback() {
@Override

View File

@ -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)) {

View File

@ -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<OAuthStatus> authorize(String authenticationUrl) {
this.authenticationUrl = authenticationUrl;
return AsyncPromiseHelper.createFromAsyncRequest(new AsyncPromiseHelper.RequestCall<OAuthStatus>() {
@Override
public void makeCall(AsyncCallback<OAuthStatus> callback) {
GitHubAuthenticatorImpl.this.callback = callback;
view.showDialog();
}
});
}
@Override
public String getProviderName() {
return GITHUB;