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