public final class JosmUserIdentityManager extends Object implements Preferences.PreferenceChangedListener
Preferences.PreferenceChangeEvent
s and keeps track
of what the current JOSM instance knows about the current user. Other subsystems can
let the global JosmUserStateManager know in case they fully identify the current user, see
setFullyIdentified(java.lang.String, org.openstreetmap.josm.data.osm.UserInfo)
.
The information kept by the JosmUserStateManager can be used to
Modifier and Type | Field and Description |
---|---|
private boolean |
accessTokenKeyChanged |
private boolean |
accessTokenSecretChanged |
private static JosmUserIdentityManager |
instance |
private UserInfo |
userInfo |
private String |
userName |
Modifier | Constructor and Description |
---|---|
private |
JosmUserIdentityManager() |
Modifier and Type | Method and Description |
---|---|
static JosmUserIdentityManager |
getInstance()
Replies the unique instance of the JOSM user identity manager
|
int |
getUserId()
Replies the user id of the current JOSM user. 0, if
isAnonymous() or
isPartiallyIdentified() is true. |
UserInfo |
getUserInfo()
Replies verified additional information about the current user if the user is
isFullyIdentified() . |
String |
getUserName()
Replies the user name of the current JOSM user. null, if
isAnonymous() is true. |
void |
initFromOAuth(Component parent)
Initializes the user identity manager from OAuth request of user details.
|
void |
initFromPreferences()
Initializes the user identity manager from Basic Authentication values in the
Preferences
This method should be called if osm-server.auth-method is set to basic . |
boolean |
isAnonymous()
Replies true if the current JOSM user is anonymous.
|
boolean |
isCurrentUser(String username)
Replies true if the user with name
username is the current
user |
boolean |
isFullyIdentified()
Replies true if the current JOSM user is fully identified.
|
boolean |
isPartiallyIdentified()
Replies true if the current JOSM user is partially identified.
|
void |
preferenceChanged(Preferences.PreferenceChangeEvent evt) |
void |
setAnonymous()
Remembers the fact that the current JOSM user is anonymous.
|
void |
setFullyIdentified(String username,
UserInfo userinfo)
Remembers the fact that the current JOSM user is fully identified with a
verified pair of user name and user id.
|
void |
setPartiallyIdentified(String userName)
Remebers the fact that the current JOSM user is partially identified
by the user name of its OSM account.
|
private static JosmUserIdentityManager instance
private boolean accessTokenKeyChanged
private boolean accessTokenSecretChanged
private JosmUserIdentityManager()
public static JosmUserIdentityManager getInstance()
public void setAnonymous()
public void setPartiallyIdentified(String userName) throws IllegalArgumentException
userName
- the user name. Must not be null. Must not be empty (whitespace only).IllegalArgumentException
- thrown if userName is nullIllegalArgumentException
- thrown if userName is emptypublic void setFullyIdentified(String username, UserInfo userinfo) throws IllegalArgumentException
username
- the user name. Must not be null. Must not be empty.userinfo
- additional information about the user, retrieved from the OSM server and including the user idIllegalArgumentException
- thrown if userName is nullIllegalArgumentException
- thrown if userName is emptyIllegalArgumentException
- thrown if userinfo is nullpublic boolean isAnonymous()
true
if the current user is anonymous.public boolean isPartiallyIdentified()
public boolean isFullyIdentified()
public String getUserName()
isAnonymous()
is true.public int getUserId()
isAnonymous()
or
isPartiallyIdentified()
is true.public UserInfo getUserInfo()
isFullyIdentified()
.public void initFromPreferences()
Preferences
This method should be called if osm-server.auth-method
is set to basic
.initFromOAuth(java.awt.Component)
public void initFromOAuth(Component parent)
osm-server.auth-method
is set to oauth
.parent
- component relative to which the PleaseWaitDialog
is displayed.initFromPreferences()
public boolean isCurrentUser(String username)
username
is the current
userusername
- the user nameusername
is the current
userpublic void preferenceChanged(Preferences.PreferenceChangeEvent evt)
preferenceChanged
in interface Preferences.PreferenceChangedListener