Java tutorial
/* * Copyright 2009 IT Mill Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.logs.mavfun2; import javax.servlet.annotation.WebServlet; import org.apache.shiro.SecurityUtils; import org.apache.shiro.subject.Subject; import com.vaadin.annotations.Theme; import com.vaadin.annotations.VaadinServletConfiguration; import com.vaadin.navigator.Navigator; import com.vaadin.navigator.ViewChangeListener; import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinServlet; import com.vaadin.ui.UI; @Theme("shiroexample") public class ExampleUI extends UI implements ViewChangeListener { @WebServlet(value = "/*") @VaadinServletConfiguration(productionMode = false, ui = ExampleUI.class) public static class Servlet extends VaadinServlet { } @Override protected void init(VaadinRequest request) { Navigator navigator = new Navigator(this, this); navigator.addViewChangeListener(this); navigator.addView("", LoginView.class); if (SecurityUtils.getSubject().isAuthenticated()) { getUI().getNavigator().addView("secure", SecureView.class); } navigator.setErrorView(ErrorView.class); } public void markAsDirty() { // TODO Auto-generated method stub } @Override public boolean beforeViewChange(ViewChangeEvent event) { Subject currentUser = SecurityUtils.getSubject(); if (currentUser.isAuthenticated() && event.getViewName().equals("")) { event.getNavigator().navigateTo("secure"); return false; } if (!currentUser.isAuthenticated() && !event.getViewName().equals("")) { event.getNavigator().navigateTo(""); return false; } return true; } @Override public void afterViewChange(ViewChangeEvent event) { // TODO Auto-generated method stub } }