| /******************************************************************************* |
| * Copyright (c) 2012-2013 EclipseSource Muenchen GmbH and others. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: Max Hohenegger (bug 371196) |
| ******************************************************************************/ |
| package org.eclipse.emf.emfstore.fx.internal.projects; |
| |
| import org.eclipse.emf.emfstore.client.ESServer; |
| import org.eclipse.emf.emfstore.client.ESUsersession; |
| import org.eclipse.emf.emfstore.client.ESWorkspaceProvider; |
| import org.eclipse.emf.emfstore.client.sessionprovider.ESAbstractSessionProvider; |
| import org.eclipse.emf.emfstore.internal.client.model.ServerInfo; |
| import org.eclipse.emf.emfstore.internal.client.model.impl.api.ESUsersessionImpl; |
| import org.eclipse.emf.emfstore.internal.server.exceptions.AccessControlException; |
| import org.eclipse.emf.emfstore.server.exceptions.ESException; |
| |
| /** |
| * An implementation of a session providers that uses a server selection and a login dialog |
| * to authenticate users. |
| * |
| * @author wesendon |
| * @author emueller |
| */ |
| // TODO api |
| @SuppressWarnings("restriction") |
| public class BasicUISessionProvider extends ESAbstractSessionProvider { |
| |
| /** |
| * |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emf.emfstore.internal.client.model.connectionmanager.SessionProvider#provideUsersession(org.eclipse.emf.emfstore.internal.client.model.ServerInfo) |
| */ |
| @Override |
| public ESUsersession provideUsersession(ESServer server) throws ESException { |
| if (server == null) { |
| // Integer userInput = RunInUI.runWithResult(new Callable<Integer>() { |
| // public Integer call() throws Exception { |
| // // try to retrieve a server info by showing a server info selection dialog |
| // ServerInfoSelectionDialog dialog = new ServerInfoSelectionDialog( |
| // Display.getCurrent().getActiveShell(), |
| // ESWorkspaceProviderImpl.getInstance().getInternalWorkspace().getServerInfos()); |
| // int input = dialog.open(); |
| // selectedServerInfo = dialog.getResult(); |
| // return input; |
| // } |
| // }); |
| // if (userInput == Dialog.OK) { |
| // server = selectedServerInfo; |
| // } else if (userInput == Dialog.CANCEL) { |
| // throw new LoginCanceledException("Operation canceled by user."); |
| // } |
| server = ESWorkspaceProvider.INSTANCE.getWorkspace().getServers().get(0); |
| } |
| if (server == null) { |
| throw new AccessControlException("Couldn't determine which server to connect."); |
| } |
| |
| return loginServerInfo(server); |
| } |
| |
| /** |
| * Extracted from {@link #provideUsersession(ServerInfo)} in order to allow overwriting. This method logs in a given |
| * server. |
| * |
| * @param server given server |
| * @return Usersession |
| * @throws ESException in case of an exception |
| */ |
| protected ESUsersession loginServerInfo(ESServer server) throws ESException { |
| // TODO Short cut for logged in sessions to avoid loginscreen. We have to discuss whether this is really |
| // wanted. |
| if (server.getLastUsersession() != null && server.getLastUsersession().isLoggedIn()) { |
| return server.getLastUsersession(); |
| } |
| // return new LoginDialogController().login(server); |
| return server.login("super", "super"); |
| } |
| |
| @Override |
| public ESUsersession login(ESUsersession usersession) throws ESException { |
| if (usersession != null) { |
| ((ESUsersessionImpl) usersession).setPassword("super"); |
| usersession.refresh(); |
| return usersession; |
| // return new LoginDialogController().login(usersession); |
| // return usersession.getServer().login("super", "super"); |
| } |
| return null; |
| } |
| } |