use of org.eclipse.che.security.oauth.OAuthStatus in project che by eclipse.
the class GitHubAuthenticatorImplTest method onAuthenticatedWhenGenerateKeysIsNotSelected.
@Test
public void onAuthenticatedWhenGenerateKeysIsNotSelected() throws Exception {
String userId = "userId";
OAuthStatus authStatus = mock(OAuthStatus.class);
CurrentUser user = mock(CurrentUser.class);
ProfileDto profile = mock(ProfileDto.class);
when(view.isGenerateKeysSelected()).thenReturn(false);
when(appContext.getCurrentUser()).thenReturn(user);
when(user.getProfile()).thenReturn(profile);
when(profile.getUserId()).thenReturn(userId);
gitHubAuthenticator.authenticate(null, getCallBack());
gitHubAuthenticator.onAuthenticated(authStatus);
verify(view).isGenerateKeysSelected();
verifyNoMoreInteractions(registry);
}
use of org.eclipse.che.security.oauth.OAuthStatus in project che by eclipse.
the class GitHubAuthenticatorImplTest method onAuthenticatedWhenGenerateKeysIsSuccess.
@Test
public void onAuthenticatedWhenGenerateKeysIsSuccess() throws Exception {
String userId = "userId";
OAuthStatus authStatus = mock(OAuthStatus.class);
SshKeyUploader keyProvider = mock(SshKeyUploader.class);
CurrentUser user = mock(CurrentUser.class);
ProfileDto profile = mock(ProfileDto.class);
when(view.isGenerateKeysSelected()).thenReturn(true);
when(registry.getUploader(GITHUB_HOST)).thenReturn(keyProvider);
when(appContext.getCurrentUser()).thenReturn(user);
when(user.getProfile()).thenReturn(profile);
when(profile.getUserId()).thenReturn(userId);
gitHubAuthenticator.authenticate(null, getCallBack());
gitHubAuthenticator.onAuthenticated(authStatus);
verify(keyProvider).uploadKey(eq(userId), generateKeyCallbackCaptor.capture());
AsyncCallback<Void> generateKeyCallback = generateKeyCallbackCaptor.getValue();
generateKeyCallback.onSuccess(null);
verify(view).isGenerateKeysSelected();
verify(registry).getUploader(eq(GITHUB_HOST));
verify(appContext).getCurrentUser();
verify(notificationManager).notify(anyString(), eq(SUCCESS), eq(FLOAT_MODE));
}
use of org.eclipse.che.security.oauth.OAuthStatus in project che by eclipse.
the class ProjectImporter method authUserAndRecallImport.
private Promise<Project> authUserAndRecallImport(final String providerName, final String authenticateUrl, final Path path, final SourceStorage sourceStorage, final ProjectNotificationSubscriber subscriber) {
return createFromAsyncRequest(new RequestCall<Project>() {
@Override
public void makeCall(final AsyncCallback<Project> callback) {
OAuth2Authenticator authenticator = oAuth2AuthenticatorRegistry.getAuthenticator(providerName);
if (authenticator == null) {
authenticator = oAuth2AuthenticatorRegistry.getAuthenticator("default");
}
authenticator.authenticate(OAuth2AuthenticatorUrlProvider.get(appContext.getMasterEndpoint(), 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(path, sourceStorage).then(new Operation<Project>() {
@Override
public void apply(Project project) throws OperationException {
callback.onSuccess(project);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
callback.onFailure(error.getCause());
}
});
} else {
subscriber.onFailure("Authentication cancelled");
callback.onFailure(new IllegalStateException("Authentication cancelled"));
}
}
});
}
});
}
Aggregations