Class JXLoginPane

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable

    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:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  JXLoginPane.CapsOnWinListener
      Window event listener to invoke capslock test when login panel get activated.
      static class  JXLoginPane.ComboNamePanel
      If a UserNameStore is used, then this combo box is presented allowing the user to select a previous login name, or type in a new login name
      static class  JXLoginPane.JXLoginDialog  
      static class  JXLoginPane.JXLoginFrame  
      protected class  JXLoginPane.LoginListenerImpl
      Listener class to track state in the LoginService
      static interface  JXLoginPane.NameComponent  
      class  JXLoginPane.RemovableKeyEventDispatcher  
      static class  JXLoginPane.SaveMode
      The JXLoginPane can attempt to save certain user information such as the username, password, or both to their respective stores.
      static class  JXLoginPane.SimpleNamePanel
      If a UserNameStore is not used, then this text field is presented allowing the user to simply enter their user name
      static class  JXLoginPane.Status
      Returns the status of the login process
      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String CANCEL_LOGIN_ACTION_COMMAND
      Action key for an Action in the ActionMap that cancels the Login procedure
      static java.lang.String LOGIN_ACTION_COMMAND
      Action key for an Action in the ActionMap that initiates the Login procedure
      static java.lang.String uiClassID
      UI Class ID
      • Fields inherited from class javax.swing.JComponent

        listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
      • Fields inherited from class java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
    • Constructor Summary

      Constructors 
      Constructor Description
      JXLoginPane()
      Create a JXLoginPane that always accepts the user, never stores passwords or user ids, and has no target servers.
      JXLoginPane​(LoginService service)
      Create a JXLoginPane with the specified LoginService that does not store user ids or passwords and has no target servers.
      JXLoginPane​(LoginService service, PasswordStore passwordStore, UserNameStore userStore)
      Create a JXLoginPane with the specified LoginService, PasswordStore, and UserNameStore, but without a server list.
      JXLoginPane​(LoginService service, PasswordStore passwordStore, UserNameStore userStore, java.util.List<java.lang.String> servers)
      Create a JXLoginPane with the specified LoginService, PasswordStore, UserNameStore, and server list.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addNotify()  
      protected void cancelLogin()
      Cancels the login procedure.
      protected javax.swing.Action createCancelAction()
      Create and return an Action for canceling login
      protected javax.swing.Action createLoginAction()
      Create and return an Action for logging in
      protected java.awt.Image createLoginBanner()
      Create and return an image to use for the Banner.
      java.awt.Image getBanner()
      Return the image used as the banner
      java.lang.String getBannerText()
      Returns text used when creating the banner
      java.lang.String getErrorMessage()
      Returns the error message for this login panel
      LoginService getLoginService()
      Gets the LoginService for this panel.
      java.lang.String getMessage()
      Returns the custom message for this login panel
      char[] getPassword()
      Gets the Password for this panel.
      PasswordStore getPasswordStore()
      Gets the PasswordStore for this panel.
      JXLoginPane.SaveMode getSaveMode()  
      java.util.List<java.lang.String> getServers()  
      JXLoginPane.Status getStatus()
      Returns the panel's status
      LoginPaneUI getUI()
      java.lang.String getUIClassID()
      Returns the name of the L&F class that renders this component.
      java.lang.String getUserName()
      Gets the User name for this panel.
      UserNameStore getUserNameStore()
      Gets the UserNameStore for this panel.
      boolean isCapsLockDetectionSupported()
      Check current state of the caps lock state detection.
      boolean isCapsLockOn()
      Gets current state of the caps lock as seen by the login panel.
      protected void recreateLoginPanel()
      Recreates the login panel, and replaces the current one with the new one
      void removeNotify()  
      protected void savePassword()
      Puts the password into the password store.
      void setBanner​(java.awt.Image img)
      Set the image to use for the banner.
      void setBannerText​(java.lang.String text)
      Set the text to use when creating the banner.
      void setComponentOrientation​(java.awt.ComponentOrientation orient)
      This method adds functionality to support bidi languages within this component
      void setErrorMessage​(java.lang.String errorMessage)
      Sets the error message for this login panel
      void setLocale​(java.util.Locale l)  
      void setLoginService​(LoginService service)
      Sets the LoginService for this panel.
      void setMessage​(java.lang.String message)
      Sets a custom message for this login panel
      void setPassword​(char[] password)
      Sets the Password for this panel.
      void setPasswordStore​(PasswordStore store)
      Sets the PasswordStore for this panel.
      void setSaveMode​(JXLoginPane.SaveMode saveMode)
      The save mode indicates whether the "save" password is checked by default.
      void setServers​(java.util.List<java.lang.String> servers)
      Sets the list of servers.
      protected void setStatus​(JXLoginPane.Status newStatus)
      Change the status
      void setUI​(LoginPaneUI ui)
      Sets the look and feel (L&F) object that renders this component.
      void setUserName​(java.lang.String username)
      Sets the User name for this panel.
      void setUserNameStore​(UserNameStore store)
      Sets the user name store for this panel.
      static JXLoginPane.Status showLoginDialog​(java.awt.Component parent, LoginService svc)
      Shows a login dialog.
      static JXLoginPane.Status showLoginDialog​(java.awt.Component parent, LoginService svc, PasswordStore ps, UserNameStore us)
      Shows a login dialog.
      static JXLoginPane.Status showLoginDialog​(java.awt.Component parent, LoginService svc, PasswordStore ps, UserNameStore us, java.util.List<java.lang.String> servers)
      Shows a login dialog.
      static JXLoginPane.Status showLoginDialog​(java.awt.Component parent, JXLoginPane panel)
      Shows a login dialog.
      static JXLoginPane.JXLoginFrame showLoginFrame​(LoginService svc)
      Shows a login frame.
      static JXLoginPane.JXLoginFrame showLoginFrame​(LoginService svc, PasswordStore ps, UserNameStore us)  
      static JXLoginPane.JXLoginFrame showLoginFrame​(LoginService svc, PasswordStore ps, UserNameStore us, java.util.List<java.lang.String> servers)  
      static JXLoginPane.JXLoginFrame showLoginFrame​(JXLoginPane panel)  
      protected void startLogin()
      Initiates the login procedure.
      void updateUI()
      Notification from the UIManager that the L&F has changed.
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, paramString, setUI
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

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

      • LOGIN_ACTION_COMMAND

        public static final java.lang.String LOGIN_ACTION_COMMAND
        Action key for an Action in the ActionMap that initiates the Login procedure
        See Also:
        Constant Field Values
      • CANCEL_LOGIN_ACTION_COMMAND

        public static final java.lang.String CANCEL_LOGIN_ACTION_COMMAND
        Action key for an Action in the ActionMap that cancels the Login procedure
        See Also:
        Constant Field Values
    • Constructor Detail

      • 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,
                           java.util.List<java.lang.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 Detail

      • 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.
      • isCapsLockDetectionSupported

        public boolean isCapsLockDetectionSupported()
        Check current state of the caps lock state detection. Note that the value can change after component have been made visible. Due to current problems in locking key state detection by core java detection of the changes in caps lock can be always reliably determined. When component can't guarantee reliable detection it will switch it off. This is usually the case for unsigned applets and webstart invoked application. Since your users are going to pass their password in the component you should always sign it when distributing application over the network.
        Returns:
        True if changes in caps lock state can be monitored by the component, false otherwise.
      • getUI

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

        public void setUI​(LoginPaneUI ui)
        Sets the look and feel (L&F) object that renders this component.
        Parameters:
        ui - the LoginPaneUI L&F object
        See Also:
        UIDefaults.getUI(javax.swing.JComponent)
      • updateUI

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

        public java.lang.String getUIClassID()
        Returns the name of the L&F class that renders this component.
        Overrides:
        getUIClassID in class javax.swing.JPanel
        Returns:
        the string uiClassID
        See Also:
        JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)
      • recreateLoginPanel

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

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

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

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

        protected javax.swing.Action createCancelAction()
        Create and return an Action for canceling login
      • 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
      • getServers

        public java.util.List<java.lang.String> getServers()
        Returns:
        the List of servers
      • setServers

        public void setServers​(java.util.List<java.lang.String> servers)
        Sets the list of servers. See the servers field javadoc for more info
      • 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​(java.lang.String username)
        Sets the User name for this panel.
        Parameters:
        username - User name
      • getUserName

        public java.lang.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 java.awt.Image getBanner()
        Return the image used as the banner
      • setBanner

        public void setBanner​(java.awt.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​(java.lang.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 java.lang.String getBannerText()
        Returns text used when creating the banner
      • getMessage

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

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

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

        public void setErrorMessage​(java.lang.String errorMessage)
        Sets the error message for this login panel
      • setStatus

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

        public void setLocale​(java.util.Locale l)
        Overrides:
        setLocale in class java.awt.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.
      • removeNotify

        public void removeNotify()
        Overrides:
        removeNotify in class javax.swing.JComponent
      • addNotify

        public void addNotify()
        Overrides:
        addNotify in class javax.swing.JComponent
      • showLoginDialog

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

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

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