Coder Social home page Coder Social logo

spring-security-jwt's Introduction

Spring Security JWT

Spring Boot Spring Security JWT License: GPL-3.0

This repository contains an example of authentication and access control using Spring Security and JWT (JSON Web Token). It provides customized authentication using a MySQL database instead of Spring Security's default user management.

Features

  • Secure API access using Spring Security
  • Authentication and access control with JWT
  • User management using MySQL database
  • Example of user login and token-based authorization

How To Run

  1. Clone this repository:
git clone [email protected]:emrtnm/spring-security-jwt.git
  1. Open project settings and select BellSoft Liberica 17 SDK (Recommended).

  2. Make your MySQL database connection settings by opening the application.properties file:

spring.datasource.url=jdbc:mysql://localhost:3306/your_database
spring.datasource.username=your_username
spring.datasource.password=your_password
  1. Change your secret key in application.properties file (Optional):
security.jwt.token.secret-key=d32d53896a4e21855aeb0efaa23c4b5ab0721a6e23702d5eb549332d9e913d14
  1. Open terminal in your project folder

  2. Run this command

mvn spring-boot:run
  1. Go to http://localhost:8080 from your browser.

  2. You should see this message:

{
  "message": "Unauthorized path"
}

How To Test

  1. Open Postman: Open the Postman application.
  2. Import File: Click on the "File" tab in the top menu.
  3. Click on Import: Select the "Import" option.
  4. Choose File to Import: Click on "Upload Files" and select the collection.json file located in the main directory. Then click "Open" or "Choose" to import the file.
  5. Collection Created: After importing the file, a collection named "Spring Security JWT API" will be created.
  6. Enjoy: You can now use the newly created collection in Postman to manage your requests and test your API.

File Structure

├── README.md
├── collection.json
├── pom.xml
── src
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └── emrtnm
    │   │           └── jwt
    │   │               ├── Application.java
    │   │               ├── config
    │   │               │   ├── JwtAuthFilter.java
    │   │               │   ├── PasswordConfig.java
    │   │               │   ├── RestExceptionHandler.java
    │   │               │   ├── SecurityConfig.java
    │   │               │   └── UserAuthenticationEntryPoint.java
    │   │               ├── controller
    │   │               │   ├── AuthController.java
    │   │               │   └── HomeController.java
    │   │               ├── dto
    │   │               │   ├── CredentialsDto.java
    │   │               │   ├── ErrorDto.java
    │   │               │   ├── SignUpDto.java
    │   │               │   ├── UserDto.java
    │   │               │   └── UserResponse.java
    │   │               ├── entity
    │   │               │   └── User.java
    │   │               ├── enums
    │   │               │   └── Role.java
    │   │               ├── exception
    │   │               │   └── AppException.java
    │   │               ├── mapper
    │   │               │   └── UserMapper.java
    │   │               ├── repository
    │   │               │   └── UserRepository.java
    │   │               └── service
    │   │                   └── UserService.java
    │   └── resources
    │       └── application.properties
    └── test
        └── java
            └── com
                └── emrtnm
                    └── jwt
                        └── ApplicationTests.java

License

This project is open-sourced software licensed under the GPL-3.0 license.

Make A Contribution!

If you think that anything here could be improved, please don't hesitate to contribute. Anyone who wants to, regardless of their ability, skill, or background, can contribute to this project. All contributions are made for the benefit of the community. Thanks very much for helping this repository become much more suitable for its purpose and more useful to a larger number of people.

#java #spring #jwt #security #springsecurity #springboot #springframework #auth #jsonwebtoken #springsecurityjwt

spring-security-jwt's People

Contributors

emrtnm avatar

Stargazers

Umit Boyraz avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.