Results 1 to 4 of 4

Thread: Spring MVC 3 session Tracking

  1. #1
    Join Date
    May 2012
    Posts
    5

    Default Spring MVC 3 session Tracking

    Hi
    Which one is best to use whether HttpSession/@SessionAttribute to user session?

    please provide some steps/references to session tracking

    Thanks in Advance

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

    Default

    Depends on what you want and what your usecase is.
    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
    May 2012
    Posts
    5

    Default

    Please find the Use case

    After the below code I need to Track session for the user "xxxSyed"


    Code:
     UserDetails userDetails= myUserService.loadUserByUsername(principal);
    		 //UserDetails userDetails= myUserService.loadUserByUsername("xxxSyed");
    		
    		 for (GrantedAuthority auth : userDetails.getAuthorities()) {
    	        		 }
    				 Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    					 PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(userDetails.getUsername(),"");
    
    			 authentication = authenticationManager.authenticate(token);
                 // Setup the security context, aka authenticate
                 SecurityContextHolder.getContext().setAuthentication(authentication);
    				
    		 		 
                 for (GrantedAuthority auth : SecurityContextHolder.getContext().getAuthentication().getAuthorities()) {
     	        	System.out.println(auth.getAuthority());
     		 }
    		
                 
    		 SecurityContextHolder.getContext().setAuthentication(authentication);
    Thanks!

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

    Default

    Apparently track the session is 100% clear for you but I still have no clue on what it is you want.

    I also suggest a read of the reference guide especially the @SessionAttributes part. IN short @SessionAttributes can be used to store model attributes in between requests to the SAME controller not OVER controller or to store other session bound information. That is its sole usecase.

    If you need something else use either a session-scoped object or put something in the session yourself.

    That being said I want to repeat that I still have no clue what you want.
    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
  •