Results 1 to 6 of 6

Thread: Handle expired session

  1. #1
    Join Date
    Oct 2006
    Posts
    27

    Default Handle expired session

    Hi ,
    I am using spring mvc 2.5 and annotaton based.
    Can anybody advice me what is the best approch for handling the expired http session and redirecting teh user to login page with valid error message?

    In my controller I use

    Code:
    @Controller
    @SessionAttributes ({"user","dmsUser"})
    @RequestMapping("/userDetails.do")
    public class UserController {
    
    ===========================
    
    and handler method
    @RequestMapping(method = RequestMethod.GET)
      public String setUpForm(@RequestParam("userId")
      String userId, @ModelAttribute("user")
      DMSUser user, Model model) {
    
        logger.info("Loading User details");
        String forward = "";
        if(userId==null||Integer.parseInt(userId)==0){
          if (user == null || user.getPermissions().get("manageuser") < 2) {
    
            model.addAttribute("message", "unauhorized operation");
            return "dmsHome";
            
          }
          else{
            model.addAttribute("dmsUser", new DMSUser());
            model.addAttribute("roles", userService.getRoles());
            return "dmsUserDetails";
          }
          
        }
    
    
    ......
    I am getting
    org.springframework.web.HttpSessionRequiredExcepti on: Session attribute 'user' required - not found in session
    Once the session expired

    Thanks in advance
    Shaiju

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Either write a ServletFilter or HandlerInterceptor that check if there is a session and if there is a valid user. If not redirect to login page.

    However that still leaves you with another problem, everything that was in the session isn't there anymore (the expired session is destroyed). So you probably run into other issues next.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Oct 2006
    Posts
    27

    Default

    Can I annotate the controller to use an Interceptor,is there a way?
    Also I am using WebBindingInitializer as follows
    Code:
    class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    		<property name="webBindingInitializer">
    			<bean
    				class="com.scientia.dms.commons.util.DMSBindingInitializer" />
    		</property>
    So when I try to configure interceptors here ,it thows exception saying invalid property "interceptors".

    Please advice

    Shaiju

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    You cannot set a interceptor on the AnnotationMethodHandlerAdapter, you can set it on the DefaultAnnotationsHandlerMapping
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Oct 2006
    Posts
    27

    Default

    So if I want to configure both the webBindingInitializer and the interceptor ,
    I need to have two different Handler mappings?

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    No. You need a

    - DefaultAnnotationHandlerMapper
    - AnnotationMethodHandlerAdapter

    Which are 2 different things. 1 is used for mapping urls to a controller, the other one is used for executing the correct method.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •