Class JXLoginPane
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,Scrollable
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);
- Author:
- Bino George, Shai Almog, rbair, Karl Schaefer, rah003, Jonathan Giles, EUG https://github.com/homebeaver (banner as CompoundPainter: ImagePainter + TextPainter)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final classprotected classListener class to track state in the LoginServicestatic enumThe JXLoginPane can attempt to save certain user information such as the username, password, or both to their respective stores.static enumReturns the status of the login processNested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAction key for an Action in the ActionMap that cancels the Login procedurestatic final StringAction key for an Action in the ActionMap that initiates the Login procedurestatic final StringUI Class IDFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionCreate aJXLoginPanethat always accepts the user, never stores passwords or user ids, and has no target servers.JXLoginPane(LoginService service) Create aJXLoginPanewith the specifiedLoginServicethat does not store user ids or passwords and has no target servers.JXLoginPane(LoginService service, PasswordStore passwordStore, UserNameStore userStore) Create aJXLoginPanewith the specifiedLoginService,PasswordStore, andUserNameStore, but without a server list.JXLoginPane(LoginService service, PasswordStore passwordStore, UserNameStore userStore, List<String> servers) Create aJXLoginPanewith the specifiedLoginService,PasswordStore,UserNameStore, and server list. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCancels the login procedure.protected ActionCreate and return an Action for canceling loginprotected ActionCreate and return an Action for logging inprotected ImageCreate and return an image to use for the Banner.Return the image used as the bannerReturns text shown in the bannerReturns the error message for this login panelGets the LoginService for this panel.Returns the custom message for this login panelchar[]Gets the Password for this panel.Gets the PasswordStore for this panel.Returns the panel's statusgetUI()Returns the name of the LaF class that renders this component.Gets the User name for this panel.Gets theUserNameStorefor this panel.booleanGets current state of the caps lock as seen by the login panel.booleanindicator for customized BannerbooleanbooleanGets current state of the user name field.protected voidRecreates the login panel, and replaces the current one with the new oneprotected voidPuts the password into the password store.voidSet the image to use for the banner.voidsetBannerText(String text) Set the text to use when creating the banner.voidThis method adds functionality to support bidi languages within this componentvoidsetErrorMessage(String errorMessage) Sets the error message for this login panelvoidvoidsetLoginService(LoginService service) Sets theLoginServicefor this panel.voidsetMessage(String message) Sets a custom message for this login panelvoidsetPassword(char[] password) Sets the Password for this panel.voidsetPasswordStore(PasswordStore store) Sets the PasswordStore for this panel.voidsetSaveMode(JXLoginPane.SaveMode saveMode) The save mode indicates whether the "save" password is checked by default.voidsetServers(List<String> servers) Sets the list of servers.protected voidsetStatus(JXLoginPane.Status newStatus) Change the statusvoidsetUserName(String username) Sets the User name for this panel.voidsetUserNameEnabled(boolean enabled) Enables or disables User name for this panel.voidsetUserNameStore(UserNameStore store) Sets the user name store for this panel.static JXLoginPane.StatusshowLoginDialog(Component parent, LoginService svc) Shows a login dialog.static JXLoginPane.StatusshowLoginDialog(Component parent, LoginService svc, PasswordStore ps, UserNameStore us) Shows a login dialog.static JXLoginPane.StatusshowLoginDialog(Component parent, LoginService svc, PasswordStore ps, UserNameStore us, List<String> servers) Shows a login dialog.static JXLoginPane.StatusshowLoginDialog(Component parent, JXLoginPane panel) Shows a login dialog.static JXLoginPane.JXLoginFrameShows a login frame.static JXLoginPane.JXLoginFrameshowLoginFrame(LoginService svc, PasswordStore ps, UserNameStore us) Shows a login frame.static JXLoginPane.JXLoginFrameshowLoginFrame(LoginService svc, PasswordStore ps, UserNameStore us, List<String> servers) Shows a login frame.static JXLoginPane.JXLoginFrameshowLoginFrame(JXLoginPane panel) Shows a login frame.protected voidInitiates the login procedure.voidupdateUI()Notification from theUIManagerthat the LaF has changed.Methods inherited from class org.jdesktop.swingx.JXPanel
getAlpha, getBackgroundPainter, getEffectiveAlpha, getPainterChangeListener, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableHeightHint, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollableWidthHint, isAlpha, isInheritAlpha, isOpaque, isOpaquePatch, isPaintBorderInsets, isPaintingBackground, isPaintingOrigin, isPatch, isTransparentBackground, paint, paintComponent, paintComponentPatch, setAlpha, setBackgroundPainter, setInheritAlpha, setOpaque, setOpaquePatch, setPaintBorderInsets, setScrollableHeightHint, setScrollableTracksViewportHeight, setScrollableTracksViewportWidth, setScrollableWidthHintMethods inherited from class javax.swing.JPanel
getAccessibleContext, paramString, setUIMethods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, 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, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, 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, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods 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, validateTreeMethods 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
-
Field Details
-
uiClassID
UI Class ID- See Also:
-
LOGIN_ACTION_COMMAND
Action key for an Action in the ActionMap that initiates the Login procedure- See Also:
-
CANCEL_LOGIN_ACTION_COMMAND
Action key for an Action in the ActionMap that cancels the Login procedure- See Also:
-
-
Constructor Details
-
JXLoginPane
public JXLoginPane()Create aJXLoginPanethat 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
Create aJXLoginPanewith the specifiedLoginServicethat does not store user ids or passwords and has no target servers.- Parameters:
service- theLoginServiceto use for logging in
-
JXLoginPane
Create aJXLoginPanewith the specifiedLoginService,PasswordStore, andUserNameStore, but without a server list.If you do not want to store passwords or user ids, those parameters can be
null.SaveModeis autoconfigured from passed in store parameters.- Parameters:
service- theLoginServiceto use for logging inpasswordStore- thePasswordStoreto use for storing password informationuserStore- theUserNameStoreto use for storing user information
-
JXLoginPane
public JXLoginPane(LoginService service, PasswordStore passwordStore, UserNameStore userStore, List<String> servers) Create aJXLoginPanewith the specifiedLoginService,PasswordStore,UserNameStore, and server list.If you do not want to store passwords or user ids, those parameters can be
null.SaveModeis autoconfigured from passed in store parameters.Setting the server list to
nullwill unset all of the servers. The server list is guaranteed to be non-null.- Parameters:
service- theLoginServiceto use for logging inpasswordStore- thePasswordStoreto use for storing password informationuserStore- theUserNameStoreto use for storing user informationservers- a list of servers to authenticate against
-
-
Method Details
-
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.
-
isCustomizedBanner
public boolean isCustomizedBanner()indicator for customized Banner- Returns:
- boolean
-
getUI
-
updateUI
public void updateUI()Notification from theUIManagerthat the LaF has changed. Replaces the current UI object with the latest version from theUIManager. -
getUIClassID
Returns the name of the LaF class that renders this component.- Overrides:
getUIClassIDin classJPanel- Returns:
- the string
uiClassID - See Also:
-
recreateLoginPanel
protected void recreateLoginPanel()Recreates the login panel, and replaces the current one with the new one -
setComponentOrientation
This method adds functionality to support bidi languages within this component- Overrides:
setComponentOrientationin classComponent
-
createLoginBanner
Create and return an image to use for the Banner. This may be overridden to return any image you like- Returns:
- Image to use for the Banner
-
createLoginAction
Create and return an Action for logging in- Returns:
- Action to log in
-
createCancelAction
Create and return an Action for canceling login- Returns:
- Action to cancel log in
-
getSaveMode
- Returns:
- Returns the saveMode.
-
setSaveMode
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()- Returns:
- true if isRememberPassword is selected
-
getServers
- Returns:
- the List of servers
-
setServers
Sets the list of servers. See the servers field javadoc for more info.- Parameters:
servers- list of servers
-
setLoginService
Sets theLoginServicefor this panel. Setting the login service tonullwill actually set the service to useNullLoginService.- Parameters:
service- the service to set. Ifservice == null, then aNullLoginServiceis used.
-
getLoginService
Gets the LoginService for this panel.- Returns:
- service service
-
setPasswordStore
Sets the PasswordStore for this panel.- Parameters:
store- PasswordStore
-
getUserNameStore
Gets theUserNameStorefor this panel.- Returns:
- the
UserNameStore
-
setUserNameStore
Sets the user name store for this panel.- Parameters:
store- UserNameStore
-
getPasswordStore
Gets the PasswordStore for this panel.- Returns:
- store PasswordStore
-
setUserName
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- flag
-
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
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
Return the image used as the banner- Returns:
- Image banner
-
setBanner
Set the image to use for the banner. If theimgisnull, then no image will be displayed.- Parameters:
img- the image to display
-
setBannerText
Set the text to use when creating the banner. If a custom banner image is specified, then this is ignored. Iftextisnull, then no text is displayed.- Parameters:
text- the text to display
-
getBannerText
Returns text shown in the banner- Returns:
- banner text
-
getMessage
Returns the custom message for this login panel- Returns:
- message text
-
setMessage
Sets a custom message for this login panel- Parameters:
message- text
-
getErrorMessage
Returns the error message for this login panel- Returns:
- error message
-
setErrorMessage
Sets the error message for this login panel- Parameters:
errorMessage- the error message
-
getStatus
Returns the panel's status- Returns:
- Status
-
setStatus
Change the status- Parameters:
newStatus- Status
-
setLocale
-
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 ifgetSynchronous()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 tostartAuthentications()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. -
showLoginDialog
Shows a login dialog. This method blocks.- Parameters:
parent- Componentsvc- LoginService- 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.- Parameters:
parent- Componentsvc- LoginServiceps- PasswordStoreus- UserNameStore- 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.- Parameters:
parent- Componentsvc- LoginServiceps- PasswordStoreus- UserNameStoreservers- list of servers- Returns:
- The status of the login operation
-
showLoginDialog
Shows a login dialog. This method blocks.- Parameters:
parent- Componentpanel- JXLoginPane to show- Returns:
- The status of the login operation
-
showLoginFrame
Shows a login frame. A JFrame is not modal, and thus does not block- Parameters:
svc- LoginService- Returns:
- JXLoginFrame to show
-
showLoginFrame
public static JXLoginPane.JXLoginFrame showLoginFrame(LoginService svc, PasswordStore ps, UserNameStore us) Shows a login frame.- Parameters:
svc- LoginServiceps- PasswordStoreus- UserNameStore- Returns:
- JXLoginFrame to show
-
showLoginFrame
public static JXLoginPane.JXLoginFrame showLoginFrame(LoginService svc, PasswordStore ps, UserNameStore us, List<String> servers) Shows a login frame.- Parameters:
svc- LoginServiceps- PasswordStoreus- UserNameStoreservers- list of servers- Returns:
- JXLoginFrame to show
-
showLoginFrame
Shows a login frame.- Parameters:
panel- JXLoginPane panel to show- Returns:
- JXLoginFrame to show
-