Class SocketServer

  • All Implemented Interfaces:
    java.lang.Runnable

    final class SocketServer
    extends java.lang.Object
    implements java.lang.Runnable
    this class is used to receive incoming connections for the telnet UI and then authenticate and create a console session for the connection
    • Constructor Summary

      Constructors 
      Constructor Description
      SocketServer​(UI ui, int port, java.util.Set allowedHosts, UserManager userManager, int maxLoginAttempts)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean checkHost​(java.lang.String hostName)
      compare the specified host (might be a hostname or an IP - dont really care) and see if it is a match against one of the allowed hosts
      private boolean isAllowed​(java.net.InetSocketAddress addr)
      check that the specified host/ip is allowed
      private UserProfile login​(java.io.InputStream in, java.io.OutputStream out)
      if usermanager is null (ie: multi user is not enabled), returns the default user profile otherwise, requests username and password and authenticates user before returning the user profile for this user
      void run()
      start up the server socket and when a new connection is received, check that the source address is in our permitted list and if so, start a new console input on that socket.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • serverSocket

        private final java.net.ServerSocket serverSocket
      • allowedHosts

        private final java.util.Set allowedHosts
      • maxLoginAttempts

        private final int maxLoginAttempts
      • ui

        private final UI ui
    • Constructor Detail

      • SocketServer

        public SocketServer​(UI ui,
                            int port,
                            java.util.Set allowedHosts,
                            UserManager userManager,
                            int maxLoginAttempts)
                     throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • run

        public void run()
        start up the server socket and when a new connection is received, check that the source address is in our permitted list and if so, start a new console input on that socket.
        Specified by:
        run in interface java.lang.Runnable
      • login

        private UserProfile login​(java.io.InputStream in,
                                  java.io.OutputStream out)
                           throws java.io.IOException
        if usermanager is null (ie: multi user is not enabled), returns the default user profile otherwise, requests username and password and authenticates user before returning the user profile for this user
        Parameters:
        in - input stream to read from
        out - stream to write messages to
        Returns:
        username if login was successful, null otherwise
        Throws:
        java.io.IOException
      • isAllowed

        private boolean isAllowed​(java.net.InetSocketAddress addr)
        check that the specified host/ip is allowed
        Parameters:
        addr -
        Returns:
      • checkHost

        private boolean checkHost​(java.lang.String hostName)
        compare the specified host (might be a hostname or an IP - dont really care) and see if it is a match against one of the allowed hosts
        Parameters:
        hostName -
        Returns:
        true if this hostname matches one in our allowed hosts