//Authenticates user BooleanResult IPluginAuthentication.AuthenticateUser(SessionProperties properties) { m_logger.DebugFormat("AuthenticateUser({0})", properties.Id.ToString()); // Get user info UserInformation userInfo = properties.GetTrackedSingle <UserInformation>(); try { RADIUSClient client = GetClient(null); //No session ID is required for auth, only accounting bool result = client.Authenticate(userInfo.Username, userInfo.Password); if (result) { return new BooleanResult() { Success = result } } ; return(new BooleanResult() { Success = result, Message = "Invalid username or password." }); } catch (RADIUSException re) { m_logger.Error("An error occurred during while authenticating.", re); return(new BooleanResult() { Success = false, Message = re.Message }); } catch (Exception e) { m_logger.Error("An unexpected error occurred while authenticating.", e); throw e; } }
//Authenticates user BooleanResult IPluginAuthentication.AuthenticateUser(SessionProperties properties) { m_logger.DebugFormat("AuthenticateUser({0})", properties.Id.ToString()); if (!(bool)Settings.Store.EnableAuth) { m_logger.Debug("Authentication stage set on RADIUS plugin but authentication is not enabled in plugin settings."); return(new BooleanResult() { Success = false }); } // Get user info UserInformation userInfo = properties.GetTrackedSingle <UserInformation>(); if (String.IsNullOrEmpty(userInfo.Username) || String.IsNullOrEmpty(userInfo.Password)) { return new BooleanResult() { Success = false, Message = "Username and password must be provided." } } ; try { RADIUSClient client = GetClient(); bool result = client.Authenticate(userInfo.Username, userInfo.Password); if (result) { Session session = new Session(properties.Id, userInfo.Username, client); Packet p = client.lastReceievedPacket; //Check for session timeout if ((bool)Settings.Store.AllowSessionTimeout && p.containsAttribute(Packet.AttributeType.Session_Timeout)) { int seconds = client.lastReceievedPacket.getFirstIntAttribute(Packet.AttributeType.Session_Timeout); session.SetSessionTimeout(seconds, SessionTimeoutCallback); //m_logger.DebugFormat("Setting timeout for {0} to {1} seconds.", userInfo.Username, seconds); } if (p.containsAttribute(Packet.AttributeType.Idle_Timeout)) { int seconds = client.lastReceievedPacket.getFirstIntAttribute(Packet.AttributeType.Idle_Timeout); } if (p.containsAttribute(Packet.AttributeType.Vendor_Specific)) { foreach (byte[] val in p.getByteArrayAttributes(Packet.AttributeType.Vendor_Specific)) { //m_logger.DebugFormat("Vendor ID: {0:D}, Type: {1:D}, Value: {2}", Packet.VSA_vendorID(val), Packet.VSA_VendorType(val), Packet.VSA_valueAsString(val)); if ((bool)Settings.Store.WisprSessionTerminate && Packet.VSA_vendorID(val) == (int)Packet.VSA_WISPr.Vendor_ID && Packet.VSA_VendorType(val) == (int)Packet.VSA_WISPr.WISPr_Session_Terminate_Time) { try { //Value is in format "2014-03-11T23:59:59" string sdt = Packet.VSA_valueAsString(val); DateTime dt = DateTime.ParseExact(sdt, "yyyy-MM-dd'T'HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); if (dt > DateTime.Now) { session.Set_Session_Terminate(dt, SessionTerminateCallback); } else { m_logger.DebugFormat("The timestamp provided for WisperSessionTerminate time value has passed."); } } catch (FormatException e) { m_logger.DebugFormat("Unable to parse timestamp: {0}", Packet.VSA_valueAsString(val)); } } } } //Check for interim-update if ((bool)Settings.Store.SendInterimUpdates) { int seconds = 0; if (p.containsAttribute(Packet.AttributeType.Acct_Interim_Interval)) { seconds = client.lastReceievedPacket.getFirstIntAttribute(Packet.AttributeType.Acct_Interim_Interval); } //Check to see if plugin is set to send interim updates more frequently if ((bool)Settings.Store.ForceInterimUpdates) { int forceTime = (int)Settings.Store.InterimUpdateTime; if (forceTime > 0) { seconds = forceTime; } } //Set interim update if (seconds > 0) { session.SetInterimUpdate(seconds, InterimUpdatesCallback); m_logger.DebugFormat("Setting interim update interval for {0} to {1} seconds.", userInfo.Username, seconds); } else { m_logger.DebugFormat("Interim Updates are enabled, but no update interval was provided by the server or user."); } } lock (m_sessionManager) { //m_logger.DebugFormat("Adding session to m_sessionManager. ID: {0}, session: {1}", session.id, session); m_sessionManager.Add(session.id, session); } string message = null; if (p.containsAttribute(Packet.AttributeType.Reply_Message)) { message = p.getFirstStringAttribute(Packet.AttributeType.Reply_Message); } return(new BooleanResult() { Success = result, Message = message }); } //Failure string msg = "Unable to validate username or password."; if (client.lastReceievedPacket == null) { msg = msg + " No response from server."; } else if (client.lastReceievedPacket.containsAttribute(Packet.AttributeType.Reply_Message)) { msg = client.lastReceievedPacket.getFirstStringAttribute(Packet.AttributeType.Reply_Message); } else if (client.lastReceievedPacket.code == Packet.Code.Access_Reject) { msg = msg + String.Format(" Access Rejected."); } return(new BooleanResult() { Success = result, Message = msg }); } catch (RADIUSException re) { m_logger.Error("An error occurred during while authenticating.", re); return(new BooleanResult() { Success = false, Message = re.Message }); } catch (Exception e) { m_logger.Error("An unexpected error occurred while authenticating.", e); throw e; } }