package com.theorem.radserver3.examples.server; import com.theorem.radserver3.*; import com.theorem.radserver3.radutil.*; import com.theorem.misc.*; import java.util.*; /** * Proxy implementation example of using the ProxyInfo methods to send a client * response instead of forwarding a packet. * * This might be required if a server is temporarily unavailable a reply can be processed. * In this example accounting responses will be generated that give free usage to the client. */ public class ProxyFreeUsage extends ProxyImpl { // Logs. LogImpl dbg, svr; // External configuration information. Configure conf; /** * Constructor. * @param conf Configuration object. */ public ProxyFreeUsage(Configure conf) { this.conf = conf; } /** * Intialize the logs for this class. * * @param svrLog Server log object. * @param dbgLog Debug log object. */ public void logs(LogImpl svrLog, LogImpl dbgLog) { dbg = dbgLog; svr = svrLog; } /** * Change a request's proxy information. * * @param prx ProxyInfo object from server. */ public void changeRequest(ProxyInfo prx) throws AccessDropException, AccessRejectException { // If the target realm is 'andromeda' and this is an accounting Start request // don't send the request. All other requests are permitted to pass through normally. String realm =prx.getRealm(); if (realm.equals("andromeda")) { // Only process accounting requests. if (prx.getRequestType() == PacketType.Accounting_Request) { // See if it's a start packet. AttributeList requestList = prx.getRequestAttributeList(); Attribute a[] = requestList.getAttributeArray(Attribute.Acct_Status_Type); if (a.length > 0 && a[0].getInt() == AV.Acct_Status_Type.Start) { // Send a response back to the original client. AttributeList list = new AttributeList(); list.addAttribute(Attribute.Reply_Message, "Your access to Andromeda is free!"); try { prx.sendClientResponse(PacketType.Accounting_Response, list); } catch (Exception e) { throw new AccessDropException("Unable to send accounting response to client: " + e.getMessage()); } // Drop the packet that was to be forwarded. throw new AccessDropException("Dropping accounting start packet. - Free for Andromeda"); } } } } /** * Change proxy response routing. * * @param prx ProxyInfo object from server. */ public void changeResponse(ProxyInfo prx) throws AccessDropException, AccessRejectException { // Does nothing. } }