Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC 3 session Tracking Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Depends on what you want and what your usecase is.

    Comment


    • #3
      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!

      Comment


      • #4
        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.

        Comment

        Working...
        X