Package uk.ac.starlink.auth
Class UserInterface
java.lang.Object
uk.ac.starlink.auth.UserInterface
Abstraction via which authentication classes can acquire credentials
from the user.
- Since:
- 15 Jun 2020
- Author:
- Mark Taylor
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final UserInterface
Command-line instance.static final UserInterface
Instance that uses Swing popup dialogues.static final UserInterface
Instance that will not authenticate.static final String
Name of password system property for headless UI instance ("auth.password").static final String
Name of username system property for headless UI instance ("auth.username"). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract boolean
canRetry()
Indicates whether there is any point in repeated attempts to acquire credentials from the user.static JComponent
createAuthPanel
(String[] msgLines, JTextField userField, JPasswordField passField) Places the components for acquiring username and password.static UserInterface
createFixed
(String username, String password) Returns a headless implementation with a fixed user name and password supplied as strings.static UserInterface
createFixed
(UserPass userpass) Returns a headless implementation with a fixed username+password object.Returns the GUI component to which this UI is subordinate.static UserInterface
Returns a headless UI that takes username and password from the system propertiesUSERNAME_PROP
andPASSWORD_PROP
respectively, if both properties are set.static UserInterface
getPropertiesUi
(String userProp, String passProp) Returns a headless UI that takes username and password from two named System Properties.abstract void
Sends a message to the user.abstract UserPass
readUserPassword
(String[] msgLines) Returns a username/password pair, or null if the user declines to supply one.void
Sets a GUI component to which this UI is subordinate.
-
Field Details
-
CLI
Command-line instance. -
GUI
Instance that uses Swing popup dialogues. -
NO_AUTH
Instance that will not authenticate. -
USERNAME_PROP
Name of username system property for headless UI instance ("auth.username").- See Also:
-
PASSWORD_PROP
Name of password system property for headless UI instance ("auth.password").- See Also:
-
-
Constructor Details
-
UserInterface
public UserInterface()
-
-
Method Details
-
readUserPassword
Returns a username/password pair, or null if the user declines to supply one.- Parameters:
msgLines
- message to output to the user first- Returns:
- credentials, or null if the user declines
-
message
Sends a message to the user. In the case of a GUI this will typically provoke a popup window, so it should not be used gratitously.- Parameters:
lines
- message to pass to the user
-
canRetry
public abstract boolean canRetry()Indicates whether there is any point in repeated attempts to acquire credentials from the user. In an interactive context, this would typically return true, but in a headless context with preset credentials that will not change between invocations, it should return false.- Returns:
- true if repeated requests may return different results
-
setParent
Sets a GUI component to which this UI is subordinate. For non-GUI implementations, this method is likely to have no effect, but for GUI-based implementations, it can be used to manage the ownership of popup dialogues.- Parameters:
parent
- new parent component, may be null
-
getParent
Returns the GUI component to which this UI is subordinate. Likely to be irrelevant for non-GUI implementations.- Returns:
- parent component, may be null
-
createFixed
Returns a headless implementation with a fixed user name and password supplied as strings.- Parameters:
username
- usernamepassword
- password- Returns:
- headless instance
-
createFixed
Returns a headless implementation with a fixed username+password object.- Parameters:
userpass
- credentials object- Returns:
- headless instance
-
getPropertiesUi
Returns a headless UI that takes username and password from the system propertiesUSERNAME_PROP
andPASSWORD_PROP
respectively, if both properties are set.If the first character of either property value is "@", the remainder is interpreted as a filename containing the value.
Use the result of this method with care, since it risks leaking credentials to sites for which they are not intended.
This is a shortcut for
getPropertiesUi
(USERNAME_PROP
,PASSWORD_PROP
).- Returns:
- new headless UserInterface instance, or null if not both properties are set
-
getPropertiesUi
Returns a headless UI that takes username and password from two named System Properties. If the system properties, read at the time of this invocation, have not been defined, then null is returned.If the first character of either property value is "@", the remainder is interpreted as a filename containing the value.
Use the result of this method with care, since it risks leaking credentials to sites for which they are not intended.
- Parameters:
userProp
- system property name for acquiring usernamepassProp
- system property name for acquiring password- Returns:
- new headless UserInterface instance, or null if not both properties are set
-
createAuthPanel
public static JComponent createAuthPanel(String[] msgLines, JTextField userField, JPasswordField passField) Places the components for acquiring username and password.- Parameters:
msgLines
- message to display to useruserField
- field for usernamepassField
- field for password
-