I'm using TinyRadius in a Java EE application and in this application simultaneous access of the same user can not be allowed, but the same TinyRadius does not implement such a requirement.
I thought of ways to prevent this:
- If the user authenticates successfully, register this access in a database. When the user shifts, remove this record
- If the user successfully authenticates, add this user to a
List
. When the user shifts, remove it fromList
But what if the Radius client does not report for any reason (disconnection or other problem) that the user disconnected? In previous solutions the user would get lost in List
or in the Database and the next authentication would not be allowed.
How can I circumvent this situation?
Here's an implementation of RadiusServer
public class TestServer {
public static void main(String[] args)
throws IOException, Exception {
RadiusServer server = new RadiusServer() {
// Authorize localhost/testing123
@Override
public String getSharedSecret(InetSocketAddress client) {
//if (client.getAddress().getHostAddress().equals("0.0.0.0"))
return "1234";
//else
// return null;
}
// Authenticate mw
public String getUserPassword(String userName) {
System.out.println("Requisitando password... //////////////////////////////////////////////////////////////////////////////////////");
if (userName.equals("gtragoso"))
return "gtragoso";
else
return null;
}
// Adds an attribute to the Access-Accept packet
@Override
public RadiusPacket accessRequestReceived(AccessRequest accessRequest, InetSocketAddress client)
throws RadiusException {
System.out.println("Received Access-Request:\n" + accessRequest);
RadiusPacket packet = super.accessRequestReceived(accessRequest, client);
if (packet.getPacketType() == RadiusPacket.ACCESS_ACCEPT){
System.out.println("Definindo banda... ///////////////////////////////////////////////////////////////////////////////////");
packet.addAttribute("WISPr-Bandwidth-Max-Down", "256000");
packet.addAttribute("WISPr-Bandwidth-Max-Up", "32000");
packet.addAttribute("Reply-Message", "Welcome " + accessRequest.getUserName() + "!");
}
if (packet == null)
System.out.println("Ignore packet.");
else
System.out.println("Answer:\n" + packet);
return packet;
}
public RadiusPacket accountingRequestReceived(AccountingRequest accountingRequest, InetSocketAddress client)
throws RadiusException {
RadiusPacket answer = new RadiusPacket(RadiusPacket.ACCOUNTING_RESPONSE, accountingRequest.getPacketIdentifier());
copyProxyState(accountingRequest, answer);
return answer;
}
};
server.setAuthPort(1645);
server.setAcctPort(1646);
server.start(true, true);
System.out.println("Server started.");
Thread.sleep(1000*60*30);
System.out.println("Stop server");
server.stop();
}