-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,001 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ name: "CodeQL" | |
|
||
on: | ||
push: | ||
branches: [ "master","dev" ] | ||
branches: [ "master","main" ] | ||
pull_request: | ||
# The branches below must be a subset of the branches above | ||
branches: [ "dev" ] | ||
|
@@ -27,7 +27,25 @@ jobs: | |
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '17' | ||
|
||
- name: Cache local Maven repository | ||
uses: actions/[email protected] | ||
env: | ||
cache-name: cache-mvn | ||
with: | ||
path: ~/.m2/repository | ||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }} | ||
restore-keys: | | ||
${{ runner.os }}-build-${{ env.cache-name }}- | ||
${{ runner.os }}-build- | ||
${{ runner.os }}- | ||
# Initializes the CodeQL tools for scanning. | ||
- name: Initialize CodeQL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,14 @@ | |
import com.power4j.fist.boot.security.context.UserContextHolder; | ||
import com.power4j.fist.boot.security.core.SecurityConstant; | ||
import com.power4j.fist.boot.security.core.UserInfo; | ||
import inet.ipaddr.AddressStringException; | ||
import inet.ipaddr.IPAddress; | ||
import inet.ipaddr.IPAddressString; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import javax.servlet.FilterChain; | ||
|
@@ -34,9 +37,8 @@ | |
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.regex.Pattern; | ||
import java.util.regex.PatternSyntaxException; | ||
|
||
/** | ||
* @author CJ ([email protected]) | ||
|
@@ -54,15 +56,24 @@ public class TrustedUserFilter extends OncePerRequestFilter { | |
@Setter | ||
private boolean strictMode = true; | ||
Check warning on line 57 in fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/inner/TrustedUserFilter.java GitHub Actions / Qodana Community for JVMField can be local
|
||
|
||
@Override | ||
public void afterPropertiesSet() throws ServletException { | ||
postCheck(); | ||
super.afterPropertiesSet(); | ||
} | ||
private final Collection<IPAddress> whitelist = new ArrayList<>(4); | ||
|
||
@Nullable | ||
@Setter | ||
private Collection<String> whitelist; | ||
public void setWhitelist(Collection<String> list) { | ||
whitelist.clear(); | ||
if (ObjectUtils.isNotEmpty(list)) { | ||
for (String p : list) { | ||
try { | ||
IPAddressString ip = new IPAddressString(p); | ||
ip.validate(); | ||
whitelist.add(ip.getAddress()); | ||
} | ||
catch (AddressStringException e) { | ||
String msg = "非法IP地址:" + p; | ||
throw new IllegalArgumentException(msg, e); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | ||
|
@@ -92,32 +103,19 @@ else if (e.getCause() instanceof IOException) { | |
} | ||
} | ||
|
||
void postCheck() { | ||
if (whitelist != null) { | ||
for (String p : whitelist) { | ||
try { | ||
Pattern.compile(p); | ||
} | ||
catch (PatternSyntaxException e) { | ||
log.error("表达式非法:{}", p); | ||
throw e; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private boolean isTrusted(HttpServletRequest request) { | ||
if (strictMode) { | ||
String ip = request.getRemoteAddr(); | ||
if (whitelist != null && whitelist.stream().anyMatch(ip::matches)) { | ||
return true; | ||
if (ObjectUtils.isNotEmpty(whitelist)) { | ||
IPAddress reqAddr = new IPAddressString(ip).getAddress(); | ||
return whitelist.stream().anyMatch(addr -> addr.contains(reqAddr)); | ||
} | ||
else { | ||
InetAddress address = NetKit.parse(ip); | ||
if (address.isLoopbackAddress() || address.isSiteLocalAddress()) { | ||
return true; | ||
} | ||
log.warn("认证信息不可信"); | ||
log.warn("认证信息不可信,来源:{}", ip); | ||
return false; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.