{"id":19968327,"url":"https://github.com/ecostanzi/spring-rate-limiter","last_synced_at":"2026-04-18T07:31:37.505Z","repository":{"id":84470430,"uuid":"47890237","full_name":"ecostanzi/spring-rate-limiter","owner":"ecostanzi","description":"an AOP based spring rate limiter","archived":false,"fork":false,"pushed_at":"2018-01-27T13:07:26.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-13T06:42:59.702Z","etag":null,"topics":["aop","rate-limits","redis","spring"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ecostanzi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-12T18:47:30.000Z","updated_at":"2021-08-15T13:07:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"0d8a827b-2e71-40bf-a794-b44ede033bff","html_url":"https://github.com/ecostanzi/spring-rate-limiter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ecostanzi/spring-rate-limiter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecostanzi%2Fspring-rate-limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecostanzi%2Fspring-rate-limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecostanzi%2Fspring-rate-limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecostanzi%2Fspring-rate-limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ecostanzi","download_url":"https://codeload.github.com/ecostanzi/spring-rate-limiter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecostanzi%2Fspring-rate-limiter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31961094,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aop","rate-limits","redis","spring"],"created_at":"2024-11-13T02:45:26.301Z","updated_at":"2026-04-18T07:31:37.489Z","avatar_url":"https://github.com/ecostanzi.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Spring Rate Limiter\n===\n\n[![Build Status](https://travis-ci.org/encos/spring-rate-limiter.svg?branch=master)](https://travis-ci.org/encos/flydown)\n\n\n**A Spring rate limiter**\n\n### The Goal\nFlydown provides a rate limiter based on the AOP technology. It mainly relies on in-memory data store to efficiently rate all the potential threats for your system. \n\nWith Flydown you'll be able to limit:\n* the principal obtained by the securityContextHolder\n* any parameter contained in the signature of the annotated method\n* any variable you want to insert in the *flydown request context*\n\nLet's say you have to manage the public APIs of a social network. Of course you want to limit any malicious behaviour. \nAdd these few lines to our spring xml configuration file\n```\n\u003cbean id=\"memoryRateCache\" class=\"org.encos.flydown.limiters.cache.impl.InMemoryRateCache\"/\u003e\n\n\u003cbean class=\"org.encos.flydown.Flydown\"\u003e\n    \u003cproperty name=\"rateCache\" ref=\"memoryRateCache\"/\u003e\n\u003c/bean\u003e\n```\n#### Principal Rating\nYou don't want a user to insert more than 5 comments in one minute. If this behaviour is detected the user has to be stopped temporarily from inserting comments in the platform. Let's give him a 5 minutes break. Here's what you can do:\n```\n@RequestRate(value = FlydownIdentifier.PRINCIPAL,\n        max = 5, range = 60000,\n        suspendFor = 36000)\npublic void commentPost(int postId, String comment) {\n  // the principal does something\n}\n```\n\n#### Parameter Rating\nYou don't want a user to receive be sent more than 1 SMS a minute if he/her forgets his credentials. The same number can't receive more than 1 sms a minute. If a second request comes into the system in this range, all the SMS to this number are blocked for 5 minutes.\n```\n@RequestRate(value = FlydownIdentifier.PARAM, paramIndex = 0,\n        max = 1, range = 60000,\n        suspendFor = 36000))\npublic void sendSms(String phoneNumber){\n  //send an sms to the phone number\n}\n```\n\n#### Flydown Context Rating\nLet's say you don't want to learn how to use nginx and you want to set up a (temporary) IP rating limiting the access to one of you APIs.\n```\n@Autowired\nIRateCache rateCache;\n\n@RequestRate(value = FlydownIdentifier.CONTEXT_VAR, contextKey = \"IP\")\npublic void doSomething(HttpRequest request) {\n  String currentIp = MyUtils.getIp(request);\n  rateCache.addToContext(\"IP\", currentIp);\n  //do something\n}\n```\n\n#### Rating Exception\nRequests might not be the only thing you want to limit. A malicious behaviour can be detected and announced also by a java exception. \n\n```\n@ExceptionRate(value = FlydownIdentifier.PRINCIPAL,\n        max = 1, range = 60000,\n        suspendFor = 36000, exception=BadLanguageException.class)\npublic void commentPost(int postId, String comment) {\n  // the principal does something\n}\n```\n\n#### Default values\n\nYou might also want to set default values for most of your Request/Exception Rate, this can be done through the flydown properties:\n\n```\n\u003cbean class=\"org.encos.flydown.Flydown\"\u003e\n    \u003cproperty name=\"rateCache\" ref=\"memoryRateCache\"/\u003e\n    \u003cproperty name=\"flydownProperties\"\u003e\n        \u003cprops\u003e\n            \u003cprop key=\"flydown.requests.limit\"\u003e10\u003c/prop\u003e\n            \u003cprop key=\"flydown.interval.time\"\u003e10000\u003c/prop\u003e\n            \u003cprop key=\"flydown.suspension.time\"\u003e36000\u003c/prop\u003e\n        \u003c/props\u003e\n    \u003c/property\u003e\n\u003c/bean\u003e\n```\n\nSo that your annotations become more readable:\n\n```\n@RequestRate(value = FlydownIdentifier.PRINCIPAL)\npublic void commentPost(int postId, String comment) {\n  // the principal does something\n}\n    \n    \n```\n\n\n### Available Caches\n* InMemoryRateCache is a dummy implementation of a key/value store \n* RedisRatingCache the cache implementation relying on redis\n\nTo be implemented\n* EhCacheRatingCache the cache implementation relying on ehcache\n\nAny others? There's just an interface to implement :)\n\n### What's missing?\n\nMainly *time*! Any help or suggestions are welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecostanzi%2Fspring-rate-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecostanzi%2Fspring-rate-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecostanzi%2Fspring-rate-limiter/lists"}