public final class UserIdentityManager extends java.lang.Object implements PreferenceChangedListener
GET /api/0.6/user/details
request, submitted with the user name and password
of the current user.
The global UserIdentityManager listens to PreferenceChangeEvent
s and keeps track
of what the current JOSM instance knows about the current user. Other subsystems can
let the global UserIdentityManager 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 UserIdentityManager can be used to
org.openstreetmap.josm.gui.JosmUserIdentityManager
), 2689 (creation)Modifier and Type | Field and Description |
---|---|
private boolean |
accessTokenKeyChanged |
private boolean |
accessTokenSecretChanged |
private static UserIdentityManager |
instance |
private UserInfo |
userInfo |
private java.lang.String |
userName |
Modifier | Constructor and Description |
---|---|
private |
UserIdentityManager() |
Modifier and Type | Method and Description |
---|---|
User |
asUser()
Returns the identity as a
User object |
static UserIdentityManager |
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 |
isCurrentUser(User user)
Replies true if the current user is
fully identified and the user ids match,
or if the current user is not fully identified and the user names match. |
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(PreferenceChangeEvent evt)
Triggered when a preference entry value changes.
|
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)
Remembers the fact that the current JOSM user is partially identified
by the user name of its OSM account.
|
private static UserIdentityManager instance
private java.lang.String userName
private boolean accessTokenKeyChanged
private boolean accessTokenSecretChanged
private UserIdentityManager()
public static UserIdentityManager 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 User asUser()
User
objectUser.getAnonymous()
if isAnonymous()
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 boolean isCurrentUser(User user)
fully identified
and the user ids
match,
or if the current user is not fully identified
and the user names
match.user
- the user to testpublic void preferenceChanged(PreferenceChangeEvent evt)
PreferenceChangedListener
preferenceChanged
in interface PreferenceChangedListener
evt
- the preference change event