https://github.com/babyblue94520/firewall
https://github.com/babyblue94520/firewall
firewall java security spring-boot
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/babyblue94520/firewall
- Owner: babyblue94520
- Created: 2018-11-03T01:28:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-01-05T07:26:03.000Z (over 2 years ago)
- Last Synced: 2025-11-13T18:02:59.537Z (8 months ago)
- Topics: firewall, java, security, spring-boot
- Language: Java
- Homepage:
- Size: 83 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Firewall
## Overview
## Requirement
* Spring Boot 2.3+
* Java 8+
## QuickStart
1. Write rule in yml
```yaml
firewall:
rule:
additional-rule:
```
2. Enable
```java
import com.primestar.firewall.EnableFirewall;
@EnableFirewall
public class Application {
}
```
3. Implement Filter
```java
import com.primestar.firewall.FirewallService;
import com.primestar.firewall.FirewallType;
public class DemoFilter implements Filter {
@Autowired
private FirewallService firewallService;
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
String path = request.getRequestURI();
String url = request.getRequestURL().toString();
String origin = request.getHeader(HttpHeaders.ORIGIN);
String clientIp = WebUtil.getClientIp(request);
String remoteIp = request.getRemoteAddr();
int type = firewallService.parse(path, url, origin, clientIp, remoteIp);
}
}
```
## Advanced
1. Add rule at runtime
```java
import com.primestar.firewall.EnableFirewall;
import com.primestar.firewall.FirewallService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
@EnableFirewall
@Configuration
public class CustomConfig implements InitializingBean {
@Autowired
private FirewallService firewallService;
@Override
public void afterPropertiesSet() throws Exception {
// add other rule
firewallService.getIgnorePath().add("");
}
}
```