Java Implementation of Radius secondary verification based on RSA securID (PAP authentication method) and securidradius
Secondary Verification Based on rsa SecurID. The RSA server itself can be used as a Radius server, RSA can also be used with other software sets, and other servers can be used as a Radius server.
The general process of radius verification is as follows:
The main Code implemented in java is as follows (the radius jar package must be imported, mainly radiusclient3.jar ):
① For the first verification of radius, the four parameters of RADIUSClient are the server ip address, port, and Radius keys respectively, and the radius input timeout time. the username and password of authenticate are the users to be verified.
1 RADIUSClient r = null;2 int nResult = 0; r = new RADIUSClient("ip", port , "secret" , radius_soctet_timeout);3 r.setDebug(true);4 AttributeList aList = new AttributeList();5 aList.addAttribute(Attribute.NAS_Port, 1);6 nResult = r.authenticate(username, password, aList);
② Judge with the returned nResult. The number 3 in the Code represents access_reject, the number 0 represents access_badpacket, the number 11 represents access_challenge, And the number 2 represents access_accept.
In the case of access_challenge, there are two situations: one is that the new pin (new pin is more complex) and the other is the next token. in addition, this Attribute. the State property is always inherited to distinguish
Whether it is the verification we need (for example, Code 25 or 26 lines, the state is taken into the next verification for verification and recognition ).
1 switch (nResult) { 2 case 3: 3 try{ 4 AttributeList response = r.getAttributes(); 5 AttributeList state = response.getAttributeList(Attribute.State); 6 } 7 catch(Exception e){ 8 9 }10 11 break;12 case 0:13 14 break;15 case 11:16 AttributeList response = r.getAttributes();17 AttributeList state = response.getAttributeList(Attribute.State);18 r.reset();19 System.out.println(":");20 Scanner sa = new Scanner(System.in);21 String sl = sa.next();22 String mima = sl + ""; 23 AttributeList attList = new AttributeList();24 attList.addAttribute(Attribute.NAS_Port, 1);25 attList.mergeAttributes(state);26 nResult = r.authenticate(username, mima, attList);27 System.out.println(r.getPacketType());28 System.out.println("r.getErrorString():" + r.getErrorString());29 System.out.println("Second nResult:" + nResult);30 if(nResult == 11){31 AttributeList rresponse = r.getAttributes();32 AttributeList sstate = rresponse.getAttributeList(Attribute.State); 33 r.reset();34 System.out.println("re new pins");35 Scanner ssa = new Scanner(System.in);36 String ssl = ssa.next();37 String renewpin = ssl + "";38 System.out.println(renewpin);39 AttributeList aattList = new AttributeList();40 aattList.addAttribute(Attribute.NAS_Port, 1);41 aattList.mergeAttributes(sstate);42 nResult = r.authenticate(username, renewpin, aattList);43 System.out.println(r.getPacketType());44 System.out.println("r.getErrorString():" + r.getErrorString());4546 if (nResult == 11){47 AttributeList rrresponse = r.getAttributes();48 AttributeList ssstate = rrresponse.getAttributeList(Attribute.State);49 r.reset();50 System.out.println("posscode");51 Scanner ressa = new Scanner(System.in);52 String ressl = ressa.next();53 String passcode = ressl + "";54 AttributeList reaattList = new AttributeList();55 reaattList.addAttribute(Attribute.NAS_Port, 1);56 nResult = r.authenticate(username, passcode, reaattList);57 System.out.println(r.getPacketType());58 System.out.println("r.getErrorString():" + r.getErrorString());59 System.out.println("nResult:" + nResult);60 if (nResult == 2){61 return "AUTH SUCCESS";62 }63 }64 }65 if (nResult == 2){66 return "AUTH SUCCESS";67 }68 case 2:69 70 return "AUTH SUCCESS";71 default:72 73 break;74 }75 return "AUTH FAILURE";