Class JXLoginPane

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, AlphaPaintable, BackgroundPaintable

@JavaBean public class JXLoginPane extends JXPanel

JXLoginPane is a specialized JPanel that implements a Login dialog with support for saving passwords supplied for future use in a secure manner. LoginService is invoked to perform authentication and optional PasswordStore can be provided to store the user login information.

In order to perform the authentication, JXLoginPane calls the authenticate method of the LoginService . In order to perform the persistence of the password, JXLoginPane calls the put method of the PasswordStore object that is supplied. If the PasswordStore is null, then the password is not saved. Similarly, if a PasswordStore is supplied and the password is null, then the PasswordStore will be queried for the password using the get method. Example:

         final JXLoginPane panel = new JXLoginPane(new LoginService() {
                      public boolean authenticate(String name, char[] password,
                                      String server) throws Exception {
                              // perform authentication and return true on success.
                              return false;
                      }});
      final JFrame frame = JXLoginPane.showLoginFrame(panel);
 
See Also:
  • Field Details

    • LOG

      private static final Logger LOG
      The Logger
    • serialVersionUID

      private static final long serialVersionUID
      Comment for serialVersionUID
      See Also:
    • uiClassID

      public static final String uiClassID
      UI Class ID
      See Also:
    • LOGIN_ACTION_COMMAND

      public static final String LOGIN_ACTION_COMMAND
      Action key for an Action in the ActionMap that initiates the Login procedure
      See Also:
    • CANCEL_LOGIN_ACTION_COMMAND

      public static final String CANCEL_LOGIN_ACTION_COMMAND
      Action key for an Action in the ActionMap that cancels the Login procedure
      See Also:
    • CLASS_NAME

      private static String CLASS_NAME
      Used as a prefix when pulling data out of UIManager for i18n
    • status

      private JXLoginPane.Status status
      The current login status for this panel
    • bannerText

      private String bannerText
      Text that should appear on the banner
    • messageLabel

      private JLabel messageLabel
      Custom label allowing the developer to display some message to the user
    • errorMessageLabel

      private JXLabel errorMessageLabel
      Shows an error message such as "user name or password incorrect" or "could not contact server" or something like that if something goes wrong
    • loginPanel

      private JXPanel loginPanel
      A Panel containing all of the input fields, check boxes, etc necessary for the user to do their job. The items on this panel change whenever the SaveMode changes, so this panel must be recreated at runtime if the SaveMode changes. Thus, I must maintain this reference so I can remove this panel from the content panel at runtime.
    • contentPanel

      private JXPanel contentPanel
      The panel on which the input fields, messageLabel, and errorMessageLabel are placed. While the login thread is running, this panel is removed from the dialog and replaced by the progressPanel
    • namePanel

      private JXLoginPane.NameComponent namePanel
      This is the area in which the name field is placed. That way it can toggle on the fly between text field and a combo box depending on the situation, and have a simple way to get the user name
    • passwordField

      private JPasswordField passwordField
      The password field presented allowing the user to enter their password
    • serverCombo

      private JComboBox serverCombo
      A combo box presenting the user with a list of servers to which they may log in. This is an optional feature, which is only enabled if the List of servers supplied to the JXLoginPane has a length greater than 1.
    • saveCB

      private JCheckBox saveCB
      Check box presented if a PasswordStore is used, allowing the user to decide whether to save their password
    • capsOn

      private JLabel capsOn
      Label displayed whenever caps lock is on.
    • progressPanel

      private JXPanel progressPanel
      A special panel that displays a progress bar and cancel button, and which notify the user of the login process, and allow them to cancel that process.
    • progressMessageLabel

      private JLabel progressMessageLabel
      A JLabel on the progressPanel that is used for informing the user of the status of the login procedure (logging in..., canceling login...)
    • loginService

      private LoginService loginService
      The LoginService to use. This must be specified for the login dialog to operate. If no LoginService is defined, a default login service is used that simply allows all users access. This is useful for demos or prototypes where a proper login server is not available.
    • passwordStore

      private PasswordStore passwordStore
      Optional: a PasswordStore to use for storing and retrieving passwords for a specific user.
    • userNameStore

      private UserNameStore userNameStore
      Optional: a UserNameStore to use for storing user names and retrieving them
    • servers

      private List<String> servers
      A list of servers where each server is represented by a String. If the list of Servers is greater than 1, then a combo box will be presented to the user to choose from. If any servers are specified, the selected one (or the only one if servers.size() == 1) will be passed to the LoginService
    • saveMode

      private JXLoginPane.SaveMode saveMode
      Whether to save password or username or both.
    • oldCursor

      private Cursor oldCursor
      Tracks the cursor at the time that authentication was started, and restores to that cursor after authentication ends, or is canceled;
    • namePanelEnabled

      private boolean namePanelEnabled
    • defaultLoginListener

      private LoginListener defaultLoginListener
      The default login listener used by this panel.
    • buttonPanel

      private JXLoginPane.JXBtnPanel buttonPanel
      Login/cancel control pane;
    • contentCardPane

      private JPanel contentCardPane
      Card pane holding user/pwd fields view and the progress view.
    • isErrorMessageSet

      private boolean isErrorMessageSet
  • Constructor Details

    • JXLoginPane

      public JXLoginPane()
      Create a JXLoginPane that always accepts the user, never stores passwords or user ids, and has no target servers.

      This constructor should NOT be used in a real application. It is provided for compliance to the bean specification and for use with visual editors.

    • JXLoginPane

      public JXLoginPane(LoginService service)
      Create a JXLoginPane with the specified LoginService that does not store user ids or passwords and has no target servers.
      Parameters:
      service - the LoginService to use for logging in
    • JXLoginPane

      public JXLoginPane(LoginService service, PasswordStore passwordStore, UserNameStore userStore)
      Create a JXLoginPane with the specified LoginService, PasswordStore, and UserNameStore, but without a server list.

      If you do not want to store passwords or user ids, those parameters can be null. SaveMode is autoconfigured from passed in store parameters.

      Parameters:
      service - the LoginService to use for logging in
      passwordStore - the PasswordStore to use for storing password information
      userStore - the UserNameStore to use for storing user information
    • JXLoginPane

      public JXLoginPane(LoginService service, PasswordStore passwordStore, UserNameStore userStore, List<String> servers)
      Create a JXLoginPane with the specified LoginService, PasswordStore, UserNameStore, and server list.

      If you do not want to store passwords or user ids, those parameters can be null. SaveMode is autoconfigured from passed in store parameters.

      Setting the server list to null will unset all of the servers. The server list is guaranteed to be non-null.

      Parameters:
      service - the LoginService to use for logging in
      passwordStore - the PasswordStore to use for storing password information
      userStore - the UserNameStore to use for storing user information
      servers - a list of servers to authenticate against
  • Method Details

    • reinitLocales

      private void reinitLocales(Locale l)
      Populates UIDefaults with the localizable Strings we will use in the Login panel.
    • isCapsLockOn

      public boolean isCapsLockOn()
      Gets current state of the caps lock as seen by the login panel. The state seen by the login panel and therefore returned by this method can be delayed in comparison to the real caps lock state and displayed by the keyboard light. This is usually the case when component or its text fields are not focused.
      Returns:
      True when caps lock is on, false otherwise. Returns always false when isCapsLockDetectionSupported() returns false.
    • getUI

      public LoginPaneUI getUI()
      Overrides:
      getUI in class JPanel
    • setUI

      public void setUI(LoginPaneUI ui)
      Sets the look and feel (Linvalid input: '&F') object that renders this component.
      Parameters:
      ui - the LoginPaneUI Linvalid input: '&F' object
      See Also:
    • updateUI

      public void updateUI()
      Notification from the UIManager that the Linvalid input: '&F' has changed. Replaces the current UI object with the latest version from the UIManager.
      Overrides:
      updateUI in class JPanel
      See Also:
    • getUIClassID

      public String getUIClassID()
      Returns the name of the Linvalid input: '&F' class that renders this component.
      Overrides:
      getUIClassID in class JPanel
      Returns:
      the string uiClassID
      See Also:
    • recreateLoginPanel

      protected void recreateLoginPanel()
      Recreates the login panel, and replaces the current one with the new one
    • createLoginPanel

      private JXPanel createLoginPanel()
      Creates and returns a new LoginPanel, based on the SaveMode state of the login panel. Whenever the SaveMode changes, the panel is recreated. I do this rather than hiding/showing components, due to a cleaner implementation (no invisible components, components are not sharing locations in the LayoutManager, etc).
    • setComponentOrientation

      public void setComponentOrientation(ComponentOrientation orient)
      This method adds functionality to support bidi languages within this component
      Overrides:
      setComponentOrientation in class Component
    • initComponents

      private void initComponents()
      Create all of the UI components for the login panel
    • createLoginBanner

      protected Image createLoginBanner()
      Create and return an image to use for the Banner. This may be overridden to return any image you like
    • createLoginAction

      protected Action createLoginAction()
      Create and return an Action for logging in
    • createCancelAction

      protected Action createCancelAction()
      Create and return an Action for canceling login
    • getSaveMode

      public JXLoginPane.SaveMode getSaveMode()
      Returns:
      Returns the saveMode.
    • setSaveMode

      public void setSaveMode(JXLoginPane.SaveMode saveMode)
      The save mode indicates whether the "save" password is checked by default. This method makes no difference if the passwordStore is null.
      Parameters:
      saveMode - The saveMode to set either SAVE_NONE, SAVE_PASSWORD or SAVE_USERNAME
    • isRememberPassword

      public boolean isRememberPassword()
    • getServers

      public List<String> getServers()
      Returns:
      the List of servers
    • setServers

      public void setServers(List<String> servers)
      Sets the list of servers. See the servers field javadoc for more info.
    • getDefaultLoginListener

      private LoginListener getDefaultLoginListener()
    • setLoginService

      public void setLoginService(LoginService service)
      Sets the LoginService for this panel. Setting the login service to null will actually set the service to use NullLoginService.
      Parameters:
      service - the service to set. If service == null, then a NullLoginService is used.
    • getLoginService

      public LoginService getLoginService()
      Gets the LoginService for this panel.
      Returns:
      service service
    • setPasswordStore

      public void setPasswordStore(PasswordStore store)
      Sets the PasswordStore for this panel.
      Parameters:
      store - PasswordStore
    • getUserNameStore

      public UserNameStore getUserNameStore()
      Gets the UserNameStore for this panel.
      Returns:
      the UserNameStore
    • setUserNameStore

      public void setUserNameStore(UserNameStore store)
      Sets the user name store for this panel.
      Parameters:
      store -
    • getPasswordStore

      public PasswordStore getPasswordStore()
      Gets the PasswordStore for this panel.
      Returns:
      store PasswordStore
    • setUserName

      public void setUserName(String username)
      Sets the User name for this panel.
      Parameters:
      username - User name
    • setUserNameEnabled

      public void setUserNameEnabled(boolean enabled)
      Enables or disables User name for this panel.
      Parameters:
      enabled -
    • isUserNameEnabled

      public boolean isUserNameEnabled()
      Gets current state of the user name field. Field can be either disabled (false) for editing or enabled (true).
      Returns:
      True when user name field is enabled and editable, false otherwise.
    • getUserName

      public String getUserName()
      Gets the User name for this panel.
      Returns:
      the user name
    • setPassword

      public void setPassword(char[] password)
      Sets the Password for this panel.
      Parameters:
      password - Password
    • getPassword

      public char[] getPassword()
      Gets the Password for this panel.
      Returns:
      password Password
    • getBanner

      public Image getBanner()
      Return the image used as the banner
    • setBanner

      public void setBanner(Image img)
      Set the image to use for the banner. If the img is null, then no image will be displayed.
      Parameters:
      img - the image to display
    • setBannerText

      public void setBannerText(String text)
      Set the text to use when creating the banner. If a custom banner image is specified, then this is ignored. If text is null, then no text is displayed.
      Parameters:
      text - the text to display
    • getBannerText

      public String getBannerText()
      Returns text used when creating the banner
    • getMessage

      public String getMessage()
      Returns the custom message for this login panel
    • setMessage

      public void setMessage(String message)
      Sets a custom message for this login panel
    • getErrorMessage

      public String getErrorMessage()
      Returns the error message for this login panel
    • setErrorMessage

      public void setErrorMessage(String errorMessage)
      Sets the error message for this login panel
    • getStatus

      public JXLoginPane.Status getStatus()
      Returns the panel's status
    • setStatus

      protected void setStatus(JXLoginPane.Status newStatus)
      Change the status
    • setLocale

      public void setLocale(Locale l)
      Overrides:
      setLocale in class Component
    • startLogin

      protected void startLogin()
      Initiates the login procedure. This method is called internally by the LoginAction. This method handles cursor management, and actually calling the LoginService's startAuthentication method. Method will return immediately if asynchronous login is enabled or will block until authentication finishes if getSynchronous() returns true.
    • cancelLogin

      protected void cancelLogin()
      Cancels the login procedure. Handles cursor management and interfacing with the LoginService's cancelAuthentication method. Calling this method has an effect only when authentication is still in progress (i.e. after previous call to startAuthentications() and only when authentication is performed asynchronously (getSynchronous() returns false).
    • savePassword

      protected void savePassword()
      Puts the password into the password store. If password store is not set, method will do nothing.
    • updatePassword

      private void updatePassword(String username)
    • showLoginDialog

      public static JXLoginPane.Status showLoginDialog(Component parent, LoginService svc)
      Shows a login dialog. This method blocks.
      Returns:
      The status of the login operation
    • showLoginDialog

      public static JXLoginPane.Status showLoginDialog(Component parent, LoginService svc, PasswordStore ps, UserNameStore us)
      Shows a login dialog. This method blocks.
      Returns:
      The status of the login operation
    • showLoginDialog

      public static JXLoginPane.Status showLoginDialog(Component parent, LoginService svc, PasswordStore ps, UserNameStore us, List<String> servers)
      Shows a login dialog. This method blocks.
      Returns:
      The status of the login operation
    • showLoginDialog

      public static JXLoginPane.Status showLoginDialog(Component parent, JXLoginPane panel)
      Shows a login dialog. This method blocks.
      Returns:
      The status of the login operation
    • showLoginFrame

      public static JXLoginPane.JXLoginFrame showLoginFrame(LoginService svc)
      Shows a login frame. A JFrame is not modal, and thus does not block
    • showLoginFrame

      public static JXLoginPane.JXLoginFrame showLoginFrame(LoginService svc, PasswordStore ps, UserNameStore us)
    • showLoginFrame

      public static JXLoginPane.JXLoginFrame showLoginFrame(LoginService svc, PasswordStore ps, UserNameStore us, List<String> servers)
    • showLoginFrame

      public static JXLoginPane.JXLoginFrame showLoginFrame(JXLoginPane panel)
    • initWindow

      static void initWindow(Window w, JXLoginPane panel)
      Utility method for initializing a Window for displaying a LoginDialog. This is particularly useful because the differences between JFrame and JDialog are so minor. Note: This method is package private for use by JXLoginDialog (proper, not JXLoginPane.JXLoginDialog). Change to private if JXLoginDialog is removed.
    • setButtonPanel

      private void setButtonPanel(JXLoginPane.JXBtnPanel buttonPanel)