@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);
Modifier and Type | Class and Description |
---|---|
static class |
JXLoginPane.JXLoginDialog |
static class |
JXLoginPane.JXLoginFrame |
protected class |
JXLoginPane.LoginListenerImpl
Listener class to track state in the LoginService
|
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.Status
Returns the status of the login process
|
JPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
static String |
CANCEL_LOGIN_ACTION_COMMAND
Action key for an Action in the ActionMap that cancels the Login
procedure
|
static String |
LOGIN_ACTION_COMMAND
Action key for an Action in the ActionMap that initiates the Login
procedure
|
static String |
uiClassID
UI Class ID
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and 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,
List<String> servers)
Create a
JXLoginPane with the specified LoginService ,
PasswordStore , UserNameStore , and server list. |
Modifier and Type | Method and Description |
---|---|
protected void |
cancelLogin()
Cancels the login procedure.
|
protected Action |
createCancelAction()
Create and return an Action for canceling login
|
protected Action |
createLoginAction()
Create and return an Action for logging in
|
protected Image |
createLoginBanner()
Create and return an image to use for the Banner.
|
Image |
getBanner()
Return the image used as the banner
|
String |
getBannerText()
Returns text used when creating the banner
|
String |
getErrorMessage()
Returns the error message for this login panel
|
LoginService |
getLoginService()
Gets the LoginService for this panel.
|
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() |
List<String> |
getServers() |
JXLoginPane.Status |
getStatus()
Returns the panel's status
|
LoginPaneUI |
getUI() |
String |
getUIClassID()
Returns the name of the L&F class that renders this component.
|
String |
getUserName()
Gets the User name for this panel.
|
UserNameStore |
getUserNameStore()
Gets the
UserNameStore for this panel. |
boolean |
isCapsLockOn()
Gets current state of the caps lock as seen by the login panel.
|
boolean |
isRememberPassword() |
boolean |
isUserNameEnabled()
Gets current state of the user name field.
|
protected void |
recreateLoginPanel()
Recreates the login panel, and replaces the current one with the new one
|
protected void |
savePassword()
Puts the password into the password store.
|
void |
setBanner(Image img)
Set the image to use for the banner.
|
void |
setBannerText(String text)
Set the text to use when creating the banner.
|
void |
setComponentOrientation(ComponentOrientation orient)
This method adds functionality to support bidi languages within this
component
|
void |
setErrorMessage(String errorMessage)
Sets the error message for this login panel
|
void |
setLocale(Locale l) |
void |
setLoginService(LoginService service)
Sets the
LoginService for this panel. |
void |
setMessage(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(List<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(String username)
Sets the User name for this panel.
|
void |
setUserNameEnabled(boolean enabled)
Enables or disables User name for this panel.
|
void |
setUserNameStore(UserNameStore store)
Sets the user name store for this panel.
|
static JXLoginPane.Status |
showLoginDialog(Component parent,
JXLoginPane panel)
Shows a login dialog.
|
static JXLoginPane.Status |
showLoginDialog(Component parent,
LoginService svc)
Shows a login dialog.
|
static JXLoginPane.Status |
showLoginDialog(Component parent,
LoginService svc,
PasswordStore ps,
UserNameStore us)
Shows a login dialog.
|
static JXLoginPane.Status |
showLoginDialog(Component parent,
LoginService svc,
PasswordStore ps,
UserNameStore us,
List<String> servers)
Shows a login dialog.
|
static JXLoginPane.JXLoginFrame |
showLoginFrame(JXLoginPane panel) |
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,
List<String> servers) |
protected void |
startLogin()
Initiates the login procedure.
|
void |
updateUI()
Notification from the
UIManager that the L&F has changed. |
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, setScrollableWidthHint
getAccessibleContext, paramString, setUI
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, update
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
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, getPeer, 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, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public static final String uiClassID
public static final String LOGIN_ACTION_COMMAND
public static final String CANCEL_LOGIN_ACTION_COMMAND
public JXLoginPane()
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.
public JXLoginPane(LoginService service)
JXLoginPane
with the specified LoginService
that does not store user ids or passwords and has no target servers.service
- the LoginService
to use for logging inpublic JXLoginPane(LoginService service, PasswordStore passwordStore, UserNameStore userStore)
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.
service
- the LoginService
to use for logging inpasswordStore
- the PasswordStore
to use for storing password
informationuserStore
- the UserNameStore
to use for storing user informationpublic JXLoginPane(LoginService service, PasswordStore passwordStore, UserNameStore userStore, List<String> servers)
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
.
service
- the LoginService
to use for logging inpasswordStore
- the PasswordStore
to use for storing password
informationuserStore
- the UserNameStore
to use for storing user informationservers
- a list of servers to authenticate againstpublic boolean isCapsLockOn()
isCapsLockDetectionSupported()
returns false.public LoginPaneUI getUI()
public void setUI(LoginPaneUI ui)
ui
- the LoginPaneUI L&F objectUIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
UIManager
that the L&F has changed.
Replaces the current UI object with the latest version from the
UIManager
.updateUI
in class JPanel
JComponent.updateUI()
public String getUIClassID()
getUIClassID
in class JPanel
uiClassID
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
protected void recreateLoginPanel()
public void setComponentOrientation(ComponentOrientation orient)
setComponentOrientation
in class Component
protected Image createLoginBanner()
protected Action createLoginAction()
protected Action createCancelAction()
public JXLoginPane.SaveMode getSaveMode()
public void setSaveMode(JXLoginPane.SaveMode saveMode)
saveMode
- The saveMode to set either SAVE_NONE, SAVE_PASSWORD or SAVE_USERNAMEpublic boolean isRememberPassword()
public void setServers(List<String> servers)
public void setLoginService(LoginService service)
LoginService
for this panel. Setting the login service
to null
will actually set the service to use
NullLoginService
.service
- the service to set. If service == null
, then a
NullLoginService
is used.public LoginService getLoginService()
public void setPasswordStore(PasswordStore store)
store
- PasswordStorepublic UserNameStore getUserNameStore()
UserNameStore
for this panel.UserNameStore
public void setUserNameStore(UserNameStore store)
store
- public PasswordStore getPasswordStore()
public void setUserName(String username)
username
- User namepublic void setUserNameEnabled(boolean enabled)
enabled
- public boolean isUserNameEnabled()
public String getUserName()
public void setPassword(char[] password)
password
- Passwordpublic char[] getPassword()
public Image getBanner()
public void setBanner(Image img)
img
is null
,
then no image will be displayed.img
- the image to displaypublic void setBannerText(String text)
text
is null
, then
no text is displayed.text
- the text to displaypublic String getBannerText()
public String getMessage()
public void setMessage(String message)
public String getErrorMessage()
public void setErrorMessage(String errorMessage)
public JXLoginPane.Status getStatus()
protected void setStatus(JXLoginPane.Status newStatus)
protected void startLogin()
getSynchronous()
returns true.protected void cancelLogin()
startAuthentications()
and only when
authentication is performed asynchronously (getSynchronous()
returns false).protected void savePassword()
public static JXLoginPane.Status showLoginDialog(Component parent, LoginService svc)
public static JXLoginPane.Status showLoginDialog(Component parent, LoginService svc, PasswordStore ps, UserNameStore us)
public static JXLoginPane.Status showLoginDialog(Component parent, LoginService svc, PasswordStore ps, UserNameStore us, List<String> servers)
public static JXLoginPane.Status showLoginDialog(Component parent, JXLoginPane panel)
public static JXLoginPane.JXLoginFrame showLoginFrame(LoginService svc)
public static JXLoginPane.JXLoginFrame showLoginFrame(LoginService svc, PasswordStore ps, UserNameStore us)
public static JXLoginPane.JXLoginFrame showLoginFrame(LoginService svc, PasswordStore ps, UserNameStore us, List<String> servers)
public static JXLoginPane.JXLoginFrame showLoginFrame(JXLoginPane panel)
Copyright © 2018. All rights reserved.