Java tutorial
/* * WicketApplication.java * Copyright (c) 2009 Felix Cachaldora Sanchez * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE */ package com.wickettasks.web.application; import org.apache.wicket.Application; import org.apache.wicket.Request; import org.apache.wicket.Response; import org.apache.wicket.Session; import org.apache.wicket.authentication.AuthenticatedWebApplication; import org.apache.wicket.authentication.AuthenticatedWebSession; import org.apache.wicket.authorization.strategies.role.Roles; import org.apache.wicket.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy; import org.apache.wicket.injection.web.InjectorHolder; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.spring.injection.annot.SpringBean; import org.apache.wicket.spring.injection.annot.SpringComponentInjector; import org.springframework.stereotype.Component; import com.wickettasks.business.services.user.UserService; import com.wickettasks.web.pages.LoginPage; import com.wickettasks.web.pages.NewUserPage; import com.wickettasks.web.pages.TasksPage; import com.wickettasks.web.pages.UserTaskListsPage; import com.wickettasks.web.session.WicketTasksSession; /** * Application object for your web application. If you want to run this application without deploying, run the Start class. * * @see wicket.myproject.Start#main(String[]) */ @Component public class WicketTasksApplication extends AuthenticatedWebApplication { @SpringBean private UserService userService; @Override protected void init() { super.init(); addComponentInstantiationListener(new SpringComponentInjector(this)); mountBookmarkablePage("/login", LoginPage.class); mountBookmarkablePage("/lists", UserTaskListsPage.class); mountBookmarkablePage("/singup", NewUserPage.class); mountBookmarkablePage("/lists/tasks", TasksPage.class); getSecuritySettings().setAuthorizationStrategy(new MetaDataRoleAuthorizationStrategy(this)); MetaDataRoleAuthorizationStrategy.authorize(TasksPage.class, Roles.USER); MetaDataRoleAuthorizationStrategy.authorize(UserTaskListsPage.class, Roles.USER); InjectorHolder.getInjector().inject(this); }; @SuppressWarnings("unchecked") public Class getHomePage() { return UserTaskListsPage.class; } @Override public Session newSession(Request request, Response response) { return new WicketTasksSession(request); } @Override protected Class<? extends WebPage> getSignInPageClass() { return LoginPage.class; } @Override protected Class<? extends AuthenticatedWebSession> getWebSessionClass() { return WicketTasksSession.class; } public UserService getUserService() { return this.userService; } public static WicketTasksApplication get() { return (WicketTasksApplication) Application.get(); } }