middleware.go 578 B

1234567891011121314151617181920212223242526272829303132333435
  1. package sec
  2. import (
  3. "git.clearsky.net.au/cody/gex.git/srv"
  4. )
  5. func Middleware(req *srv.Req, res srv.Res) bool {
  6. //Session
  7. var sess Sess
  8. sess.Construct(req, res)
  9. sess.Save()
  10. req.Ctx["Sess"] = sess
  11. pattern := req.Pattern
  12. // Route Access Check
  13. // Cancel the security check as there are no permissions for this route
  14. if len(permissions[pattern]) == 0 {
  15. return true
  16. }
  17. handlerRoles := permissions[pattern]
  18. sess = req.Ctx["Sess"].(Sess)
  19. for _, role := range handlerRoles {
  20. if sess.HasRole(role) {
  21. return true
  22. }
  23. }
  24. res.Send("No Access")
  25. return false
  26. }