{"id":24445334,"url":"https://github.com/nuraj250/custom-auth-interceptor","last_synced_at":"2025-07-17T00:05:52.097Z","repository":{"id":272737387,"uuid":"916674938","full_name":"Nuraj250/custom-auth-interceptor","owner":"Nuraj250","description":"Spring Boot project with a custom annotation for user authentication using JWT and Spring Security.","archived":false,"fork":false,"pushed_at":"2025-01-29T17:15:44.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T04:23:36.085Z","etag":null,"topics":["backend","custom-annotation","java","logging","spring-boot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nuraj250.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-01-14T15:02:03.000Z","updated_at":"2025-01-29T17:44:04.000Z","dependencies_parsed_at":"2025-03-14T07:15:09.363Z","dependency_job_id":null,"html_url":"https://github.com/Nuraj250/custom-auth-interceptor","commit_stats":null,"previous_names":["nuraj250/custom-auth-interceptor"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Nuraj250/custom-auth-interceptor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nuraj250%2Fcustom-auth-interceptor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nuraj250%2Fcustom-auth-interceptor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nuraj250%2Fcustom-auth-interceptor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nuraj250%2Fcustom-auth-interceptor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nuraj250","download_url":"https://codeload.github.com/Nuraj250/custom-auth-interceptor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nuraj250%2Fcustom-auth-interceptor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265553190,"owners_count":23787032,"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":["backend","custom-annotation","java","logging","spring-boot"],"created_at":"2025-01-20T23:19:50.795Z","updated_at":"2025-07-17T00:05:52.050Z","avatar_url":"https://github.com/Nuraj250.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Custom Annotation in Spring Boot with JWT Authentication\n\n## 📌 What is this project?\n\nThis project demonstrates how to create a **custom annotation** in a Spring Boot application while implementing **JWT-based authentication**. The custom annotation `@InjectUserContext` allows automatic injection of user details (like username and roles) into API methods, simplifying authentication and authorization workflows. The project also includes:\n\n- **Spring Security** for authentication and authorization.\n- **JWT (JSON Web Token)** for secure API access.\n- **H2 in-memory database** for easy testing.\n- **Aspect-Oriented Programming (AOP)** to handle the custom annotation.\n- **Global Exception Handling** for better error management.\n\nIt is a complete authentication system that demonstrates best practices for user authentication and role-based access control in Spring Boot.\n\n## 🚀 How to Run Your Spring Boot Project (With Custom Annotation \u0026 JWT Authentication)\n\nNow that your project is set up correctly, follow these **step-by-step instructions** to run and test your application.\n\n---\n\n## 🔹 1️⃣ Ensure Your Environment is Ready\n\nBefore running the project, make sure you have:\n\n- ✅ **Java 17** (or the version specified in `pom.xml`)\n- ✅ **Maven Installed** (`mvn -v` to check)\n- ✅ **IntelliJ IDEA / VS Code / Eclipse** (Any Java IDE)\n- ✅ **Postman / cURL** (for API testing)\n\n---\n\n## 🔹 2️⃣ Build \u0026 Run the Application\n\n### **Option 1: Using Your IDE (IntelliJ / Eclipse / VS Code)**\n\n1. Open the project in **IntelliJ IDEA** (or your preferred IDE).\n2. Navigate to the `CustomAnnotationApplication.java` class.\n3. Click Run ▶️ OR use the shortcut:\n\nMac: Cmd + Shift + F10\n\nWindows/Linux: Ctrl + Shift + F10\n\n\n\n### **Option 2: Using Maven (Terminal)**\n\nRun the following commands in the project root directory:\n\n```sh\n# 1️⃣ Clean previous builds (optional)\nmvn clean\n\n# 2️⃣ Build the project\nmvn install\n\n# 3️⃣ Run the application\nmvn spring-boot:run\n```\n\nYour **Spring Boot application** should now start on **`http://localhost:8080`**.\n\n---\n\n## 🔹 3️⃣ Verify the H2 Database (Optional)\n\nSince we are using **H2 in-memory database**, you can check the database via **H2 Console**:\n\n- **URL**: `http://localhost:8080/h2-console`\n- **JDBC URL**: `jdbc:h2:mem:testdb`\n- **Username**: `sa`\n- **Password**: `password`\n\nClick **Connect** to view the `users` table.\n\n---\n\n## 🔹 4️⃣ Test API Endpoints (Authentication \u0026 Custom Annotation)\n\nNow let's test your APIs using **Postman** or **cURL**.\n\n### **📌 Login API (Get JWT Token)**\n\n#### **POST `http://localhost:8080/api/auth/login`**\n\n##### **Request Body (JSON)**\n\n```json\n{\n  \"username\": \"admin\",\n  \"password\": \"admin123\"\n}\n```\n\n##### **Response (JSON)**\n\n```json\n{\n  \"token\": \"eyJhbGciOiJIUzI1NiIsInR5...\"\n}\n```\n\n✅ **Copy this token** for the next requests.\n\n---\n\n### **📌 Access Secured API (`@InjectUserContext` Custom Annotation)**\n\n#### **GET `http://localhost:8080/api/auth/me`**\n\n##### **Headers**\n\n```text\nAuthorization: Bearer \u003cPASTE_YOUR_JWT_HERE\u003e\n```\n\n##### **Response (JSON)**\n\n```json\n{\n  \"username\": \"admin\",\n  \"roles\": \"ROLE_ADMIN\"\n}\n```\n\nIf you don’t send a token, you should get:\n\n```json\n{\n  \"error\": \"Unauthorized\"\n}\n```\n\n✅ **This confirms that the JWT authentication and custom annotation are working.**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuraj250%2Fcustom-auth-interceptor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuraj250%2Fcustom-auth-interceptor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuraj250%2Fcustom-auth-interceptor/lists"}