fixed multiple roles in 1 policy

This commit is contained in:
2025-12-15 13:24:16 +08:00
parent 5743dbf22d
commit 15deba4584
6 changed files with 79 additions and 84 deletions
+4 -2
View File
@@ -1,12 +1,12 @@
package handlers
import (
"authorization/db"
"authorization/helper"
"authorization/middleware"
"authorization/models"
"authorization/services"
"encoding/json"
"log"
"net/http"
)
@@ -14,7 +14,7 @@ var authService *models.CachedAuthorizationService
// InitAuthService initializes the authorization service with caching
func InitAuthService() {
authService = services.NewCachedAuthorizationService(db.DB)
authService = services.NewCachedAuthorizationService()
}
// AuthorizeHandler godoc
@@ -52,6 +52,8 @@ func AuthorizeHandler(w http.ResponseWriter, r *http.Request) {
return
}
log.Print("Authorization request for user=", ctx.UserID, ", resource=", ctx.Resource, ", action=", ctx.Action)
log.Print("JWT claims user=", claims.UserID, ", username=", claims.Username, ", role=", claims.Role)
// Verify JWT user matches request user (security check)
if ctx.UserID != claims.UserID {
helper.RespondWithError(w, http.StatusForbidden, "User ID mismatch")