GAAS 广汽安道拓GFrame金属件MOM项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.2 KiB

  1. package middleware
  2. import (
  3. "github.com/kataras/iris/v12"
  4. "leit.com/LAPP_GAAS_GFrame/conf"
  5. "leit.com/LAPP_GAAS_GFrame/utils"
  6. "leit.com/LAPP_GAAS_GFrame/web/middleware/casbins"
  7. "leit.com/LAPP_GAAS_GFrame/web/middleware/jwts"
  8. "strings"
  9. )
  10. type Middleware struct {
  11. }
  12. func ServeHTTP(ctx iris.Context) {
  13. path := ctx.Path()
  14. // 过滤静态资源、login接口、首页等...不需要验证
  15. if checkURL(path) || strings.Contains(path, "/public") {
  16. ctx.Next()
  17. return
  18. }
  19. // jwt token拦截
  20. if !jwts.Serve(ctx) {
  21. return
  22. }
  23. // 系统菜单不进行权限拦截
  24. publicRutes := conf.AppConfig.PublicRute
  25. res := utils.IsContain(publicRutes,path)
  26. if !res {
  27. // casbin权限拦截
  28. ok := casbins.CheckPermissions(ctx)
  29. if !ok {
  30. return
  31. }
  32. }
  33. //if !strings.Contains(path, "/sysMenu") {
  34. // // casbin权限拦截
  35. // ok := casbins.CheckPermissions(ctx)
  36. // if !ok {
  37. // return
  38. // }
  39. //}
  40. // Pass to real API
  41. ctx.Next()
  42. }
  43. /**
  44. return
  45. true:则跳过不需验证如登录接口等...
  46. false:需要进一步验证
  47. */
  48. func checkURL(reqPath string) bool {
  49. //过滤
  50. for _, v := range conf.AppConfig.Other.IgnoreURLs {
  51. if reqPath == v {
  52. return true
  53. }
  54. }
  55. return false
  56. }