Skip to content

Commit

Permalink
Merge branch 'v2022.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Chan committed Aug 5, 2024
2 parents b1d74f9 + f2a57c6 commit f067612
Show file tree
Hide file tree
Showing 32 changed files with 1,001 additions and 138 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@ name: Java CI with Maven
on:
push:
branches:
- main
- master
- dev
- develop
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'adopt'
distribution: 'temurin'
java-version: '17'

- name: Cache local Maven repository
Expand All @@ -43,11 +45,8 @@ jobs:
- name: Test with Maven
run: mvn -B test -DskipTests=false
- name: Upload to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
# token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
# files: ./coverage1.xml,./coverage2.xml # optional
flags: unittests # optional
name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
# possibly other stuff
token: ${{ secrets.CODECOV_ORG_TOKEN }}
fail_ci_if_error: false # or true if you want CI to fail when Codecov fails
2 changes: 1 addition & 1 deletion .github/workflows/codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
- name: Run Codacy Analysis CLI
Expand Down
22 changes: 20 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/oss-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'adopt'
distribution: 'temurin'
java-version: '17'

- name: Cache local Maven repository
Expand All @@ -39,8 +39,9 @@ jobs:
# run: mvn deploy
# env:
# GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password

- name: Import GPG
uses: crazy-max/ghaction-import-gpg@v5.3.0
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.MAVEN_GPG_KEY }}
passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
Expand All @@ -49,5 +50,5 @@ jobs:
run: ./mvnw --settings ./ossrh-settings.xml clean deploy -Dgpg.passphrase=${MAVEN_GPG_PASSPHRASE} -DskipTests=true -P 'oss-release'
env:
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
OSSRH_USERNAME: ${{ secrets.OSSRH_TOKEN_USER }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN_PWD }}
9 changes: 5 additions & 4 deletions .github/workflows/qodana-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ on:
- main
- master
- dev
- 'releases/*'
- develop
#- 'releases/*'

jobs:
qodana:
Expand All @@ -17,15 +18,15 @@ jobs:
pull-requests: write
checks: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit
fetch-depth: 0 # a full history is required for pull request analysis

- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'adopt'
distribution: 'temurin'
java-version: '17'

- name: Cache local Maven repository
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.power4j.fist/fist-kit-dependencies/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.power4j.fist/fist-kit-dependencies)
[![Maven Central Version](https://img.shields.io/maven-central/v/com.power4j.fist/fist-kit-dependencies)](https://central.sonatype.com/artifact/com.power4j.fist/fist-kit-dependencies)
## 技术栈

- JDK: `11`
Expand Down
6 changes: 5 additions & 1 deletion fist-kit-app/fist-security/fist-support-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>com.github.seancfoley</groupId>
<artifactId>ipaddress</artifactId>
</dependency>
<!-- optional -->
<dependency>
<groupId>io.projectreactor</groupId>
Expand Down Expand Up @@ -92,7 +96,7 @@
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15to18</artifactId>
<version>1.77</version>
<version>1.78.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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])
Expand All @@ -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

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field can be local

Field can be converted to a local variable

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

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `strictMode` may be 'final'

@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)
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
Expand Down Expand Up @@ -55,6 +56,8 @@ public class GlobalAuthorizationProperties {

private Auth auth = new Auth();

Check warning on line 57 in fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/security/core/authorization/config/GlobalAuthorizationProperties.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `auth` may be 'final'

private AccessIpConfig accessIp = new AccessIpConfig();

Check warning on line 59 in fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/security/core/authorization/config/GlobalAuthorizationProperties.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `accessIp` may be 'final'

@Data
public static class Auth {

Expand All @@ -81,4 +84,20 @@ public static class SafeModeConfig {

}

@Data
public static class AccessIpConfig {

/** 用户访问IP的最大解析索引,用于防止IP欺骗 */
private int maxTrustResolves = 64;

Check warning on line 91 in fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/security/core/authorization/config/GlobalAuthorizationProperties.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `maxTrustResolves` may be 'final'

/** 所有用户的IP白名单(CIDR) */
private List<String> global = Collections.singletonList("0.0.0.0/0");

Check warning on line 94 in fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/security/core/authorization/config/GlobalAuthorizationProperties.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `global` may be 'final'

/**
* 针对特定用户的IP白名单(CIDR)
*/
private Map<String, List<String>> rules = Collections.emptyMap();

Check warning on line 99 in fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/security/core/authorization/config/GlobalAuthorizationProperties.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field may be 'final'

Field `rules` may be 'final'

}

}
2 changes: 1 addition & 1 deletion fist-kit-app/fist-web/fist-boot-web-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15to18</artifactId>
<version>1.77</version>
<version>1.78.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

package com.power4j.fist.boot.common.jackson;

import com.fasterxml.jackson.databind.AnnotationIntrospector;

Check warning on line 19 in fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/common/jackson/JacksonConfig.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.fasterxml.jackson.databind.AnnotationIntrospector;`
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
import com.power4j.fist.boot.common.jackson.module.DateTimeModule;
import com.power4j.fist.boot.common.jackson.module.NumberStrModule;
import com.power4j.fist.jackson.support.obfuscation.ObfuscatedAnnotationIntrospector;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
Expand Down Expand Up @@ -72,6 +75,7 @@ public Jackson2ObjectMapperBuilderCustomizer customizer() {
applyTimeZone(builder);
applySimpleDateFormat(builder);
applyModules(builder);
applyExtra(builder);
};
}

Expand Down Expand Up @@ -111,4 +115,10 @@ private void applyModules(Jackson2ObjectMapperBuilder builder) {
}
}

private void applyExtra(Jackson2ObjectMapperBuilder builder) {
log.info("Install extra Serializer/Deserializer");
builder.annotationIntrospector(
introspector -> AnnotationIntrospectorPair.pair(introspector, new ObfuscatedAnnotationIntrospector()));
}

}
4 changes: 4 additions & 0 deletions fist-kit-app/fist-web/fist-support-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<groupId>com.power4j.fist</groupId>
<artifactId>fist-support-spring</artifactId>
</dependency>
<dependency>
<groupId>com.power4j.fist</groupId>
<artifactId>fist-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Loading

0 comments on commit f067612

Please sign in to comment.