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-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>
|
||||
+72
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user