Example #1
0
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()
		}
	}
}
Example #2
0
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()
		}
	}
}