Class SessionManager

java.lang.Object
org.metricshub.ipmi.core.connection.SessionManager

public class SessionManager extends Object
Manages multiple Sessions.
  • Constructor Details

    • SessionManager

      public SessionManager()
  • Method Details

    • generateSessionId

      public static int generateSessionId()
      Generates the console session ID of a new session.
      Returns:
      a session ID between 1 and Integer.MAX_VALUE / 4 (never 0, the ID of session-less messages), different from the previous ones
    • establishSession

      public static Session establishSession(IpmiConnector connector, String remoteHost, int remotePort, String user, String password, CipherSuiteSelectionHandler cipherSuiteSelectionHandler) throws SessionException
      Opens a new connection and session, at the Administrator privilege level, raised to it right after the login.
      Parameters:
      connector - the connector of the connection
      remoteHost - the address of the BMC
      remotePort - the UDP port of the BMC
      user - the user name
      password - the password, sent in UTF-8
      cipherSuiteSelectionHandler - chooses the cipher suite among those the BMC offers
      Returns:
      the new session
      Throws:
      SessionException - when the session cannot be opened, or the account is not allowed the Administrator privilege
    • establishSession

      public static Session establishSession(IpmiConnector connector, String remoteHost, int remotePort, String user, byte[] password, byte[] bmcKey, CipherSuiteSelectionHandler cipherSuiteSelectionHandler) throws SessionException
      Opens a new connection and session, at the Administrator privilege level, raised to it right after the login.
      Parameters:
      connector - the connector of the connection
      remoteHost - the address of the BMC
      remotePort - the UDP port of the BMC
      user - the user name
      password - the password, as sent to the BMC
      bmcKey - the BMC key (Kg) for a two-key login, or null
      cipherSuiteSelectionHandler - chooses the cipher suite among those the BMC offers
      Returns:
      the new session
      Throws:
      SessionException - when the session cannot be opened, or the account is not allowed the Administrator privilege
    • establishSession

      public static Session establishSession(IpmiConnector connector, ConnectionHandle connectionHandle, int remotePort) throws SessionException
      Opens a new connection and session on another UDP port of the BMC of the given connection (the port of a payload, IPMI 2.0 section 24.1), with its user name, password, BMC key and privilege level, and a copy of its cipher suite: opening the session keys the algorithms of its suite.
      Parameters:
      connector - the connector of the connection
      connectionHandle - the connection whose credentials, cipher suite and privilege level the session takes
      remotePort - the UDP port of the BMC
      Returns:
      the new session
      Throws:
      SessionException - when the session cannot be opened, or the account is not allowed the privilege level
    • registerSession

      public Session registerSession(int newSessionId, ConnectionHandle connectionHandle)
      Either returns the Session registered for given connection, or creates new IPMI Session and registers it for the given connection handle, if no session was found for the connection.
      Parameters:
      connectionHandle - handle of the connection, for which this session should be registered.
      Returns:
      newly created session object or session already registered for the connection
    • registerSession

      public Session registerSession(int newSessionId, int managedSystemSessionId, ConnectionHandle connectionHandle)
      Either returns the Session registered for given connection, or creates new IPMI Session and registers it for the given connection handle, if no session was found for the connection.
      Parameters:
      newSessionId - the remote console session ID of the new session
      managedSystemSessionId - the managed system session ID of the new session, which the BMC generated
      connectionHandle - handle of the connection, for which this session should be registered.
      Returns:
      newly created session object or session already registered for the connection
    • unregisterSession

      public void unregisterSession(ConnectionHandle connectionHandle)
      Unregisters session for given connection handle, and wipes the credentials of the handle it was registered with.
      Parameters:
      connectionHandle - handle of the connection, for which the session should be unregistered.
    • wipeCredentials

      public void wipeCredentials()
      Wipes the credentials of the connections of all the registered sessions, when their connector tears down without closing each connection.
    • getSessionForCriteria

      public Session getSessionForCriteria(InetAddress remoteAddress, int remotePort, String user)
      Returns session already bound to given connection handle fulfilling given criteria.
      Parameters:
      remoteAddress - IP addres of the managed system
      remotePort - UDP port of the managed system
      user - IPMI user for whom the connection is established
      Returns:
      session object fulfilling given criteria, or null if no session was registered for such connection.