feat: add native/Java auth SDK, docs, CI, and examples

Made-with: Cursor
This commit is contained in:
hpd840321
2026-04-06 17:42:09 +08:00
commit 3894315759
35 changed files with 4825 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.craftlabs</groupId>
<artifactId>craftlabs-auth-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>craftlabs-auth-selfhosted</artifactId>
<name>CraftLabs Auth — self-hosted HTTP adapter</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>cn.craftlabs</groupId>
<artifactId>craftlabs-auth-core</artifactId>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,72 @@
package cn.craftlabs.auth.selfhosted;
import cn.craftlabs.auth.AuthProvider;
import cn.craftlabs.auth.AuthResult;
import cn.craftlabs.auth.LicenseInfo;
import cn.craftlabs.auth.internal.NativeBridge;
/**
* 自研授权(HTTP)适配器的 Java 封装。
*
* <p>当前阶段复用与 Bitanswer 相同的 native 桩实现;后续可切换为独立 {@code
* libcraftlabs_auth_selfhosted}。
*
* <p>版权所有 © 广州创飞人工智能技术有限公司
*
* @author huangping@craftlabs.cn
*/
public final class SelfHostedAuthProvider implements AuthProvider {
static {
System.loadLibrary("craftlabs_auth_bitanswer");
}
private long nativeHandle;
@Override
public AuthResult initialize(String configJson) {
if (nativeHandle != 0L) {
NativeBridge.nativeDestroy(nativeHandle);
nativeHandle = 0L;
}
nativeHandle = NativeBridge.nativeInitialize(configJson != null ? configJson : "{}");
return new AuthResult(true, "Initialized (self-hosted stub)");
}
@Override
public AuthResult activate(String licenseKey) {
return NativeBridge.nativeActivate(nativeHandle, licenseKey);
}
@Override
public AuthResult checkLicense() {
return NativeBridge.nativeCheckLicense(nativeHandle);
}
@Override
public LicenseInfo getLicenseInfo() {
return NativeBridge.nativeGetLicenseInfo(nativeHandle);
}
@Override
public boolean hasFeature(String featureName) {
return NativeBridge.nativeHasFeature(nativeHandle, featureName);
}
@Override
public AuthResult release() {
return NativeBridge.nativeRelease(nativeHandle);
}
@Override
public AuthResult heartbeat() {
return NativeBridge.nativeHeartbeat(nativeHandle);
}
@Override
public void close() {
if (nativeHandle != 0L) {
NativeBridge.nativeDestroy(nativeHandle);
nativeHandle = 0L;
}
}
}