diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b39b0f1..65126de 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -2,9 +2,9 @@ name: CI
on:
push:
- branches: [2.3.x, 2.7.x, 3.0.x, 3.1.x, 3.2.x, 3.3.x, 3.4.x, 3.5.x, 4.0.x, 4.1.x]
+ branches: [main, test/20261119, 2.3.x, 2.7.x, 3.0.x, 3.1.x, 3.2.x, 3.3.x, 3.4.x, 3.5.x, 4.0.x, 4.1.x]
pull_request:
- branches: [2.3.x, 2.7.x, 3.0.x, 3.1.x, 3.2.x, 3.3.x, 3.4.x, 3.5.x, 4.0.x, 4.1.x]
+ branches: [main, 2.3.x, 2.7.x, 3.0.x, 3.1.x, 3.2.x, 3.3.x, 3.4.x, 3.5.x, 4.0.x, 4.1.x]
permissions:
contents: read
@@ -12,4 +12,6 @@ permissions:
jobs:
build:
uses: easy-4-java/.github/.github/workflows/maven-starter-ci.yml@main
+ with:
+ version-line: ${{ ( (github.base_ref || github.ref_name) == 'main' || (github.base_ref || github.ref_name) == 'test/20261119' ) && '2.3.x' || '' }}
secrets: inherit
diff --git a/README.md b/README.md
index 57fb970..16770e4 100644
--- a/README.md
+++ b/README.md
@@ -6,23 +6,22 @@
**Spring Boot Starter for security-yiban**
-[](https://github.com/easy-4-java/security-yiban-spring-boot-starter)
-[](#3-requirements-and-compatibility)
+[](#3-requirements-and-compatibility)
[](https://www.apache.org/licenses/LICENSE-2.0)
[简体中文](./README.zh-CN.md) | [English](./README.md)
[Positioning](#1-positioning) · [Capabilities](#2-core-capabilities) ·
-[Dependency](#5-dependency) · [Quick Start](#6-quick-start) ·
-[Configuration](#7-configuration-reference) · [Versions](#9-version-lines-and-compatibility) ·
-[Build](#10-build-and-test) · [License](#12-license)
+[Dependencies](#5-dependencies) · [Enable](#6-enable-yiban-configuration) ·
+[Configuration](#7-configuration-reference) · [Versions](#8-version-lines-and-compatibility) ·
+[Build](#9-build-and-test) · [License](#12-license)
---
> **Current Version**:`1.0.0-SNAPSHOT`
-> **JDK Baseline**:`17`
+> **JDK Baseline**:`8`
> **Group ID**:`io.github.easy4j`
> **Artifact ID**:`security-yiban-spring-boot-starter`
> **License**:Apache License 2.0
@@ -36,25 +35,35 @@
| Type | Spring Boot Starter |
| Consumers | Spring Boot applications using security-yiban |
| Core Capabilities | auto-configuration, property binding, ready-to-use beans for security-yiban |
-| JDK | `17` |
-| Coordinates | `io.github.easy4j:security-yiban-spring-boot-starter:1.0.0-SNAPSHOT` |
-| Config Prefix | `security.yiban` |
+| JDK | `8` |
+| Source POM coordinates | `io.github.easy4j:security-yiban-spring-boot-starter:1.0.0-SNAPSHOT` |
+| Config Prefix | `spring.security.yiban` |
## 2. Core Capabilities
| Capability | Status | Description |
|---|:---:|---|
-| Auto-configuration | ✅ Stable | Registers security-yiban beans automatically |
-| Property Binding | ✅ Stable | Binds `security.yiban.*` to `SecurityYibanAuthcProperties` |
-| `Authorize` bean | ✅ Stable | Auto-registered via SecurityYibanAutoConfiguration |
+| Auto-configuration | Declared in source | Registers security-yiban beans automatically |
+| Property Binding | Declared in source | Binds `spring.security.yiban.authc.*` to `SecurityYibanAuthcProperties` |
+| `Authorize` bean | Declared in source | Auto-registered via SecurityYibanAutoConfiguration |
## 3. Requirements and Compatibility
| Dependency | Minimum | Evidence |
|---|---:|---|
-| JDK | `17` | `pom.xml` |
-| Spring Boot | `2.3.0.RELEASE` | `pom.xml` parent |
-| Maven | `3.6+` | Maven Enforcer |
+| JDK | `8` | `pom.xml` |
+| Spring Boot | `2.3.12.RELEASE` | `pom.xml` parent |
+| Maven | `3.0` | Maven Enforcer |
+
+For Boot 2.3 applications using the Boot parent, set `spring-framework.version` to `5.3.39` and
+`spring-security.version` to `5.8.14` in the application POM. Security Biz is pinned to the Easy4J
+snapshot build `2.7.x.20260630-20261029.080305-2`, which is verified with Boot 2.3.12 and JDK 8
+in this starter. Use the Easy4J Maven snapshot settings when building or consuming it.
+
+The build checks the SHA-256 of `YBOpenApi.jar` in the repository's `YBApi_sdk_java.zip`
+and includes the SDK classes from the 2015-08-20 archive. It supplies a replacement HTTP transport
+with the JVM's certificate trust and hostname verification, bounded timeouts and no redirects.
+The starter no longer resolves `cn.yiban.open:java-sdk:1.6.0`.
## 4. Auto-configuration
@@ -68,65 +77,46 @@ The starter auto-configures the following beans:
| `YibanMatchedAuthenticationFailureHandler` | classpath + property | not created |
| `YibanAuthenticationProvider` | classpath + property | not created |
-Auto-configuration registration:
+The source declares configuration classes, while the Boot 2.3 discovery file
+`META-INF/spring.factories` is absent. Verify configuration discovery and the
+live Yiban sign-in flow before using this branch.
-- `META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports` (Spring Boot 2.7+ / 3.x / 4.x)
-- `META-INF/spring.factories` (Spring Boot 2.x legacy)
+## 5. Dependencies
-## 5. Dependency
+The build requires two artifacts that are currently unresolved:
-```xml
-
- io.github.easy4j
- security-yiban-spring-boot-starter
- 1.0.0-SNAPSHOT
-
-```
+- `cn.yiban.open:java-sdk:1.6.0` for Yiban authorization and user APIs.
+- `io.github.easy4j:security-biz-spring-boot-starter:1.0.9-SNAPSHOT` for shared Spring Security components.
-No additional easy4j component dependencies.
+The [official Yiban Java download](https://open.yiban.cn/wiki/download/oauth_java.7z)
+contains a Servlet authorization example. The archive does not contain the Maven
+SDK JAR. Resolve both artifacts from a trusted repository and verify the Java 8
+build and Yiban integration before using any release coordinates.
-## 6. Quick Start
+The historical Security Biz `1.0.9` source used earlier organization coordinates. Independent resolution from the configured Aliyun repository found neither `1.0.9-SNAPSHOT` nor the Boot 2.3 maintenance snapshot `2.3.x.20260630-SNAPSHOT` under the Easy4J coordinates. Moving to the maintained line also requires verification of Spring Security and authentication error compatibility.
-### 6.1 Add dependency
+## 6. Enable Yiban configuration
-Add the dependency above to your `pom.xml`.
-
-### 6.2 Configure
+For an application that already loads the Yiban configuration:
```yaml
-security.yiban:
- enabled: true
-```
-
-### 6.3 Use the bean
-
-```java
-@SpringBootApplication
-public class Application {
- public static void main(String[] args) {
- SpringApplication.run(Application.class, args);
- }
-}
-```
-
-Then inject the auto-configured bean in your code:
-
-```java
-@Autowired
-private Authorize yibanAuthorize;
+spring:
+ security:
+ yiban:
+ enabled: true
```
## 7. Configuration Reference
### 7.1 Config Prefix
-`security.yiban`
+`spring.security.yiban`
### 7.2 Configuration Items
| Property | Type | Default | Required | Description | Sensitive |
|---|---|---|:---:|---|:---:|
-| `security.yiban.enabled` | boolean | `true` | No | Enable the starter | No |
+| `spring.security.yiban.enabled` | boolean | `false` | No | Enable the starter | No |
## 8. Version Lines and Compatibility
@@ -135,20 +125,19 @@ private Authorize yibanAuthorize;
|---|---:|---:|---|:---:|
| `2.3.x` / `2.7.x` | `8+` | 2.3.x / 2.7.x | `1.0.x` | Maintenance |
| `3.0.x` ~ `3.5.x` | `17` | 3.x | `2.0.x` | Maintenance |
-| `4.0.x` / `4.1.x` | `17+` | 4.x | `3.0.x` | Active |
+| `4.1.x` (`76dfef6`) | `21` | 4.1.2 | `4.1.x.20260630-SNAPSHOT` | Compilation blocked by missing SDK and authentication classes |
## 9. Build and Test
```bash
-mvn clean verify
-mvn -pl security-yiban-spring-boot-starter -am test
+mvn -U clean verify
```
## 10. Troubleshooting
| Symptom | Diagnosis | Resolution |
|---|---|---|
-| Bean not created | Check auto-configuration report | Verify `security.yiban.enabled=true` and classpath |
+| Bean not created | Check auto-configuration report | Verify `spring.security.yiban.enabled=true` and classpath |
| `ClassNotFoundException` | Missing dependency | Add the required module |
| Version conflict | `mvn dependency:tree` | Use BOM for version alignment |
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 9ea4629..8bb4505 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -6,14 +6,13 @@
**Spring Boot Starter,集成 security-yiban**
-[](https://github.com/easy-4-java/security-yiban-spring-boot-starter)
-[](#3-运行要求与兼容性)
+[](#3-运行要求与兼容性)
[](https://www.apache.org/licenses/LICENSE-2.0)
[English](./README.md) | [简体中文](./README.zh-CN.md)
[项目定位](#1-项目定位) · [核心能力](#2-核心能力) ·
-[引入依赖](#5-引入依赖) · [快速开始](#6-快速开始) ·
+[引入依赖](#5-引入依赖) · [启用配置](#6-启用配置) ·
[配置参考](#7-配置参考) · [版本线](#8-版本线与兼容性) ·
[构建测试](#9-构建与测试) · [许可证](#12-许可证)
@@ -22,7 +21,7 @@
---
> **当前版本**:`1.0.0-SNAPSHOT`
-> **JDK 基线**:`17`
+> **JDK 基线**:`8`
> **Group ID**:`io.github.easy4j`
> **Artifact ID**:`security-yiban-spring-boot-starter`
> **许可证**:Apache License 2.0
@@ -36,25 +35,34 @@
| 类型 | Spring Boot Starter |
| 消费方 | 使用 security-yiban 的 Spring Boot 应用 |
| 核心能力 | 自动装配、属性绑定、开箱即用的 security-yiban Bean |
-| JDK | `17` |
-| 坐标 | `io.github.easy4j:security-yiban-spring-boot-starter:1.0.0-SNAPSHOT` |
-| 配置前缀 | `security.yiban` |
+| JDK | `8` |
+| 当前源码坐标 | `io.github.easy4j:security-yiban-spring-boot-starter:1.0.0-SNAPSHOT` |
+| 配置前缀 | `spring.security.yiban` |
## 2. 核心能力
| 能力 | 状态 | 说明 |
|---|:---:|---|
-| 自动装配 | ✅ 稳定 | 自动注册 security-yiban 相关 Bean |
-| 属性绑定 | ✅ 稳定 | 绑定 `security.yiban.*` 到 `SecurityYibanAuthcProperties` |
-| `Authorize` Bean | ✅ 稳定 | 通过 SecurityYibanAutoConfiguration 自动注册 |
+| 自动装配 | 源码已声明 | 自动注册 security-yiban 相关 Bean |
+| 属性绑定 | 源码已声明 | 绑定 `spring.security.yiban.authc.*` 到 `SecurityYibanAuthcProperties` |
+| `Authorize` Bean | 源码已声明 | 通过 SecurityYibanAutoConfiguration 自动注册 |
## 3. 运行要求与兼容性
| 依赖 | 最低版本 | 证据来源 |
|---|---:|---|
-| JDK | `17` | `pom.xml` |
-| Spring Boot | `2.3.0.RELEASE` | `pom.xml` parent |
-| Maven | `3.6+` | Maven Enforcer |
+| JDK | `8` | `pom.xml` |
+| Spring Boot | `2.3.12.RELEASE` | `pom.xml` parent |
+| Maven | `3.0` | Maven Enforcer |
+
+使用 Boot 父 POM 的 Boot 2.3 应用,请在应用 POM 中将 `spring-framework.version` 设为
+`5.3.39`、`spring-security.version` 设为 `5.8.14`。Security Biz 固定使用 Easy4J 已发布的
+快照构建 `2.7.x.20260630-20261029.080305-2`,本 Starter 在 JDK 8 与 Boot 2.3.12 上验证其运行兼容性。
+构建和消费该构件时需配置 Easy4J Maven 快照仓库。
+
+构建校验仓库内 `YBApi_sdk_java.zip` 中 `YBOpenApi.jar` 的 SHA-256,再打包 2015-08-20
+归档中的 SDK 类。HTTP 传输使用 JVM 证书信任库和主机名校验,设定超时并禁用重定向。
+Starter 不再解析 `cn.yiban.open:java-sdk:1.6.0`。
## 4. 自动装配
@@ -68,65 +76,41 @@ Starter 自动装配以下 Bean:
| `YibanMatchedAuthenticationFailureHandler` | classpath + property | 不创建 |
| `YibanAuthenticationProvider` | classpath + property | 不创建 |
-自动装配注册:
-
-- `META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports`(Spring Boot 2.7+ / 3.x / 4.x)
-- `META-INF/spring.factories`(Spring Boot 2.x 传统方式)
+当前源码包含配置类,但没有 Boot 2.3 自动发现使用的 `META-INF/spring.factories`。自动发现及真实易班登录流程仍待验证。
## 5. 引入依赖
-```xml
-
- io.github.easy4j
- security-yiban-spring-boot-starter
- 1.0.0-SNAPSHOT
-
-```
+本分支构建仍需解析以下依赖:
-无其他 easy4j 组件依赖。
+- `cn.yiban.open:java-sdk:1.6.0`,易班授权及用户接口。
+- `io.github.easy4j:security-biz-spring-boot-starter:1.0.9-SNAPSHOT`,通用 Spring Security 组件。
-## 6. 快速开始
+[易班官方下载的 Java 压缩包](https://open.yiban.cn/wiki/download/oauth_java.7z)包含 Servlet 授权示例,未提供上述 Maven SDK JAR。需先从可信来源解析这两个 Maven 制品,并完成 Java 8 构建和联调,再验证可用的发布坐标。
-### 6.1 引入依赖
+Security Biz 的历史 `1.0.9` 源码使用旧组织坐标。对阿里云私服的独立解析显示,Easy4J 坐标下的 `1.0.9-SNAPSHOT` 和 Boot 2.3 维护版 `2.3.x.20260630-SNAPSHOT` 均未解析到。切换到维护版还需验证 Spring Security 版本及异常响应兼容性。
-在 `pom.xml` 中添加上述依赖。
+## 6. 启用配置
-### 6.2 配置
+在已加载 Yiban 配置的应用中使用以下开关:
```yaml
-security.yiban:
- enabled: true
-```
-
-### 6.3 使用 Bean
-
-```java
-@SpringBootApplication
-public class Application {
- public static void main(String[] args) {
- SpringApplication.run(Application.class, args);
- }
-}
-```
-
-在业务代码中注入自动装配的 Bean:
-
-```java
-@Autowired
-private Authorize yibanAuthorize;
+spring:
+ security:
+ yiban:
+ enabled: true
```
## 7. 配置参考
### 7.1 配置前缀
-`security.yiban`
+`spring.security.yiban`
### 7.2 配置项
| 属性 | 类型 | 默认值 | 必填 | 说明 | 敏感 |
|---|---|---|:---:|---|:---:|
-| `security.yiban.enabled` | boolean | `true` | 否 | 是否启用 Starter | 否 |
+| `spring.security.yiban.enabled` | boolean | `false` | 否 | 是否启用 Starter | 否 |
## 8. 版本线与兼容性
@@ -135,20 +119,19 @@ private Authorize yibanAuthorize;
|---|---:|---:|---|:---:|
| `2.3.x` / `2.7.x` | `8+` | 2.3.x / 2.7.x | `1.0.x` | 维护中 |
| `3.0.x` ~ `3.5.x` | `17` | 3.x | `2.0.x` | 维护中 |
-| `4.0.x` / `4.1.x` | `17+` | 4.x | `3.0.x` | 活跃开发 |
+| `4.1.x`(`76dfef6`) | `21` | 4.1.2 | `4.1.x.20260630-SNAPSHOT` | 缺少 SDK 和认证实现,编译失败 |
## 9. 构建与测试
```bash
-mvn clean verify
-mvn -pl security-yiban-spring-boot-starter -am test
+mvn -U clean verify
```
## 10. 排障
| 症状 | 诊断 | 解决 |
|---|---|---|
-| Bean 未创建 | 查看自动装配报告 | 确认 `security.yiban.enabled=true` 与 classpath |
+| Bean 未创建 | 查看自动装配报告 | 确认 `spring.security.yiban.enabled=true` 与 classpath |
| `ClassNotFoundException` | 缺少依赖 | 引入对应模块 |
| 版本冲突 | `mvn dependency:tree` | 使用 BOM 统一版本 |
diff --git a/pom.xml b/pom.xml
index 194b2c0..f49bd43 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,6 +10,7 @@
+ io.github.easy4j
security-yiban-spring-boot-starter
Spring Boot Starter For Spring Security With yiban SDK
1.0.0-SNAPSHOT
@@ -170,13 +171,13 @@
${maven-surefire-plugin.version}
- true
- true
+ false
+ false
once
- -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m -Dfile.encoding=UTF-8
+ -Xmx1024m -Dfile.encoding=UTF-8
${basedir}/target/test-classes
@@ -246,6 +247,39 @@
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+ 3.1.0
+
+
+ verify-and-unpack-yiban-sdk
+ generate-resources
+ run
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -422,8 +456,9 @@
3.1.0
2.22.1
1.6.8
- 1.6.0
- 1.0.9-SNAPSHOT
+ 2.7.x.20260630-20261029.080305-2
+ 5.8.14
+ 5.3.39
@@ -435,19 +470,13 @@
security-biz-spring-boot-starter
${spring-security-biz.version}
-
-
- cn.yiban.open
- java-sdk
- ${yiban-sdk.version}
-
commons-httpclient
commons-httpclient
${commons-httpclient.version}
-
+
- org.apache.commons
+ ca.juliusdavies
not-yet-commons-ssl
${commons-not-yet-ssl.version}
@@ -552,7 +581,7 @@
- org.apache.commons
+ ca.juliusdavies
not-yet-commons-ssl
@@ -563,17 +592,18 @@
commons-lang3
+
+ org.springframework.boot
+ spring-boot-starter-web
+ test
+
+
io.github.easy4j
security-biz-spring-boot-starter
-
-
- cn.yiban.open
- java-sdk
-
diff --git a/src/main/java/cn/yiban/util/HTTPSimple.java b/src/main/java/cn/yiban/util/HTTPSimple.java
new file mode 100644
index 0000000..0c8a690
--- /dev/null
+++ b/src/main/java/cn/yiban/util/HTTPSimple.java
@@ -0,0 +1,62 @@
+package cn.yiban.util;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Objects;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpEntity;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+/** 保留旧版易班 SDK 的静态传输入口,使用 JVM 默认信任库和主机名验证。 */
+@Slf4j
+public final class HTTPSimple {
+
+ private static final RequestConfig TIMEOUTS = RequestConfig.custom()
+ .setConnectTimeout(5000)
+ .setSocketTimeout(10000)
+ .build();
+
+ private HTTPSimple() {
+ }
+
+ /** 返回易班 GET 响应正文。 */
+ public static String GET(String url) {
+ return execute(new HttpGet(url));
+ }
+
+ /** 以 UTF-8 表单发送易班 POST 请求。 */
+ public static String POST(String url, List parameters) {
+ HttpPost request = new HttpPost(url);
+ request.setEntity(new UrlEncodedFormEntity(parameters, StandardCharsets.UTF_8));
+ return execute(request);
+ }
+
+ private static String execute(HttpUriRequest request) {
+ try (CloseableHttpClient client = HttpClients.custom()
+ .disableRedirectHandling()
+ .setDefaultRequestConfig(TIMEOUTS)
+ .build();
+ CloseableHttpResponse response = client.execute(request)) {
+ int status = response.getStatusLine().getStatusCode();
+ if (status >= 300 && status < 400) {
+ log.warn("Yiban API returned a redirect, status={}", status);
+ return "";
+ }
+ HttpEntity entity = response.getEntity();
+ return Objects.isNull(entity) ? "" : EntityUtils.toString(entity, StandardCharsets.UTF_8);
+ } catch (IOException ex) {
+ log.warn("Yiban API request failed, errorType={}", ex.getClass().getSimpleName());
+ return "";
+ }
+ }
+}
diff --git a/src/main/java/org/springframework/security/boot/SecurityYibanFilterConfiguration.java b/src/main/java/org/springframework/security/boot/SecurityYibanFilterConfiguration.java
index 1f8e71a..b748a88 100644
--- a/src/main/java/org/springframework/security/boot/SecurityYibanFilterConfiguration.java
+++ b/src/main/java/org/springframework/security/boot/SecurityYibanFilterConfiguration.java
@@ -4,7 +4,7 @@
import java.util.stream.Collectors;
import org.springframework.beans.factory.ObjectProvider;
-import org.springframework.biz.web.servlet.i18n.LocaleContextFilter;
+import org.springframework.extension.web.servlet.i18n.LocaleContextFilter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
diff --git a/src/main/java/org/springframework/security/boot/yiban/exception/AuthenticationYibanServerException.java b/src/main/java/org/springframework/security/boot/yiban/exception/AuthenticationYibanServerException.java
index 99df784..35fa345 100644
--- a/src/main/java/org/springframework/security/boot/yiban/exception/AuthenticationYibanServerException.java
+++ b/src/main/java/org/springframework/security/boot/yiban/exception/AuthenticationYibanServerException.java
@@ -17,13 +17,13 @@
import org.springframework.security.boot.biz.exception.AuthResponseCode;
-import org.springframework.security.boot.biz.exception.AuthenticationServiceExceptionAdapter;
+import org.springframework.security.authentication.AuthenticationServiceException;
/**
*
*/
@SuppressWarnings("serial")
-public class AuthenticationYibanServerException extends AuthenticationServiceExceptionAdapter {
+public class AuthenticationYibanServerException extends AuthenticationServiceException {
final String code;
@@ -37,7 +37,7 @@ public class AuthenticationYibanServerException extends AuthenticationServiceExc
* @param msg the detail message
*/
public AuthenticationYibanServerException(String code, String msg) {
- super(AuthResponseCode.SC_AUTHZ_THIRD_PARTY_SERVICE, msg);
+ super(msg);
this.code = code;
}
@@ -49,10 +49,14 @@ public AuthenticationYibanServerException(String code, String msg) {
* @param t root cause
*/
public AuthenticationYibanServerException(String code, String msg, Throwable t) {
- super(AuthResponseCode.SC_AUTHZ_THIRD_PARTY_SERVICE, msg, t);
+ super(msg, t);
this.code = code;
}
+ public AuthResponseCode getAuthCode() {
+ return AuthResponseCode.SC_AUTHZ_THIRD_PARTY_SERVICE;
+ }
+
public String getCode() {
return code;
}
diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..c4995c7
--- /dev/null
+++ b/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,3 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.springframework.security.boot.SecurityYibanAutoConfiguration,\
+org.springframework.security.boot.SecurityYibanFilterConfiguration
diff --git a/src/test/java/org/springframework/security/boot/yiban/YibanBoot23CompatibilityTest.java b/src/test/java/org/springframework/security/boot/yiban/YibanBoot23CompatibilityTest.java
new file mode 100644
index 0000000..f9c80e3
--- /dev/null
+++ b/src/test/java/org/springframework/security/boot/yiban/YibanBoot23CompatibilityTest.java
@@ -0,0 +1,82 @@
+package org.springframework.security.boot.yiban;
+
+import cn.yiban.open.Authorize;
+import cn.yiban.util.HTTPSimple;
+import com.sun.net.httpserver.HttpServer;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.http.message.BasicNameValuePair;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.SpringBootVersion;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.boot.biz.userdetails.UserDetailsServiceAdapter;
+import org.springframework.security.boot.yiban.authentication.YibanAuthenticationProvider;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+class YibanBoot23CompatibilityTest {
+
+ @Test
+ void startsServletSecurityWithThePublishedSecurityBizDependency() {
+ assertThat(SpringBootVersion.getVersion()).isEqualTo("2.3.12.RELEASE");
+ assertThat(System.getProperty("java.specification.version")).isEqualTo("1.8");
+ new WebApplicationContextRunner()
+ .withUserConfiguration(ServletApplication.class)
+ .withBean(UserDetailsServiceAdapter.class, () -> mock(UserDetailsServiceAdapter.class))
+ .withPropertyValues("spring.security.yiban.enabled=true",
+ "spring.security.yiban.authc.app-key=local-fixture",
+ "spring.security.yiban.authc.app-secret=fixture-secret",
+ "spring.security.yiban.authc.callback=https://example.test/callback")
+ .run(context -> {
+ assertThat(context).hasSingleBean(Authorize.class)
+ .hasSingleBean(YibanAuthenticationProvider.class)
+ .hasBean("springSecurityFilterChain");
+ assertThat(context.getBean(Authorize.class)
+ .forwardurl("https://example.test/callback", "fixture-state", Authorize.DISPLAY_TAG_T.WEB))
+ .startsWith("https://openapi.yiban.cn/")
+ .contains("local-fixture", "fixture-state");
+ });
+ }
+
+ @Test
+ void transportAcceptsFormResponsesWithoutFollowingRedirects() throws IOException {
+ HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
+ AtomicInteger redirected = new AtomicInteger();
+ server.createContext("/redirect", exchange -> {
+ exchange.getResponseHeaders().set("Location", "/destination");
+ exchange.sendResponseHeaders(302, -1);
+ exchange.close();
+ });
+ server.createContext("/destination", exchange -> {
+ redirected.incrementAndGet();
+ exchange.sendResponseHeaders(200, -1);
+ exchange.close();
+ });
+ server.createContext("/form", exchange -> {
+ byte[] body = "{\"access_token\":\"fixture\"}".getBytes(StandardCharsets.UTF_8);
+ exchange.sendResponseHeaders(200, body.length);
+ exchange.getResponseBody().write(body);
+ exchange.close();
+ });
+ server.start();
+ try {
+ String endpoint = "http://127.0.0.1:" + server.getAddress().getPort();
+ assertThat(HTTPSimple.POST(endpoint + "/form", Collections.singletonList(
+ new BasicNameValuePair("code", "fixture")))).contains("access_token");
+ assertThat(HTTPSimple.GET(endpoint + "/redirect")).isEmpty();
+ assertThat(redirected.get()).isZero();
+ } finally {
+ server.stop(0);
+ }
+ }
+ @Configuration(proxyBeanMethods = false)
+ @EnableAutoConfiguration
+ static class ServletApplication {
+ }
+}
diff --git a/src/test/java/org/springframework/security/boot/yiban/YibanErrorResponseTest.java b/src/test/java/org/springframework/security/boot/yiban/YibanErrorResponseTest.java
new file mode 100644
index 0000000..2ac171a
--- /dev/null
+++ b/src/test/java/org/springframework/security/boot/yiban/YibanErrorResponseTest.java
@@ -0,0 +1,35 @@
+package org.springframework.security.boot.yiban;
+
+import com.alibaba.fastjson.JSONObject;
+import org.junit.jupiter.api.Test;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.security.boot.biz.exception.AuthResponseCode;
+import org.springframework.security.boot.yiban.authentication.YibanMatchedAuthenticationEntryPoint;
+import org.springframework.security.boot.yiban.authentication.YibanMatchedAuthenticationFailureHandler;
+import org.springframework.security.boot.yiban.exception.AuthenticationYibanServerException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class YibanErrorResponseTest {
+
+ @Test
+ void retainsTheVendorCodeAndTheStartersThirdPartyServiceResponse() throws Exception {
+ IllegalStateException cause = new IllegalStateException("upstream unavailable");
+ AuthenticationYibanServerException failure =
+ new AuthenticationYibanServerException("YIBAN-429", "Please retry", cause);
+ assertThat(failure.getCode()).isEqualTo("YIBAN-429");
+ assertThat(failure.getAuthCode()).isEqualTo(AuthResponseCode.SC_AUTHZ_THIRD_PARTY_SERVICE);
+ assertThat(failure.getCause()).isSameAs(cause);
+
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ MockHttpServletResponse failedLogin = new MockHttpServletResponse();
+ MockHttpServletResponse rejectedRequest = new MockHttpServletResponse();
+ new YibanMatchedAuthenticationFailureHandler().onAuthenticationFailure(request, failedLogin, failure);
+ new YibanMatchedAuthenticationEntryPoint().commence(request, rejectedRequest, failure);
+ assertThat(failedLogin.getContentAsString()).isEqualTo(rejectedRequest.getContentAsString());
+ assertThat(failedLogin.getStatus()).isEqualTo(200);
+ assertThat(JSONObject.parseObject(failedLogin.getContentAsString()).getInteger("code"))
+ .isEqualTo(AuthResponseCode.SC_AUTHZ_THIRD_PARTY_SERVICE.getCode());
+ }
+}