Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Base for Spring Boot projects with MongoDB and JWT authentication

License

Notifications You must be signed in to change notification settings

vlsidlyarevich/spring-boot-mongodb-jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring-Boot-MongoDB-JWT

Build Status

Spring Boot base for projects with MongoDB and JWT based security.


This is a quick-start base for java projects with Spring Boot, MongoDB and configured JWT security.

Running

  • Download this base
  • Start the MongoDB service/daemon in your system
  • Run project by Application.class or by mvn clean install, java -jar target/*.jar, or by mvn spring-boot:run

JWT security

Page http://localhost:8080/api/hello is secured. To access this page, you need to do the following:

  • POST request to http://localhost:8080/api/signup with body
  username: "user",
  password: "12345"
  • POST request to http://localhost:8080/api/auth, then take token from responce and use it in header to access secured page
  • GET request to http://localhost:8080/api/hello with header:
  x-auth-token: <your token here>

Security is based on AuthenticationTokenFilter:

@Override 
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) 
             throws IOException, ServletException { 
  HttpServletRequest httpRequest = (HttpServletRequest) request; 
  Authentication authentication = authenticationService.authenticate(httpRequest); 
  SecurityContextHolder.getContext().setAuthentication(authentication); 
  filterChain.doFilter(request, response); 
  SecurityContextHolder.getContext().setAuthentication(null); 
} 

And some services for Token creation and Token verification.

About

Base for Spring Boot projects with MongoDB and JWT authentication

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages