| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.osgi.hybrid.api; |
| |
| import java.util.Map; |
| |
| import com.vaadin.server.Extension; |
| import com.vaadin.server.VaadinRequest; |
| import com.vaadin.ui.UI; |
| |
| import org.eclipse.osbp.ui.api.useraccess.IUserAccessService; |
| import org.eclipse.osbp.webserver.messagequeue.ECXMqMessageAttribute; |
| import org.eclipse.osbp.webserver.messagequeue.ECXMqMessageEvent; |
| |
| /** |
| * This abstract class has to be used as extended class in all Vaadin applications, which need |
| * Shiro Authentication support and/or CCNG Hybrid support! |
| * Just extend this class and add any extending functionality! |
| */ |
| @SuppressWarnings("serial") |
| abstract public class AbstractHybridVaadinUI extends UI implements IHybridVaadinVaaclipseListener { |
| |
| private HybridVaadinVaaclipseConnector fConnector; |
| |
| protected IUserAccessService getUserAccessService() { |
| return fConnector.getUserAccessService(); |
| } |
| |
| /** |
| * You <b>must call this at the start of the overriden init()</b> |
| */ |
| protected final Extension preInit(VaadinRequest request) { |
| fConnector = HybridVaadinVaaclipseConnector.instance(null); |
| fConnector.addListener(this); |
| return null; // fConnector.createRefresher(); |
| } |
| |
| /** |
| * You <b>must call this at the end of the overriden init()</b> |
| */ |
| protected final void postInit(VaadinRequest request) { |
| fConnector.postInit(request); |
| } |
| |
| /** |
| * React in the application according to <code>authenticated</code> |
| * @param authenticated true if the user is authenticated now! |
| */ |
| public void setAuthenticated(boolean authenticated) { |
| fConnector.setAuthenticated(authenticated); |
| } |
| |
| /** |
| * Try to authenticate with the credentials given!<br> |
| * {@link #setAuthenticated(boolean)} will explicit be called! |
| * @param portalId |
| * @param userName |
| * @param password |
| * @return true if the user was authenticated successful |
| */ |
| protected boolean tryToAuthenticate(String portalId, String userName, String password) { |
| return fConnector.tryToAuthenticate(portalId, userName, password); |
| } |
| |
| /** |
| * Logout from the Shiro API and send a LOGOUT event via ActiveMQ |
| */ |
| protected void logout() { |
| fConnector.logout(); |
| } |
| |
| /** |
| * handle any message received via ActiveMQ |
| * @param event |
| * @param body |
| */ |
| @Override |
| public final boolean onMessage(ECXMqMessageEvent event, Map<ECXMqMessageAttribute, Object> body) { |
| boolean retcode = false; |
| switch (event) { |
| // !!! handled by connector ... |
| case TRY_AUTHENTICATE: |
| case DISPOSE: |
| case LOGOUT: |
| break; |
| // ... handled by connector !!! |
| default: |
| break; |
| } |
| return false; |
| } |
| } |