首页
/ TinyRadius 技术文档

TinyRadius 技术文档

2024-12-24 03:07:56作者:江焘钦

1. 安装指南

环境要求

  • JDK 1.4 或更高版本
  • Apache Commons Logging

安装步骤

  1. TinyRadius 项目页面 下载最新版本的 TinyRadius。
  2. 解压下载的压缩包。
  3. 将解压后的 TinyRadius-x.x.x.jar 文件添加到项目的类路径中。
  4. 如果你需要 Apache Commons Logging,请确保将其也添加到类路径中。

2. 项目使用说明

TinyRadius 是一个简单、小巧且快速的 Java Radius 库,能够发送和接收所有类型的 Radius 包。下面是基本的使用方法:

示例 1:简单认证

RadiusClient rc = new RadiusClient(host, sharedSecret);
if (rc.authenticate(userName, password)) {
    // 认证成功
}

示例 2:发送带有多个属性的 Access-Request

// 1. 创建 RadiusClient 对象
RadiusClient rc = new RadiusClient(host, sharedSecret);

// 2. 创建 Access-Request 包
AccessRequest ar = new AccessRequest(userName, password);
ar.setAuthProtocol(AccessRequest.AUTH_CHAP); // 或者 AUTH_PAP

// 3. 设置其他属性
ar.addAttribute("NAS-Identifier", "this_is_my_nas_identifier_de");
ar.addAttribute("NAS-IP-Address", "192.168.0.100");
ar.addAttribute("Service-Type", "Login-User");
ar.addAttribute("WISPr-Location-ID", "ger_de_sample_location");

// 4. 发送包并接收响应
RadiusPacket response = rc.authenticate(ar);
if (response.getPacketType() == RadiusPacket.ACCESS_ACCEPT) {
    // 响应是 Access-Accept
}

3. 项目 API 使用文档

TinyRadius 提供了丰富的 API,以下是部分常用的类和方法:

  • RadiusClient: 用于发送和接收 Radius 包。

    • RadiusClient(String host, String sharedSecret): 构造函数。
    • boolean authenticate(String userName, String password): 使用用户名和密码进行认证。
    • RadiusPacket authenticate(AccessRequest request): 发送 Access-Request 包并接收响应。
  • AccessRequest: 表示一个 Access-Request 包。

    • AccessRequest(String userName, String password): 构造函数。
    • void setAuthProtocol(int authProtocol): 设置认证协议(PAP 或 CHAP)。
    • void addAttribute(String attributeName, String value): 添加一个属性。
  • RadiusPacket: 表示一个 Radius 包。

    • int getPacketType(): 获取包类型。
    • void encode(): 对包进行编码。
    • void decode(): 对包进行解码。

更多 API 文档请参考项目中的 apidoc 目录。

4. 项目安装方式

TinyRadius 的安装方式已在上述的“安装指南”中详细说明。简要总结如下:

  1. 确保你的开发环境满足要求(JDK 1.4 或更高版本,Apache Commons Logging)。
  2. 下载 TinyRadius 的最新版本。
  3. 解压下载的压缩包。
  4. TinyRadius-x.x.x.jar 文件添加到项目的类路径中。
  5. 如果需要 Apache Commons Logging,请确保将其也添加到类路径中。
登录后查看全文
热门项目推荐