Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
|---|:---:|---|
| 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 |
| `YibanOAuthClient` bean | Declared in source | Auto-registered via SecurityYibanAutoConfiguration |

## 3. Requirements and Compatibility

Expand All @@ -60,40 +60,25 @@ For Boot 2.3 applications using the Boot parent, set `spring-framework.version`
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`.
The starter implements the OAuth contract from the official Yiban Java example (2.26.1103) with its existing Apache HttpClient. It uses the JVM trust store and hostname verification and disables redirects for API requests.

## 4. Auto-configuration

The starter auto-configures the following beans:

| Bean | Condition | Missing Behavior |
|---|---|---|
| `Authorize` | classpath + property | not created |
| `YibanOAuthClient` | classpath + property | not created |
| `SecurityContextLogoutHandler` | classpath + property | not created |
| `YibanMatchedAuthenticationEntryPoint` | classpath + property | not created |
| `YibanMatchedAuthenticationFailureHandler` | classpath + property | not created |
| `YibanAuthenticationProvider` | classpath + property | not created |

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.
Boot 2.3 discovers these configurations through `META-INF/spring.factories`. The registered callback must route to `/login/yiban` by default, or to the configured `spring.security.yiban.authc.login-url`.

## 5. Dependencies

The build requires two artifacts that are currently unresolved:

- `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.

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.

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.
Use the starter with the Easy4J Security Biz dependency available from the snapshot repository. Provide a `UserDetailsServiceAdapter` bean to map verified Yiban credentials to a local account.

## 6. Enable Yiban configuration

Expand All @@ -104,6 +89,10 @@ spring:
security:
yiban:
enabled: true
authc:
app-key: ${YIBAN_APP_KEY}
app-secret: ${YIBAN_APP_SECRET}
callback: https://app.example.com/login/yiban
```

## 7. Configuration Reference
Expand All @@ -119,6 +108,8 @@ spring:
| `spring.security.yiban.enabled` | boolean | `false` | No | Enable the starter | No |
<!-- additional properties below -->

Authorization uses a one-time session state. Check the [OAuth migration notes](docs/reviews/pr-2-current-oauth.md) when updating existing Yiban integrations.

## 8. Version Lines and Compatibility

| Branch | JDK | Spring Boot | Component Version | Status |
Expand Down
25 changes: 11 additions & 14 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
|---|:---:|---|
| 自动装配 | 源码已声明 | 自动注册 security-yiban 相关 Bean |
| 属性绑定 | 源码已声明 | 绑定 `spring.security.yiban.authc.*` 到 `SecurityYibanAuthcProperties` |
| `Authorize` Bean | 源码已声明 | 通过 SecurityYibanAutoConfiguration 自动注册 |
| `YibanOAuthClient` Bean | 源码已声明 | 通过 SecurityYibanAutoConfiguration 自动注册 |

## 3. 运行要求与兼容性

Expand All @@ -60,34 +60,25 @@
快照构建 `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`。
Starter 使用现有 Apache HttpClient 实现易班 Java 官方示例 2.26.1103 的 OAuth 协议。接口请求使用 JVM 信任库和主机名校验,并禁用重定向。

## 4. 自动装配

Starter 自动装配以下 Bean:

| Bean | 条件 | 缺失时行为 |
|---|---|---|
| `Authorize` | classpath + property | 不创建 |
| `YibanOAuthClient` | classpath + property | 不创建 |
| `SecurityContextLogoutHandler` | classpath + property | 不创建 |
| `YibanMatchedAuthenticationEntryPoint` | classpath + property | 不创建 |
| `YibanMatchedAuthenticationFailureHandler` | classpath + property | 不创建 |
| `YibanAuthenticationProvider` | classpath + property | 不创建 |

当前源码包含配置类,但没有 Boot 2.3 自动发现使用的 `META-INF/spring.factories`。自动发现及真实易班登录流程仍待验证。
Boot 2.3 通过 `META-INF/spring.factories` 发现这些自动配置。注册回调默认应指向 `/login/yiban`,也可使用应用配置的 `spring.security.yiban.authc.login-url`。

## 5. 引入依赖

本分支构建仍需解析以下依赖:

- `cn.yiban.open:java-sdk:1.6.0`,易班授权及用户接口。
- `io.github.easy4j:security-biz-spring-boot-starter:1.0.9-SNAPSHOT`,通用 Spring Security 组件。

[易班官方下载的 Java 压缩包](https://open.yiban.cn/wiki/download/oauth_java.7z)包含 Servlet 授权示例,未提供上述 Maven SDK JAR。需先从可信来源解析这两个 Maven 制品,并完成 Java 8 构建和联调,再验证可用的发布坐标。

Security Biz 的历史 `1.0.9` 源码使用旧组织坐标。对阿里云私服的独立解析显示,Easy4J 坐标下的 `1.0.9-SNAPSHOT` 和 Boot 2.3 维护版 `2.3.x.20260630-SNAPSHOT` 均未解析到。切换到维护版还需验证 Spring Security 版本及异常响应兼容性。
使用 Starter 时需能从 Easy4J 快照仓库解析 Security Biz,应用需提供 `UserDetailsServiceAdapter` Bean,把已验证的易班凭据映射到本地账号。

## 6. 启用配置

Expand All @@ -98,6 +89,10 @@ spring:
security:
yiban:
enabled: true
authc:
app-key: ${YIBAN_APP_KEY}
app-secret: ${YIBAN_APP_SECRET}
callback: https://app.example.com/login/yiban
```

## 7. 配置参考
Expand All @@ -113,6 +108,8 @@ spring:
| `spring.security.yiban.enabled` | boolean | `false` | 否 | 是否启用 Starter | 否 |
<!-- 更多属性见下方 -->

授权流程使用会话内的一次性状态。升级已接入易班的应用时,请核对[迁移说明](docs/reviews/pr-2-current-oauth.md)。

## 8. 版本线与兼容性

| 分支 | JDK | Spring Boot | 组件版本 | 状态 |
Expand Down
15 changes: 15 additions & 0 deletions docs/reviews/pr-2-current-oauth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 易班 PR #2 的 OAuth 迁移

官网发布的 Java SDK 2.26.1103 提供 JDK 11 与 Jakarta Servlet 示例源码。本 Starter 保留 JDK 8 与 Spring Boot 2.3,复用已有 Apache HttpClient 实现该协议。[官方 Java SDK 下载](https://o.yiban.cn/wiki/index.php?page=SDK%E4%B8%8B%E8%BD%BD)

| 步骤 | 接口 | 验收 |
| --- | --- | --- |
| 发起授权 | `GET https://oauth.yiban.cn/code/authorize` | 发送应用 ID、注册回调和会话级随机 state |
| 换取令牌 | `POST https://oauth.yiban.cn/token/info` | 校验并消耗 state 后,以 UTF-8 表单发送 code、应用 ID、密钥与注册回调 |
| 读取用户 | `GET https://openapi.yiban.cn/user/me` | 成功响应须包含 `info.yb_userid`,再由应用的 `UserDetailsServiceAdapter` 完成本地认证 |

用户接口遵循公开 API 指定的 `access_token` 查询参数。学校实名验证属于易班独立接口,应用应根据自身业务规则选择。[易班 user/me 文档](https://o.yiban.cn/wiki/index.php?page=user/me)

原 `yibanAuthorize` Bean 现在返回 `YibanOAuthClient`。直接引用旧 SDK 类型的代码应迁移到新客户端。已有 `state` 属性可继续绑定,实际授权使用每次生成的一次性值。新版授权接口移除了 `display` 参数。若配置 `redirect_uri`,该值优先于 `callback`,授权和换令牌请求使用同一地址。应用需在易班开放平台注册该地址,并将它路由到 Starter 的登录入口。

集成测试使用本机 HTTP 模拟易班,覆盖自动装配、浏览器授权跳转、回调、一次性状态校验、用户映射以及失败响应。真实平台联调需要已注册的应用、密钥和可用回调地址。
33 changes: 0 additions & 33 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,39 +247,6 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>verify-and-unpack-yiban-sdk</id>
<phase>generate-resources</phase>
<goals><goal>run</goal></goals>
<configuration>
<target>
<unzip src="${project.basedir}/YBApi_sdk_java.zip" dest="${project.build.directory}/yiban-sdk">
<patternset><include name="YBApi_sdk_java_20150820/lib/YBOpenApi.jar"/></patternset>
</unzip>
<checksum file="${project.build.directory}/yiban-sdk/YBApi_sdk_java_20150820/lib/YBOpenApi.jar"
algorithm="SHA-256"
property="9dfce10cbca8776f2b6fa144d770385b94c5054bbc01544fe1983df05c67486c"
verifyproperty="yiban.sdk.valid"/>
<fail message="Unexpected YBOpenApi.jar SHA-256">
<condition><isfalse value="${yiban.sdk.valid}"/></condition>
</fail>
<unzip src="${project.build.directory}/yiban-sdk/YBApi_sdk_java_20150820/lib/YBOpenApi.jar"
dest="${project.build.outputDirectory}">
<patternset>
<include name="cn/yiban/**/*.class"/>
<exclude name="cn/yiban/util/HTTPSimple*.class"/>
</patternset>
</unzip>
</target>
</configuration>
</execution>
</executions>
</plugin>
<!--环境检查插件:代码编译前的环境检查 -->
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-enforcer-plugin -->
<plugin>
Expand Down
62 changes: 0 additions & 62 deletions src/main/java/cn/yiban/util/HTTPSimple.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.springframework.security.boot.yiban.authentication.YibanAuthorizationProcessingFilter;
import org.springframework.security.core.Authentication;

import cn.yiban.open.Authorize;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
Expand All @@ -40,13 +39,18 @@ public class SecurityYibanAuthcProperties extends SecurityAuthcProperties {

public static final String PREFIX = "spring.security.yiban.authc";

public SecurityYibanAuthcProperties() {
setPathPattern(YibanAuthorizationProcessingFilter.AUTHORIZATION_PATH);
}

/**
* 接入应用 APPID
*/
private String appKey;
/**
* 接入应用的 AppSecret
*/
@ToString.Exclude
private String appSecret;
private String callback;

Expand All @@ -64,7 +68,6 @@ public class SecurityYibanAuthcProperties extends SecurityAuthcProperties {
/** 异常页面:认证失败时的跳转路径 */
private String failureUrl = "/error";

private Authorize.DISPLAY_TAG_T display = Authorize.DISPLAY_TAG_T.WEB;

private String authorizationParamName = YibanAuthorizationProcessingFilter.AUTHORIZATION_PARAM;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,28 @@
import org.springframework.security.boot.yiban.authentication.YibanAuthenticationProvider;
import org.springframework.security.boot.yiban.authentication.YibanMatchedAuthenticationEntryPoint;
import org.springframework.security.boot.yiban.authentication.YibanMatchedAuthenticationFailureHandler;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;

import cn.yiban.open.Authorize;
import org.springframework.security.boot.yiban.client.YibanOAuthClient;
import org.springframework.util.StringUtils;

@Configuration
@AutoConfigureBefore(SecurityBizAutoConfiguration.class)
@ConditionalOnProperty(prefix = SecurityYibanProperties.PREFIX, value = "enabled", havingValue = "true")
@EnableConfigurationProperties({ SecurityYibanProperties.class })
@EnableConfigurationProperties({ SecurityYibanProperties.class, SecurityYibanAuthcProperties.class })
public class SecurityYibanAutoConfiguration {

/**
* 在程序文件中导入并使用AppID与AppSecret来初始化cn.yiban.open.Authorize
* 创建使用当前易班 OAuth 接口的客户端。
*/
@Bean
public Authorize yibanAuthorize(SecurityYibanAuthcProperties authcProperties) {
return new Authorize(authcProperties.getAppKey(), authcProperties.getAppSecret());
@ConditionalOnMissingBean(YibanOAuthClient.class)
public YibanOAuthClient yibanAuthorize(SecurityYibanAuthcProperties authcProperties) {
String redirectUri = authcProperties.getRedirect_uri();
if (!StringUtils.hasText(redirectUri)) {
redirectUri = authcProperties.getCallback();
}
return new YibanOAuthClient(authcProperties.getAppKey(), authcProperties.getAppSecret(), redirectUri);
}


Expand Down Expand Up @@ -54,8 +59,8 @@ public YibanMatchedAuthenticationFailureHandler yibanMatchedAuthenticationFailur

@Bean
public YibanAuthenticationProvider yibanAuthenticationProvider(UserDetailsServiceAdapter userDetailsService,
PasswordEncoder passwordEncoder) {
return new YibanAuthenticationProvider(userDetailsService);
YibanOAuthClient yibanAuthorize) {
return new YibanAuthenticationProvider(userDetailsService, yibanAuthorize);
}

}
Loading