title: Spring Security with Rest API with React
body: <p>I am trying to implement Spring Security with Rest API and React as Front end, as this is my first Full Stack Development Project, I am clueless on how to achieve proper authentication mechanism.</p>
  
  <p>I have searched a lot and found article on Spring Security with Basic Auth but I am not able to figure out how to convert that authentication to rest api and then same managed through session/cookies. Even whatever github references that I have got are very old or they have not completely migrated to spring security 5.</p>
  
  <p>So not able to figure out the correct approach on securing a rest api. (Would it be just spring security, spring security + jwt, spring security + jwt + spring session + cookie) </p>
  
  <p><strong>Edit</strong></p>
  
  <p>User Name Validation from DB </p>
  
  <pre><code>@Component
  CustomUserDetailsService -&gt; loadUserByUsername -&gt; Mongo Db 
  </code></pre>
  
  <p>Pass Encryption </p>
  
  <pre><code>@Bean
  public PasswordEncoder passwordEncoder() { ... }
  </code></pre>
  
  <p>Cross Origin</p>
  
  <pre><code>@Bean
  public WebMvcConfigurer corsConfigurer() { ... }
  </code></pre>
  
  <p>Registration Controller</p>
  
  <pre><code>@RestController
  public class RegistrationController {
  @PostMapping("/registration")
  @ResponseStatus(HttpStatus.CREATED)
  @ResponseBody
  public ResponseEntity registerUserAccount(... ) { ... }
  ]
  </code></pre>
  
  <p>Mongo Session</p>
  
  <pre><code>build.gradle
  implementation 'org.springframework.session:spring-session-data-mongodb'
  implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
  
  @Configuration
  @EnableMongoHttpSession
  </code></pre>
  
  <p>So above is what I have already implemented. After that I am stuck on how to keep the user in session and keep verifying the user from that. </p>