mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 10:00:30 +08:00
f94f03bcc2
Add craftlabs-auth-config.schema.json, Java AuthConfigs model with tests, example configs aligned to BP-10, C/Java/auth-config documentation, native header notes, RELEASING guide, and workflow to verify SDK artifact checksums on release tags. Made-with: Cursor
49 lines
1.8 KiB
Java
49 lines
1.8 KiB
Java
import cn.craftlabs.auth.AuthProvider;
|
|
import cn.craftlabs.auth.AuthResult;
|
|
import cn.craftlabs.auth.bitanswer.BitAnswerProvider;
|
|
import cn.craftlabs.auth.config.AuthConfig;
|
|
import cn.craftlabs.auth.config.AuthConfigException;
|
|
import cn.craftlabs.auth.config.AuthConfigs;
|
|
|
|
/**
|
|
* 演示:校验 {@code config_json} 后初始化并完成许可校验。
|
|
*
|
|
* <p>编译时需将 {@code craftlabs-auth-core} 与 Jackson 置于 classpath(与 Maven 模块依赖一致)。
|
|
*
|
|
* <p>版权所有 © 广州创飞人工智能技术有限公司
|
|
*
|
|
* @author huangping@craftlabs.cn
|
|
*/
|
|
public class ExampleApp {
|
|
public static void main(String[] args) {
|
|
String json =
|
|
"""
|
|
{
|
|
"schemaVersion": 1,
|
|
"provider": "bitanswer",
|
|
"scenario": "school",
|
|
"bitanswer": { "url": "https://example.invalid/bitanswer", "loginMode": "AUTO" },
|
|
"features": {
|
|
"face": { "bitanswerFeatureId": 201 },
|
|
"expression": { "bitanswerFeatureId": 202 }
|
|
},
|
|
"school": { "edgeDeviceId": "demo-edge-01", "tenantId": "demo-tenant" }
|
|
}
|
|
""";
|
|
try {
|
|
AuthConfig cfg = AuthConfigs.parse(json);
|
|
System.out.println("scenario=" + cfg.scenario() + ", face id=" + cfg.bitanswerFeatureId("face"));
|
|
} catch (AuthConfigException e) {
|
|
System.err.println("config invalid: " + e.getMessage());
|
|
return;
|
|
}
|
|
|
|
try (AuthProvider p = new BitAnswerProvider()) {
|
|
AuthResult r = p.initialize(json);
|
|
System.out.println("init: " + r.isSuccess() + " " + r.getMessage());
|
|
r = p.checkLicense();
|
|
System.out.println("check: " + r.isSuccess() + " " + r.getMessage());
|
|
}
|
|
}
|
|
}
|