
正文
基于RSA securID的Radius二次验证java实现(PAP验证方式)
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
基于rsa SecurID的二次验证。RSA server自身可以作为Radius服务器,RSA也可以和其他的软件集合,使用其他的server作为Radius服务器。
radius的验证的一般流程如下图:

用java实现的主要代码实现如下(需要导入radius相关jar包,主要为radiusclient3.jar):
①radius第一次验证, RADIUSClient的4个参数分别为server ip,port,Radius的密钥,radius输入超时时间. authenticate的username和password即为所需要验证的用户.
RADIUSClient r = null;
int nResult = 0; r = new RADIUSClient("ip", port , "secret" , radius_soctet_timeout);
r.setDebug(true);
AttributeList aList = new AttributeList();
aList.addAttribute(Attribute.NAS_Port, 1);
nResult = r.authenticate(username, password, aList);
②跟据返回的nResult进行判断.代码中的数字3代表access_reject, 数字0代表access_badpacket, 数字11代表access_challenge, 数字2代表access_accept.
当遇到access_challenge时,有两种情况,一只是需要new pin(new pin的情况相对复杂一点), 另一种是需要next token.另外,这个Attribute.State属性是一直要继承的,用来区分
是否是我们需要的那一次验证(如代码25, 26行,就把state带入下一次验证,用来验证识别).
switch (nResult) {
case 3:
try{
AttributeList response = r.getAttributes();
AttributeList state = response.getAttributeList(Attribute.State);
}
catch(Exception e){ } break;
case 0: break;
case 11:
AttributeList response = r.getAttributes();
AttributeList state = response.getAttributeList(Attribute.State);
r.reset();
System.out.println(":");
Scanner sa = new Scanner(System.in);
String sl = sa.next();
String mima = sl + "";
AttributeList attList = new AttributeList();
attList.addAttribute(Attribute.NAS_Port, 1);
attList.mergeAttributes(state);
nResult = r.authenticate(username, mima, attList);
System.out.println(r.getPacketType());
System.out.println("r.getErrorString():" + r.getErrorString());
System.out.println("Second nResult:" + nResult);
if(nResult == 11){
AttributeList rresponse = r.getAttributes();
AttributeList sstate = rresponse.getAttributeList(Attribute.State);
r.reset();
System.out.println("re new pins");
Scanner ssa = new Scanner(System.in);
String ssl = ssa.next();
String renewpin = ssl + "";
System.out.println(renewpin);
AttributeList aattList = new AttributeList();
aattList.addAttribute(Attribute.NAS_Port, 1);
aattList.mergeAttributes(sstate);
nResult = r.authenticate(username, renewpin, aattList);
System.out.println(r.getPacketType());
System.out.println("r.getErrorString():" + r.getErrorString());
if (nResult == 11){
AttributeList rrresponse = r.getAttributes();
AttributeList ssstate = rrresponse.getAttributeList(Attribute.State);
r.reset();
System.out.println("posscode");
Scanner ressa = new Scanner(System.in);
String ressl = ressa.next();
String passcode = ressl + "";
AttributeList reaattList = new AttributeList();
reaattList.addAttribute(Attribute.NAS_Port, 1);
nResult = r.authenticate(username, passcode, reaattList);
System.out.println(r.getPacketType());
System.out.println("r.getErrorString():" + r.getErrorString());
System.out.println("nResult:" + nResult);
if (nResult == 2){
return "AUTH SUCCESS";
}
}
}
if (nResult == 2){
return "AUTH SUCCESS";
}
case 2: return "AUTH SUCCESS";
default: break;
}
return "AUTH FAILURE";
转载请注明出处:http://www.cnblogs.com/huhanbo/p/4087827.html






