title: How to implement user login sessions using springboot http session and angular
body: <p>this is my sprinboot backend code where i am trying to implement sessions for login and logout and i am facing difficulties in implementing persistence http sessions using http servlet request in a proper with angular as my frontend framework.
  Integration of sessions in my project is where i am facing difficulties the most.
  <code>it would be helpful if i get any help on how to implement sessions</code>.</p>
  <pre><code>    package com.app.controller;
      
      
      import java.util.HashMap;
      import java.util.List;
      import java.util.Map;
      
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.http.ResponseEntity;
      import org.springframework.web.bind.annotation.CrossOrigin;
      import org.springframework.web.bind.annotation.DeleteMapping;
      import org.springframework.web.bind.annotation.GetMapping;
      import org.springframework.web.bind.annotation.PathVariable;
      import org.springframework.web.bind.annotation.PostMapping;
      import org.springframework.web.bind.annotation.RequestBody;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RequestParam;
      import org.springframework.web.bind.annotation.RestController;
      
      import com.app.exception.ResourceNotFoundException;
      import com.app.model.CreateEmployee;
      import com.app.model.User;
      import com.app.model.UserLogin;
      import com.app.repo.Crepo;
      import com.app.repo.Lrepo;
      import com.app.repo.UserRepo;
      
      @RestController
      @CrossOrigin(origins = &quot;http://localhost:4200&quot;)
      
      @RequestMapping(&quot;/user&quot;)
      public class UserController {
          
          @Autowired
          private UserRepo repo;
          @Autowired
          private Lrepo repo1;
          @Autowired
          private Crepo repo2;
          
          @PostMapping(&quot;/signup&quot;)
          public ResponseEntity&lt;User&gt; registerUser(@RequestBody User user) {
              
              UserLogin login1 = new UserLogin();
              login1.setPassword(user.getPassword());
              login1.setEmail(user.getEmail());
      
              repo1.save(login1);
           System.out.println(&quot;Controller called&quot;);
           return ResponseEntity.ok(repo.save(user));
          }
          
          
          @PostMapping (&quot;/login&quot;)
          
          public ResponseEntity&lt;?&gt; loginUser(@RequestBody UserLogin userdata)
          {
              User user=repo.findByEmail(userdata.getEmail());
              if(user.getPassword().equals(userdata.getPassword()))
              {
              return ResponseEntity.ok(user);
              }
              return (ResponseEntity&lt;?&gt;) ResponseEntity.internalServerError();
      
              }
          
      
          @PostMapping(&quot;/createemployee&quot;)
          public CreateEmployee  createEmp(@RequestBody CreateEmployee createemployee) {
      
          return repo2.save(createemployee);
      
           }
          
          @GetMapping(&quot;/createemployee&quot;)
          public List&lt;CreateEmployee&gt; getAllEmployee(){
          return (List&lt;CreateEmployee&gt;) repo2.findAll();
          
          }
          
          @GetMapping(&quot;/createemployee/{empId}&quot;)
          public CreateEmployee getEmployeeById(@PathVariable(&quot;empId&quot;)Long empId) {
          return repo2.findById(empId).get();
          }
          
      
          @DeleteMapping(&quot;/createemployee/{empId}&quot;)
          public ResponseEntity&lt;Map&lt;String, Boolean&gt;&gt; deleteEmployee(@PathVariable Long empId){
              CreateEmployee createemployee = repo2.findById(empId)
                      .orElseThrow(() -&gt; new ResourceNotFoundException(&quot;employee not exist with id&quot;+ empId)); 
              repo2.delete(createemployee);
              Map&lt;String, Boolean&gt; response=new HashMap();
                    response.put(&quot;deleted&quot;,Boolean.TRUE);
                    return ResponseEntity.ok(response);
      
          }
          
          
             
      }
  
  
  </code></pre>