/** * Radius command line client. * <br/>Usage: TestClient <i>hostName sharedSecret userName password</i> * @param args arguments * @throws Exception */ public static void main(String[] args) { if (args.Length != 4) { System.Console.WriteLine("Usage: TestClient hostName sharedSecret userName password"); return; } String host = args[0]; String shared = args[1]; String user = args[2]; String pass = args[3]; var rc = new RadiusClient(IPAddress.Parse(host), shared); // 1. Send Access-Request var ar = new AccessRequest(user, pass); ar.AuthProtocol = AuthenticationType.pap; // or AUTH_CHAP 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-Redirection-URL", "http://www.sourceforge.net/"); ar.AddAttribute("WISPr-Location-ID", "net.sourceforge.ap1"); System.Console.WriteLine("Packet before it is sent\n" + ar + "\n"); RadiusPacket response = rc.Authenticate(ar); System.Console.WriteLine("Packet after it was sent\n" + ar + "\n"); System.Console.WriteLine("Response\n" + response + "\n"); // 2. Send Accounting-Request var acc = new AccountingRequest("mw", AccountingRequest.ACCT_STATUS_TYPE_START); acc.AddAttribute("Acct-Session-Id", "1234567890"); acc.AddAttribute("NAS-Identifier", "this.is.my.nas-identifier.de"); acc.AddAttribute("NAS-Port", "0"); System.Console.WriteLine(acc + "\n"); response = rc.Account(acc); System.Console.WriteLine("Response: " + response); rc.Close(); }
/// <summary> /// Creates a RadiusPacket object. Depending on the passed type, the /// appropiate successor is chosen. Sets the type, but does not touch /// the packet identifier. /// @param type packet type /// @return RadiusPacket object /// </summary> public static RadiusPacket CreateRadiusPacket(int type) { RadiusPacket rp; switch (type) { case AccessRequest: rp = new AccessRequest(); break; case AccountingRequest: rp = new AccountingRequest(); break; case AccessAccept: case AccessReject: case AccountingResponse: default: rp = new RadiusPacket(); break; } rp.Type = type; return(rp); }
/// <summary> /// Constructs an answer for an Accounting-Request packet. This method /// should be overriden if accounting is supported. /// @param accountingRequest Radius request packet /// @param client address of Radius client /// @return response packet or null if no packet shall be sent /// @exception RadiusException malformed request packet; if this /// exception is thrown, no answer will be sent /// </summary> public RadiusPacket AccountingRequestReceived(AccountingRequest accountingRequest, IPEndPoint client) { var answer = new RadiusPacket(RadiusPacket.AccountingResponse, accountingRequest.Identifier); CopyProxyState(accountingRequest, answer); return answer; }
/// <summary> /// Creates a RadiusPacket object. Depending on the passed type, the /// appropiate successor is chosen. Sets the type, but does not touch /// the packet identifier. /// @param type packet type /// @return RadiusPacket object /// </summary> public static RadiusPacket CreateRadiusPacket(int type) { RadiusPacket rp; switch (type) { case AccessRequest: rp = new AccessRequest(); break; case AccountingRequest: rp = new AccountingRequest(); break; case AccessAccept: case AccessReject: case AccountingResponse: default: rp = new RadiusPacket(); break; } rp.Type = type; return rp; }
/** * Sends an Accounting-Request packet and receives a response * packet. * @param request request packet * @return Radius response packet * @exception RadiusException malformed packet * @exception IOException communication error (after getRetryCount() * retries) */ public RadiusPacket Account(AccountingRequest request) { lock (this) { if (logger.IsInfoEnabled) logger.Info("send Accounting-Request packet: " + request); RadiusPacket response = Communicate(request, AcctPort); if (logger.IsInfoEnabled) logger.Info("received packet: " + response); return response; } }