public final class JosmUserIdentityManager extends java.lang.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 JosmUserIdentityManager 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 JosmUserIdentityManager can be used to
Modifier and Type | Field and Description |
---|---|
private boolean |
accessTokenKeyChanged |
private boolean |
accessTokenSecretChanged |
private static JosmUserIdentityManager |
instance |
private UserInfo |
userInfo |
private java.lang.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.
|
UserInfo |
getUserInfo()
Replies verified additional information about the current user if the user is
isFullyIdentified() . |
java.lang.String |
getUserName()
Replies the user name of the current JOSM user.
|
void |
initFromOAuth()
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(java.lang.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(java.lang.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(java.lang.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 java.lang.String userName
private boolean accessTokenKeyChanged
private boolean accessTokenSecretChanged
private JosmUserIdentityManager()
public static JosmUserIdentityManager getInstance()
public void setAnonymous()
public void setPartiallyIdentified(java.lang.String userName)
userName
- the user name. Must not be null. Must not be empty (whitespace only).java.lang.IllegalArgumentException
- if userName is nulljava.lang.IllegalArgumentException
- if userName is emptypublic void setFullyIdentified(java.lang.String username, UserInfo userinfo)
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 idjava.lang.IllegalArgumentException
- if userName is nulljava.lang.IllegalArgumentException
- if userName is emptyjava.lang.IllegalArgumentException
- if userinfo is nullpublic boolean isAnonymous()
true
if the current user is anonymous.public boolean isPartiallyIdentified()
public boolean isFullyIdentified()
public java.lang.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()
public void initFromOAuth()
osm-server.auth-method
is set to oauth
.initFromPreferences()
public boolean isCurrentUser(java.lang.String username)
username
is the current
userusername
- the user nameusername
is the current
userpublic void preferenceChanged(Preferences.PreferenceChangeEvent evt)
preferenceChanged
in interface Preferences.PreferenceChangedListener