add exeption array to middleware Autorization
This commit is contained in:
@@ -3,6 +3,7 @@ package handlers
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"gitea.tecamino.com/paadi/access-handler/models"
|
||||
@@ -116,7 +117,7 @@ func (aH *AccessHandler) AuthMiddleware() gin.HandlerFunc {
|
||||
// Usage:
|
||||
//
|
||||
// router.GET("/secure/:id", aH.AuthorizeRole("/api/v1"))
|
||||
func (aH *AccessHandler) AuthorizeRole(suffix string) gin.HandlerFunc {
|
||||
func (aH *AccessHandler) AuthorizeRole(suffix string, exeptions ...string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
aH.logger.Debug("AuthorizeRole", "permission path of url path")
|
||||
permissionPath := strings.TrimPrefix(c.Request.URL.Path, suffix+"/")
|
||||
@@ -149,6 +150,12 @@ func (aH *AccessHandler) AuthorizeRole(suffix string) gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
// check exeptions
|
||||
if slices.Contains(exeptions, permissionPath) {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
// Check permissions
|
||||
for _, permission := range roles[0].Permissions {
|
||||
if permission.Name == permissionPath {
|
||||
|
||||
Reference in New Issue
Block a user