Search in sources :

Example 1 with OAuth2Authenticator

use of org.eclipse.che.ide.api.oauth.OAuth2Authenticator 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"));
                    }
                }
            });
        }
    });
}
Also used : OAuth2Authenticator(org.eclipse.che.ide.api.oauth.OAuth2Authenticator) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) OAuthStatus(org.eclipse.che.security.oauth.OAuthStatus) Operation(org.eclipse.che.api.promises.client.Operation) FunctionException(org.eclipse.che.api.promises.client.FunctionException) OperationException(org.eclipse.che.api.promises.client.OperationException) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 FunctionException (org.eclipse.che.api.promises.client.FunctionException)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 OAuth2Authenticator (org.eclipse.che.ide.api.oauth.OAuth2Authenticator)1 Project (org.eclipse.che.ide.api.resources.Project)1 OAuthStatus (org.eclipse.che.security.oauth.OAuthStatus)1