func IpRestrictionFilter(configFile string) gin.HandlerFunc { config := config.SimpleYAMLoad(configFile) ranges := resolveCIDRs(config["ip_restriction"].([]interface{})) return func(context *gin.Context) { if isInvalidIp(ranges, resolveClientIP(context)) { context.String(403, "unathorized") context.Abort() } } }
func CasFilter(configFile string) gin.HandlerFunc { config := config.SimpleYAMLoad(configFile) service := cas.NewService(config["server"].(string), config["service"].(string)) return func(context *gin.Context) { request := context.Request request.ParseForm() response, err := service.ValidateServiceTicket(request.Form.Get("ticket")) if err != nil || !response.Status { context.String(401, "unauthorized") context.Abort() } } }