freeradius client

radtest只是用来调试的,radclient功能更强大。用法如下:

From the man page we can see that radclient gives us much more power as compared to radtest. The following command can be used as an equivalent to the radtest command used at the start of this chapter:

$> echo "User-Name=alice,User-Password=passme" | radclient 127.0.0.1 auth testing123

radclient的格式: Usage: radclient [options] server[:port] <command> [<secret>]

<command>  类型:  One of auth, acct, status, coa, or disconnect.

如果不是调试模式的话,只会返回code码。

The response from radclient returns a code number and does not clearly indicate a pass or fail for an Access-Request. This is where you need to know the RADIUS packet codes as discussed in Chapter 1.

Here is the response of an Access-Accept packet (Code 2 成功):

Received response ID 32, code 2, length = 40 Framed-IP-Address = 192.168.1.65
Reply-Message = "Hello, alice"

Here is the response of an Access-Reject packet:(code 3  鉴权失败

Received response ID 59, code 3, length = 34
Reply-Message = "Hello, alice"

jradius安装/编译/使用

当然还是优先参考官方文档:http://coova.github.io/JRadius/FreeRADIUS/

wget ftp://ftp.freeradius.org/pub/freeradius/freeradius-server-2.1.1.tar.bz2
bzcat freeradius-server-2.1.1.tar.bz2 | tar xf -
cd freeradius-server-2.1.1
echo rlm_jradius >> src/modules/stable

./configure
 make
 make install

就是在解压后编译前,在 src/modules/stable文件添加一行rlm_jradius ,然后再编译就有freeradius对jradius的支持模块了。

修改freeradius的配置

etc/raddb/radiusd.conf  配置文件中添加下面的部分

modules {
...
# configure the rlm_jradius module
jradius {
name = "example" # The "Requester" name (a single
# JRadius server can have
# multiple "applications")
primary = "localhost" # Uses default port 1814
secondary = "192.168.0.1" # Fail-over server
tertiary = "192.168.0.1:8002" # Fail-over server on port 8002
timeout = 1 # Connect Timeout
onfail = NOOP # What to do if no JRadius
# Server is found. Options are:
# FAIL (default), OK, REJECT, NOOP
keepalive = yes # Keep connections to JRadius pooled
connections = 8 # Number of pooled JRadius connections
}
}

在sites-available/default配置文件中,各个模块添加jradius关键字

authorize {
...
jradius
} post-auth {
...
jradius
Post-Auth-Type REJECT { # Use this to also process failures -
jradius # AccessReject replies
} # from the post-auth handler.
} preacct {
...
jradius
} accounting {
...
jradius
} 

以上步骤freeradius部分已经配置好了。之后编译安装jradius

编译安装jradius

官方给的步骤

官方是先编译后解压,应该是先下载源码解压后在根目录用maven编译

mvn clean install

编译成功后,在  jradius/server/scripts  下有start.sh文件但是无法启动,找不到类,vim start.sh打开

(cd `dirname $0`; classpath=".:./lib"
for jar in ./lib/*.jar; do
classpath="$classpath:$jar"
done
CLASSPATH="$classpath" java net.jradius.StartSpring)

由于当前目录没有lib文件夹,找不到类,我直接修改脚本,

(cd `dirname $0`; classpath=".:./lib"
for jar in /data/jradius/server/target/lib/*.jar; do
classpath="$classpath:$jar"
done
CLASSPATH="$classpath" java net.jradius.StartSpring)

/data/jradius 是我的jradius安装目录,这样还不行,报错缺少配置文件,再把 jradius/server/config下的所以配置文件copy到start.sh的目录下,再次./start.sh启动就可以成功了。

接下来用java代码测试,测试代码可以参考:

public class JradiusTest {

    public static void main(String[] args) throws Exception {
if(args.length!=4) {
System.out.println("<host><secret><username><password>");
System.exit(2);
}
InetAddress host = InetAddress.getByName(args[0]);
boolean aa=new JradiusTest().isRadius(host, 1812, 1813, "pap",args[2] , args[3], args[1], "110.110.110.110", 3, 3000);
System.out.println("鉴权结果:"+aa);
} /**
*
* @param host
* The address for the radius server test.
* @param authport
* Radius authentication port
* @param acctport
* Radius accounting port - required by jradius
* but not explicitly checked
* @param authType
* authentication type - pap or chap
* @param user
* user for Radius authentication
* @param password
* password for Radius authentication
* @param secret
* Radius shared secret
* @param timeout
* Timeout in milliseconds
* @param retry
* Number of times to retry
*
* @param nasid
* NAS Identifier to use
*
* @return True if server, false if not.
*/
@SuppressWarnings("unused")
private boolean isRadius(final InetAddress host, final int authport, final int acctport, final String authType,
final String user, final String password, final String secret, final String nasid, final int retry, final int timeout) { boolean isRadiusServer = false; AttributeFactory.loadAttributeDictionary("net.jradius.dictionary.AttributeDictionaryImpl");
try {
// final RadiusClient rc = new RadiusClient(host, secret, authport, acctport, convertTimeoutToSeconds(timeout));
final RadiusClient rc = new RadiusClient(host, secret, authport, acctport, timeout); final AttributeList attributes = new AttributeList();
attributes.add(new Attr_UserName(user));
attributes.add(new Attr_NASIdentifier(nasid));
attributes.add(new Attr_UserPassword(password)); final AccessRequest accessRequest = new AccessRequest(rc, attributes);
final RadiusAuthenticator auth;
if (authType.equalsIgnoreCase("chap")) {
auth = new CHAPAuthenticator();
} else if (authType.equalsIgnoreCase("pap")) {
auth = new PAPAuthenticator();
} else if (authType.equalsIgnoreCase("mschapv1")) {
auth = new MSCHAPv1Authenticator();
} else if (authType.equalsIgnoreCase("mschapv2")) {
auth = new MSCHAPv2Authenticator();
} else if (authType.equalsIgnoreCase("eapmd5")) {
auth = new EAPMD5Authenticator();
} else if (authType.equalsIgnoreCase("eapmschapv2")) {
auth = new EAPMSCHAPv2Authenticator();
} else {
// LogUtils.warnf(this, "Unknown authenticator type '%s'", authType);
return isRadiusServer;
} RadiusPacket reply = rc.authenticate(accessRequest, auth, retry);
isRadiusServer = reply instanceof AccessAccept;
// LogUtils.debugf(this, "Discovered RADIUS service on %s", host.getCanonicalHostName());
} catch (final Throwable e) {
// LogUtils.debugf(this, e, "Error while attempting to discover RADIUS service on %s", host.getCanonicalHostName());
isRadiusServer = false;
} return isRadiusServer;
} }

更多jradius客户端使用代码参考

github的example

https://github.com/coova/jradius/blob/master/example/src/main/java/net/jradius/example/ExampleRadiusClient.java

 和programcreek的example

https://www.programcreek.com/java-api-examples/index.php?api=net.jradius.client.RadiusClient

other :

我用上面代码去鉴权的时候,鉴权可以成功,但是jradius的服务端会报错

net.jradius.server.KeepAliveListener.run(): shutting down tcp socket listener
java.nio.BufferUnderflowException
at java.nio.Buffer.nextGetIndex(Buffer.java:498)
at java.nio.HeapByteBuffer.getInt(HeapByteBuffer.java:355)
at net.jradius.packet.Format.getUnsignedInt(Format.java:389)
at net.jradius.freeradius.FreeRadiusListener.parseRequest(FreeRadiusListener.java:98)
at net.jradius.server.ListenerRequest.getEventFromListener(ListenerRequest.java:78)
at net.jradius.server.TCPListenerRequest.accept(TCPListenerRequest.java:72)
at net.jradius.server.KeepAliveListener.run(KeepAliveListener.java:61)

而且freeradius的debug日志中看到,账号密码鉴权是成功的,但是rlm_jradius 发送数据的时候失败了。

测试代码中打印出reply.getCode() ,为2,说明鉴权是成功的,我不知道请求包缺少了必要的数据还是我配置文件没有弄对,导致数据包在FreeRadiusListener.parseRequest解析时报错。

研究后发现  上面的报错是应为ByteBuffer的limit小于实际的数据长度导致的,我以为是jradius本身的一个小bug,就注释掉FreeradiusListener.java 中96行的代码,重新编译运行,发现这个错虽然没了,但是又直接抛出了102行的异常。

这个异常没有解决,没想明白。

参考:http://blog.csdn.net/lzz957748332/article/category/6017279

freeradius client 和jradius安装编译的更多相关文章

  1. 比特币Bitcoin源代码安装编译

    body{ font: 16px/1.5em 微软雅黑,arial,verdana,helvetica,sans-serif; }        比特币 (货币符号: ฿;英文名:Bitcoin;英文 ...

  2. linux centos安装编译phantomjs 2.0的方法

    phantomjs 2.0最新版的官方不提供编译好的文件下载,只能自己编译,有教程但是过于简单,特别是服务器上要安装N多的支持.折腾到现在终于装好了并且能正常运行了,截图mark一下: linux c ...

  3. linux_安装_安装编译phantomjs 2.0的方法_转

    项目中要对数据公式webkit渲染,phantmjs 2.0的效果好比1.9好不少. 安装过程中 坑比较多. 转载文章: phantomjs 2.0最新版的官方不提供编译好的文件下载,只能自己编译,有 ...

  4. wxWidgets的安装编译、相关配置、问题分析处理

    wxWidgets的安装编译.相关配置.问题分析处理 一.介绍部分 (win7 下的 GUI 效果图见 本篇文章的最后部分截图2张) wxWidgets是一个开源的跨平台的C++构架库(framewo ...

  5. FFmpeg在Linux下安装编译过程

    转载请把头部出处链接和尾部二维码一起转载,本文出自:http://blog.csdn.net/hejjunlin/article/details/52402759 今天介绍下FFmpeg在Linux下 ...

  6. openblas下载安装编译

    编译好的库: https://github.com/JuliaLinearAlgebra/OpenBLASBuilder/releases 源码编译 下载:https://github.com/xia ...

  7. Linux上安装编译工具链

    在Linux上安装编译工具链,安装它会依赖dpkg-dev,g++,libc6-dev,make等,所以安装之后这些依赖的工具也都会被安装.ubuntu软件库中这么描述 Informational l ...

  8. plsql oracle client没有正确安装(plsql连接远程数据库)

      plsql oracle client没有正确安装(plsql连接远程数据库) CreateTime--2018年4月23日16:55:11 Author:Marydon 1.情景再现 2.问题解 ...

  9. (0.2.6)Mysql安装——编译安装

    (0.2.6)Mysql安装——编译安装 待完善

随机推荐

  1. JDK Mac 安装

    JDK安装步骤 一台mac os  环境 jdk.sdk.Android studio 1.打开终端-输入命令Java     2.从下面的图中可以看到,终端会自动给出提示,没有可以使用的java命令 ...

  2. 动手学深度学习9-多层感知机pytorch

    多层感知机 隐藏层 激活函数 小结 多层感知机 之前已经介绍过了线性回归和softmax回归在内的单层神经网络,然后深度学习主要学习多层模型,后续将以多层感知机(multilayer percetro ...

  3. Java连载12-继承开发环境&long类型

    一.集成开发环境(Integrated Develop Environment,简称IDE) 1.什么是集成开发环境 (1)集成开发环境可以使软件开发变得更简单 (2)没有IDE工具: i.需要安装J ...

  4. ROS融合IMU笔记

    ROS官网有一个叫robot_pose_ekf的包,是专门处理传感器融合的包,具体介绍:http://wiki.ros.org/robot_pose_ekf 其中主要功能是订阅主题包括odom(里程计 ...

  5. Flask高级

    关于Flask启动,和请求处理 #关于后端服务的启动,无非就是启动实现了WSGI协议的socket #关于flask启动的无非就是下面两段代码 #加载配置,创建Flask对象 app = Flask( ...

  6. 需要“jquery”ScriptResourceMapping。请添加一个名为 jquery (区分大小写)的 ScriptResourceMapping。

    问题: 该错误是因为应用程序需要jQuery,但是当前项目中并没有jQuery,或者存在jQuery但是程序不知道jQuery的存放路径. 解决方案: 一.下载jQuery,引入必要的jquery-X ...

  7. ElasticSearch(九)e代驾使用Elasticsearch流程设计(Yii1版本)

    一.控制器层的更新.添加.删除 class AddKnowledgeAction extends CAction { //add and update public function actionPo ...

  8. 设计模式之(十四)责任链模式(Chain of Responsibility)

    在业务场景中,有很多是需要审批的.审核方式还可能常常发生变化,而责任链模式就是为了解决这种场景的情况的. 责任链模式定义:十多个对象都有机会处理请求,从而避免发送者和接受者之间的耦合关系.讲这些对象连 ...

  9. asp.net+jquery 制作text editor

    利用jquery制作的文本编辑器,直接给源码吧,相信大家都能看懂.点此下载

  10. 英语cowbezoar牛黄cowbezoar单词

    牛黄(cowbezoar)是脊索动物门哺乳纲牛科动物牛胆囊的胆结石.在胆囊中产生的称“胆黄”或“蛋黄”,在胆管中产生的称“管黄”,在肝管中产生的称“肝黄”. 中文学名牛黄 拉丁学名Bos taurus ...