123456789101112131415161718192021222324 |
- package api
- import (
- "net/http"
- "github.com/go-chi/render"
- "wkla.no-ip.biz/gogs/Willie/MsgService/MessageService/dao"
- )
- //RoleCheck implements a simple middleware handler for adding a role check to a route.
- func RoleCheck(allowedRoles []string) func(next http.Handler) http.Handler {
- return func(next http.Handler) http.Handler {
- return http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
- user, _, _ := request.BasicAuth()
- idm := dao.GetIDM()
- ok := idm.UserInRoles(user, allowedRoles)
- if !ok {
- render.Render(response, request, ErrForbidden)
- return
- }
- next.ServeHTTP(response, request)
- })
- }
- }
|