Package org.openstreetmap.josm.data
Class UserIdentityManager
- java.lang.Object
-
- org.openstreetmap.josm.data.UserIdentityManager
-
- All Implemented Interfaces:
PreferenceChangedListener
public final class UserIdentityManager extends java.lang.Object implements PreferenceChangedListener
UserIdentityManager is a global object which keeps track of what JOSM knows about the identity of the current user. JOSM can be operated anonymously provided the current user never invokes an operation on the OSM server which required authentication. In this case JOSM neither knows the user name of the OSM account of the current user nor its unique id. Perhaps the user doesn't have one. If the current user supplies a user name and a password in the JOSM preferences JOSM can partially identify the user. The current user is fully identified if JOSM knows both the user name and the unique id of the users OSM account. The latter is retrieved from the OSM server with aGET /api/0.6/user/details
request, submitted with the user name and password of the current user. The global UserIdentityManager listens toPreferenceChangeEvent
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, seesetFullyIdentified(java.lang.String, org.openstreetmap.josm.data.osm.UserInfo)
. The information kept by the UserIdentityManager can be used to- safely query changesets owned by the current user based on its user id, not on its user name
- safely search for objects last touched by the current user based on its user id, not on its user name
- Since:
- 12743 (renamed from
org.openstreetmap.josm.gui.JosmUserIdentityManager
), 2689 (creation)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
UserIdentityManager.UserIdentityListener
This listener is notified whenever the osm user is changed.
-
Field Summary
Fields Modifier and Type Field Description private boolean
accessTokenKeyChanged
private boolean
accessTokenSecretChanged
private static UserIdentityManager
instance
private ListenerList<UserIdentityManager.UserIdentityListener>
listeners
private UserInfo
userInfo
private java.lang.String
userName
-
Constructor Summary
Constructors Modifier Constructor Description private
UserIdentityManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(UserIdentityManager.UserIdentityListener listener)
Add a listener that listens to changes of the current user.User
asUser()
Returns the identity as aUser
objectprivate void
fireUserIdentityChanged()
static UserIdentityManager
getInstance()
Replies the unique instance of the JOSM user identity managerint
getUserId()
Replies the user id of the current JOSM user.UserInfo
getUserInfo()
Replies verified additional information about the current user if the user isisFullyIdentified()
.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 thePreferences
This method should be called ifosm-server.auth-method
is set tobasic
.boolean
isAnonymous()
Replies true if the current JOSM user is anonymous.boolean
isCurrentUser(java.lang.String userName)
Replies true if the user with nameusername
is the current userboolean
isCurrentUser(User user)
Replies true if the current user isfully identified
and theuser ids
match, or if the current user is notfully identified
and theuser 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.
-
-
-
Field Detail
-
instance
private static UserIdentityManager instance
-
listeners
private final ListenerList<UserIdentityManager.UserIdentityListener> listeners
-
userName
private java.lang.String userName
-
accessTokenKeyChanged
private boolean accessTokenKeyChanged
-
accessTokenSecretChanged
private boolean accessTokenSecretChanged
-
-
Constructor Detail
-
UserIdentityManager
private UserIdentityManager()
-
-
Method Detail
-
getInstance
public static UserIdentityManager getInstance()
Replies the unique instance of the JOSM user identity manager- Returns:
- the unique instance of the JOSM user identity manager
-
setAnonymous
public void setAnonymous()
Remembers the fact that the current JOSM user is anonymous.
-
setPartiallyIdentified
public 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.- Parameters:
userName
- the user name. Must not be null. Must not be empty (whitespace only).- Throws:
java.lang.IllegalArgumentException
- if userName is nulljava.lang.IllegalArgumentException
- if userName is empty
-
setFullyIdentified
public 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.- Parameters:
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 id- Throws:
java.lang.IllegalArgumentException
- if userName is nulljava.lang.IllegalArgumentException
- if userName is emptyjava.lang.IllegalArgumentException
- if userInfo is null
-
isAnonymous
public boolean isAnonymous()
Replies true if the current JOSM user is anonymous.- Returns:
true
if the current user is anonymous.
-
isPartiallyIdentified
public boolean isPartiallyIdentified()
Replies true if the current JOSM user is partially identified.- Returns:
- true if the current JOSM user is partially identified.
-
isFullyIdentified
public boolean isFullyIdentified()
Replies true if the current JOSM user is fully identified.- Returns:
- true if the current JOSM user is fully identified.
-
getUserName
public java.lang.String getUserName()
Replies the user name of the current JOSM user. null, ifisAnonymous()
is true.- Returns:
- the user name of the current JOSM user
-
getUserId
public int getUserId()
Replies the user id of the current JOSM user. 0, ifisAnonymous()
orisPartiallyIdentified()
is true.- Returns:
- the user id of the current JOSM user
-
getUserInfo
public UserInfo getUserInfo()
Replies verified additional information about the current user if the user isisFullyIdentified()
.- Returns:
- verified additional information about the current user
-
asUser
public User asUser()
Returns the identity as aUser
object- Returns:
- the identity as user, or
User.getAnonymous()
ifisAnonymous()
-
initFromPreferences
public void initFromPreferences()
Initializes the user identity manager from Basic Authentication values in thePreferences
This method should be called ifosm-server.auth-method
is set tobasic
.- See Also:
initFromOAuth()
-
initFromOAuth
public void initFromOAuth()
Initializes the user identity manager from OAuth request of user details. This method should be called ifosm-server.auth-method
is set tooauth
.- Since:
- 5434
- See Also:
initFromPreferences()
-
isCurrentUser
public boolean isCurrentUser(java.lang.String userName)
Replies true if the user with nameusername
is the current user- Parameters:
userName
- the user name- Returns:
- true if the user with name
username
is the current user
-
isCurrentUser
public boolean isCurrentUser(User user)
Replies true if the current user isfully identified
and theuser ids
match, or if the current user is notfully identified
and theuser names
match.- Parameters:
user
- the user to test- Returns:
- true if given user is the current user
-
preferenceChanged
public void preferenceChanged(PreferenceChangeEvent evt)
Description copied from interface:PreferenceChangedListener
Triggered when a preference entry value changes.- Specified by:
preferenceChanged
in interfacePreferenceChangedListener
- Parameters:
evt
- the preference change event
-
addListener
public void addListener(UserIdentityManager.UserIdentityListener listener)
Add a listener that listens to changes of the current user.- Parameters:
listener
- The listener
-
fireUserIdentityChanged
private void fireUserIdentityChanged()
-
-