Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package edu.bbu.security.web.controllers; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; /** * * @author zsolt.vitalyos */ @Controller public class MainController { @RequestMapping(value = { "/", "/main**" }, method = RequestMethod.GET) public ModelAndView welcomePage() { System.out.println("root lofasz"); ModelAndView model = new ModelAndView(); model.addObject("title", "Spring Security Custom Login Form"); model.addObject("message", "This is welcome page!"); model.setViewName("hello"); return model; } @RequestMapping(value = "/admin**", method = RequestMethod.GET) public ModelAndView adminPage() { System.out.println("lofasz admin"); ModelAndView model = new ModelAndView(); model.addObject("title", "Spring Security Custom Login Form"); model.addObject("message", "This is protected page!"); model.setViewName("admin"); return model; } @RequestMapping(value = "/login", method = RequestMethod.GET) public ModelAndView login(@RequestParam(value = "error", required = false) String error, @RequestParam(value = "logout", required = false) String logout) { System.out.println("lofasz login"); ModelAndView model = new ModelAndView(); if (error != null) { model.addObject("error", "Invalid username and password!"); } if (logout != null) { model.addObject("msg", "You've been logged out successfully."); } model.setViewName("login"); return model; } }