mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 10:00:30 +08:00
feat: add native/Java auth SDK, docs, CI, and examples
Made-with: Cursor
This commit is contained in:
@@ -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-bitanswer</artifactId>
|
||||
<name>CraftLabs Auth — Bitanswer adapter</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.craftlabs</groupId>
|
||||
<artifactId>craftlabs-auth-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package cn.craftlabs.auth.bitanswer;
|
||||
|
||||
import cn.craftlabs.auth.AuthProvider;
|
||||
import cn.craftlabs.auth.AuthResult;
|
||||
import cn.craftlabs.auth.LicenseInfo;
|
||||
import cn.craftlabs.auth.internal.NativeBridge;
|
||||
|
||||
/**
|
||||
* 比特安索(Bitanswer)授权提供者的 Java 封装。
|
||||
*
|
||||
* <p>在静态初始化块中加载本地库 {@code craftlabs_auth_bitanswer},通过 {@link
|
||||
* cn.craftlabs.auth.internal.NativeBridge} 将 {@link cn.craftlabs.auth.AuthProvider} 各方法委托给 C
|
||||
* 端实现。重复调用 {@link #initialize(String)} 会先销毁已有 native 句柄再重新初始化。
|
||||
*
|
||||
* <p>版权所有 © 广州创飞人工智能技术有限公司
|
||||
*
|
||||
* @author huangping@craftlabs.cn
|
||||
*/
|
||||
public final class BitAnswerProvider 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");
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user