{"id":20807788,"url":"https://github.com/devrezaur/spring-security-jwt-module","last_synced_at":"2025-05-07T05:48:11.523Z","repository":{"id":182459656,"uuid":"307719276","full_name":"DevRezaur/spring-security-JWT-module","owner":"DevRezaur","description":"Ready to use JWT implementation with Spring Security","archived":false,"fork":false,"pushed_at":"2023-11-13T13:19:27.000Z","size":325,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T07:01:32.975Z","etag":null,"topics":["jwt-auth","spring-boot","spring-security"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DevRezaur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-27T14:03:56.000Z","updated_at":"2025-01-03T15:42:55.000Z","dependencies_parsed_at":"2024-11-17T19:52:51.378Z","dependency_job_id":null,"html_url":"https://github.com/DevRezaur/spring-security-JWT-module","commit_stats":null,"previous_names":["devrezaur/spring-security-jwt-module"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRezaur%2Fspring-security-JWT-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRezaur%2Fspring-security-JWT-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRezaur%2Fspring-security-JWT-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRezaur%2Fspring-security-JWT-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevRezaur","download_url":"https://codeload.github.com/DevRezaur/spring-security-JWT-module/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252823687,"owners_count":21809708,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jwt-auth","spring-boot","spring-security"],"created_at":"2024-11-17T19:42:38.611Z","updated_at":"2025-05-07T05:48:11.502Z","avatar_url":"https://github.com/DevRezaur.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JWT Auth with Spring Boot\n\nThis is a ready to use template code for implementing `JWT based authentication and authorization` using Spring Boot.\n\n\u003cbr /\u003e\n\n## Documentation and Usage\n\n### Authentication API\n\n`POST` URI: `localhost:8080/auth/authenticate`\n\n\u003cbr /\u003e\n\n![authenticate-api](https://github.com/DevRezaur/spring-security-JWT-module/blob/main/Screenshots/authenticate-api.PNG)\n\n### Access User Controller\n\n`GET` URI: `localhost:8080/user/`\n\n\u003cbr /\u003e\n\n![user-controller](https://github.com/DevRezaur/spring-security-JWT-module/blob/main/Screenshots/user-controller.PNG)\n\n### Access Admin Controller\n\n`GET` URI: `localhost:8080/admin/`\n\n\u003cbr /\u003e\n\n![admin-controller](https://github.com/DevRezaur/spring-security-JWT-module/blob/main/Screenshots/admin-controller.PNG)\n\n### Token Expired / Access Denied Example\n\n`GET` URI: `localhost:8080/admin/`\n\n\u003cbr /\u003e\n\n![access-denied](https://github.com/DevRezaur/spring-security-JWT-module/blob/main/Screenshots/access-denied.PNG)\n\n### User Registration API\n\n`POST` URI: `localhost:8080/auth/registerUser`\n\n\u003cbr /\u003e\n\n![user-registration](https://github.com/DevRezaur/spring-security-JWT-module/blob/main/Screenshots/user-registration.PNG)\n\n### Admin Registration API\n\nSince admin registration is a `admin privileged` feature, we protected it via `/admin/` mapping. So sending authentication header is required with this request. \n\n`POST` URI: `localhost:8080/admin/registerAdmin`\n\n\u003cbr /\u003e\n\n![admin-registration](https://github.com/DevRezaur/spring-security-JWT-module/blob/main/Screenshots/admin-registration.PNG)\n\n\u003cbr /\u003e\n\n## Migrate to MySQL\n\nBy default this module uses H2 database. To use MySQL edit the following configuration.\n\n\u003cbr /\u003e\n\nOpen `pom.xml` and configure it as below:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cproject xmlns=\"http://maven.apache.org/POM/4.0.0\"\n\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n\txsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd\"\u003e\n\t\u003cmodelVersion\u003e4.0.0\u003c/modelVersion\u003e\n\t\u003cparent\u003e\n\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\u003cartifactId\u003espring-boot-starter-parent\u003c/artifactId\u003e\n\t\t\u003cversion\u003e2.5.0\u003c/version\u003e\n\t\t\u003crelativePath /\u003e\n\t\u003c/parent\u003e\n\t\u003cgroupId\u003edev.rezaur\u003c/groupId\u003e\n\t\u003cartifactId\u003eSpring-Security-JWT\u003c/artifactId\u003e\n\t\u003cversion\u003e0.0.1-SNAPSHOT\u003c/version\u003e\n\t\u003cname\u003eSpring-Security-JWT\u003c/name\u003e\n\t\u003cdescription\u003eSpring security with JWT\u003c/description\u003e\n\n\t\u003cproperties\u003e\n\t\t\u003cjava.version\u003e15\u003c/java.version\u003e\n\t\u003c/properties\u003e\n\n\t\u003cdependencies\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003espring-boot-starter-data-jpa\u003c/artifactId\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003espring-boot-starter-security\u003c/artifactId\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003espring-boot-starter-web\u003c/artifactId\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eio.jsonwebtoken\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003ejjwt\u003c/artifactId\u003e\n\t\t\t\u003cversion\u003e0.9.1\u003c/version\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003espring-boot-devtools\u003c/artifactId\u003e\n\t\t\t\u003cscope\u003eruntime\u003c/scope\u003e\n\t\t\t\u003coptional\u003etrue\u003c/optional\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003emysql\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003emysql-connector-java\u003c/artifactId\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003ecom.fasterxml.jackson.module\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003ejackson-module-kotlin\u003c/artifactId\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003espring-boot-starter-test\u003c/artifactId\u003e\n\t\t\t\u003cscope\u003etest\u003c/scope\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eorg.springframework.security\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003espring-security-test\u003c/artifactId\u003e\n\t\t\t\u003cscope\u003etest\u003c/scope\u003e\n\t\t\u003c/dependency\u003e\n\t\u003c/dependencies\u003e\n\n\t\u003cbuild\u003e\n\t\t\u003cplugins\u003e\n\t\t\t\u003cplugin\u003e\n\t\t\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\t\t\u003cartifactId\u003espring-boot-maven-plugin\u003c/artifactId\u003e\n\t\t\t\u003c/plugin\u003e\n\t\t\u003c/plugins\u003e\n\t\u003c/build\u003e\n\n\u003c/project\u003e\n```\n\n\u003cbr /\u003e\n\nAfter that open `src/main/resources/application.properties` and configure like below:\n\n```properties\nserver.port=8080\nspring.jpa.open-in-view=false\nspring.h2.console.enabled=true\nspring.datasource.url=jdbc:mysql://localhost:3306/database_name\nspring.datasource.username=username\nspring.datasource.password=password\nspring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect\nspring.jpa.show-sql=true\nspring.jpa.defer-datasource-initialization=true\n\n# JWT secret\njwt.secret=secret\n# JWT token lifespan (5 mins)\njwt.jwtExp=300000\n```\n\n\u003cbr /\u003e\n\n## Additional Configuration\n\n`src/main/resources/data.sql` file is used to insert initial data to the database. This file is not mandatory. Feel free to `modify/delete` this `data.sql` file.\n\n```sql\nINSERT INTO roles\nVALUES(1, 'ROLE_ADMIN');\n\nINSERT INTO roles\nVALUES(2, 'ROLE_USER');\n\nINSERT INTO users (user_id, fullname, username, password)\nVALUES('101', 'Rezaur Rahman', 'DevRezaur', 'iamadmin');\n\nINSERT INTO users (user_id, fullname, username, password)\nVALUES('102', 'Sanzida Sultana', 'SanzidaSultana', 'iamuser');\n\nINSERT INTO user_role\nVALUES('101', 1);\n\nINSERT INTO user_role\nVALUES('101', 2);\n\nINSERT INTO user_role\nVALUES('102', 2);\n```\n\n\u003cbr /\u003e\n\n## Run the Project\n\n* `Clone the repository`\n* `Update maven build (Project \u003e Maven \u003e Update Project)`\n* `Run (Project \u003e Run As \u003e Spring Boot App)`\n\n\u003cbr /\u003e\n\n## Relevant Projects\n\n\u003e [JWT Auth with Refresh Token using Spring Boot](https://github.com/DevRezaur/JWT-refresh-token-spring-boot)\n\n\u003cbr /\u003e\n\nFeel free to leave a star if you find this helpful :smile:\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevrezaur%2Fspring-security-jwt-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevrezaur%2Fspring-security-jwt-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevrezaur%2Fspring-security-jwt-module/lists"}