Merge pull request #585 from eclipse/CODENVY-170
CODENVY-170 add promise-based authorization method to OAUth authenticators; prevent project synchronizing when factory used6.19.x
commit
88b79179c1
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -19,7 +20,9 @@ import org.eclipse.che.security.oauth.OAuthStatus;
|
|||
*/
|
||||
public interface OAuth2Authenticator {
|
||||
|
||||
void authorize(String authenticatorUrl, AsyncCallback<OAuthStatus> callback);
|
||||
void authenticate(String authenticationUrl, AsyncCallback<OAuthStatus> callback);
|
||||
|
||||
Promise<OAuthStatus> authenticate(String authenticationUrl);
|
||||
|
||||
String getProviderName();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -44,12 +49,24 @@ public class DefaultOAuthAuthenticatorImpl implements OAuth2Authenticator, OAuth
|
|||
}
|
||||
|
||||
@Override
|
||||
public void authorize(String authenticationUrl, @NotNull final AsyncCallback<OAuthStatus> callback) {
|
||||
public void authenticate(String authenticationUrl, @NotNull final AsyncCallback<OAuthStatus> callback) {
|
||||
this.authenticationUrl = authenticationUrl;
|
||||
this.callback = callback;
|
||||
showDialog();
|
||||
}
|
||||
|
||||
public Promise<OAuthStatus> authenticate(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
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -175,23 +175,23 @@ public class ProjectImporter extends AbstractImporter {
|
|||
if(authenticator == null) {
|
||||
authenticator = oAuth2AuthenticatorRegistry.getAuthenticator("default");
|
||||
}
|
||||
authenticator.authorize(OAuth2AuthenticatorUrlProvider.get(restContext, authenticateUrl),
|
||||
new AsyncCallback<OAuthStatus>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
callback.onFailure(new Exception(caught.getMessage()));
|
||||
}
|
||||
authenticator.authenticate(OAuth2AuthenticatorUrlProvider.get(restContext, authenticateUrl),
|
||||
new AsyncCallback<OAuthStatus>() {
|
||||
@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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -80,12 +82,24 @@ public class GitHubAuthenticatorImpl implements OAuth2Authenticator, OAuthCallba
|
|||
}
|
||||
|
||||
@Override
|
||||
public void authorize(String authenticationUrl, @NotNull final AsyncCallback<OAuthStatus> callback) {
|
||||
public void authenticate(String authenticationUrl, @NotNull final AsyncCallback<OAuthStatus> callback) {
|
||||
this.authenticationUrl = authenticationUrl;
|
||||
this.callback = callback;
|
||||
view.showDialog();
|
||||
}
|
||||
|
||||
public Promise<OAuthStatus> authenticate(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;
|
||||
|
|
|
|||
|
|
@ -282,9 +282,9 @@ public class GithubImporterPagePresenter extends AbstractWizardPage<ProjectConfi
|
|||
*/
|
||||
private void authorize() {
|
||||
showProcessing(true);
|
||||
gitHubAuthenticator.authorize(
|
||||
gitHubAuthenticator.authenticate(
|
||||
OAuth2AuthenticatorUrlProvider.get(restContext, "github", appContext.getCurrentUser().getProfile().getUserId(),
|
||||
Lists.asList("user", new String[] {"repo", "write:public_key"})),
|
||||
Lists.asList("user", new String[]{"repo", "write:public_key"})),
|
||||
new AsyncCallback<OAuthStatus>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ public class GitHubAuthenticatorImplTest {
|
|||
@Test
|
||||
public void dialogShouldBeShow() throws Exception {
|
||||
AsyncCallback<OAuthStatus> 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.<ConfirmCallback>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());
|
||||
|
|
|
|||
|
|
@ -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<OAuthStatus> 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<OAuthStatus> asyncCallback = asyncCallbackCaptor.getValue();
|
||||
asyncCallback.onSuccess(null);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue