hudson.model
Class User

java.lang.Object
  extended by hudson.model.AbstractModelObject
      extended by hudson.model.User
All Implemented Interfaces:
DescriptorByNameOwner, ModelObject, Saveable, SearchableModelObject, SearchItem, AccessControlled, Comparable<User>

@ExportedBean
public class User
extends AbstractModelObject
implements AccessControlled, DescriptorByNameOwner, Saveable, Comparable<User>

Represents a user.

In Hudson, User objects are created in on-demand basis; for example, when a build is performed, its change log is computed and as a result commits from users who Hudson has never seen may be discovered. When this happens, new User object is created.

If the persisted record for an user exists, the information is loaded at that point, but if there's no such record, a fresh instance is created from thin air (this is where UserPropertyDescriptor.newInstance(User) is called to provide initial UserProperty objects.

Such newly created User objects will be simply GC-ed without ever leaving the persisted record, unless save() method is explicitly invoked (perhaps as a result of a browser submitting a configuration.)

Author:
Kohsuke Kawaguchi

Nested Class Summary
static class User.CanonicalIdResolver
           
static class User.FullNameIdResolver
          Resolve user ID from full name
 
Field Summary
static XStream2 XSTREAM
          Used to load/save user configuration.
 
Fields inherited from interface hudson.model.Saveable
NOOP
 
Method Summary
 void addProperty(UserProperty p)
          Updates the user object by adding a property.
 boolean canDelete()
          With ADMINISTER permission, can delete users with persisted data but can't delete self.
 void checkPermission(Permission permission)
          Convenient short-cut for getACL().checkPermission(permission)
static void clear()
          Stop gap hack.
 int compareTo(User that)
           
static User current()
          Gets the User object representing the currently logged-in user, or null if the current user is anonymous.
 void delete()
          Deletes the data directory and removes this user from Hudson.
 void doConfigSubmit(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Accepts submission from the configuration page.
 void doDoDelete(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Deletes this user from Hudson.
 void doRssAll(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
           
 void doRssFailed(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
           
 void doRssLatest(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
           
 void doSubmitDescription(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Accepts the new description.
static User get(String idOrFullName)
          Gets the User object by its id or full name.
static User get(String idOrFullName, boolean create)
          Deprecated. use get(String, boolean, java.util.Map)
static User get(String idOrFullName, boolean create, Map context)
          Gets the User object by its id or full name.
 String getAbsoluteUrl()
          The URL of the user page.
 ACL getACL()
          Obtains the ACL associated with this object.
static Collection<User> getAll()
          Gets all the users.
 List<UserProperty> getAllProperties()
          List of all UserPropertys exposed primarily for the remoting API.
 Api getApi()
          Exposed remote API.
 List<String> getAuthorities()
          Checks for authorities (groups) associated with this user.
 RunList getBuilds()
          Gets the list of Builds that include changes by this user, by the timestamp order.
protected  XmlFile getConfigFile()
          The file we save our configuration.
 String getDescription()
           
 Descriptor getDescriptorByName(String className)
          Exposes all Descriptors by its name to URL.
 String getDisplayName()
          Returns the user name.
 Object getDynamic(String token)
           
 String getFullName()
          Gets the human readable name of this user.
 String getId()
           
 Set<AbstractProject<?,?>> getProjects()
          Gets all the AbstractProjects that this user has committed to.
 Map<Descriptor<UserProperty>,UserProperty> getProperties()
          Gets the user properties configured for this user.
<T extends UserProperty>
T
getProperty(Class<T> clazz)
          Gets the specific property, or null.
 List<Action> getPropertyActions()
          Return all properties that are also actions.
 String getSearchUrl()
          Returns the URL of this item relative to the parent SearchItem.
 List<Action> getTransientActions()
          Return all transient actions associated with this user.
static User getUnknown()
          Gets the fallback "unknown" user instance.
 String getUrl()
           
 boolean hasPermission(Permission permission)
          Convenient short-cut for getACL().hasPermission(permission)
 org.acegisecurity.Authentication impersonate()
          Creates an Authentication object that represents this user.
static void reload()
          Reloads the configuration from disk.
 void save()
          Save the settings to a file.
 void setFullName(String name)
          Sets the human readable name of thie user.
 String toString()
           
 
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

XSTREAM

public static final XStream2 XSTREAM
Used to load/save user configuration.

Method Detail

compareTo

public int compareTo(User that)
Specified by:
compareTo in interface Comparable<User>

getId

@Exported
public String getId()

getUrl

public String getUrl()

getSearchUrl

public String getSearchUrl()
Description copied from interface: SearchItem
Returns the URL of this item relative to the parent SearchItem.

Specified by:
getSearchUrl in interface SearchItem
Returns:
URL like "foo" or "foo/bar". The path can end with '/'. The path that starts with '/' will be interpreted as the absolute path (within the context path of Hudson.)

getAbsoluteUrl

@Exported(visibility=999)
public String getAbsoluteUrl()
The URL of the user page.


getFullName

@Exported(visibility=999)
public String getFullName()
Gets the human readable name of this user. This is configurable by the user.

Returns:
never null.

setFullName

public void setFullName(String name)
Sets the human readable name of thie user.


getDescription

@Exported
public String getDescription()

getProperties

public Map<Descriptor<UserProperty>,UserProperty> getProperties()
Gets the user properties configured for this user.


addProperty

public void addProperty(UserProperty p)
                 throws IOException
Updates the user object by adding a property.

Throws:
IOException

getAllProperties

@Exported(name="property",
          inline=true)
public List<UserProperty> getAllProperties()
List of all UserPropertys exposed primarily for the remoting API.


getProperty

public <T extends UserProperty> T getProperty(Class<T> clazz)
Gets the specific property, or null.


impersonate

public org.acegisecurity.Authentication impersonate()
Creates an Authentication object that represents this user.

Since:
1.419

doSubmitDescription

public void doSubmitDescription(org.kohsuke.stapler.StaplerRequest req,
                                org.kohsuke.stapler.StaplerResponse rsp)
                         throws IOException,
                                javax.servlet.ServletException
Accepts the new description.

Throws:
IOException
javax.servlet.ServletException

getUnknown

@Nonnull
public static User getUnknown()
Gets the fallback "unknown" user instance.

This is used to avoid null User instance.


get

public static User get(String idOrFullName,
                       boolean create)
Deprecated. use get(String, boolean, java.util.Map)

Gets the User object by its id or full name.

Parameters:
create - If true, this method will never return null for valid input (by creating a new User object if none exists.) If false, this method will return null if User object with the given name doesn't exist.

get

public static User get(String idOrFullName,
                       boolean create,
                       Map context)
Gets the User object by its id or full name.

Parameters:
create - If true, this method will never return null for valid input (by creating a new User object if none exists.) If false, this method will return null if User object with the given name doesn't exist.
context - contextual environment this user idOfFullName was retrieved from, that can help resolve the user ID

get

@Nonnull
public static User get(String idOrFullName)
Gets the User object by its id or full name.


current

@CheckForNull
public static User current()
Gets the User object representing the currently logged-in user, or null if the current user is anonymous.

Since:
1.172

getAll

public static Collection<User> getAll()
Gets all the users.


reload

public static void reload()
Reloads the configuration from disk.


clear

public static void clear()
Stop gap hack. Don't use it. To be removed in the trunk.


getDisplayName

public String getDisplayName()
Returns the user name.

Specified by:
getDisplayName in interface ModelObject

getBuilds

@WithBridgeMethods(value=java.util.List.class)
public RunList getBuilds()
Gets the list of Builds that include changes by this user, by the timestamp order. TODO: do we need some index for this?


getProjects

public Set<AbstractProject<?,?>> getProjects()
Gets all the AbstractProjects that this user has committed to.

Since:
1.191

toString

public String toString()
Overrides:
toString in class Object

getConfigFile

protected final XmlFile getConfigFile()
The file we save our configuration.


save

public void save()
          throws IOException
Save the settings to a file.

Specified by:
save in interface Saveable
Throws:
IOException - if the persistence failed.

delete

public void delete()
            throws IOException
Deletes the data directory and removes this user from Hudson.

Throws:
IOException - if we fail to delete.

getApi

public Api getApi()
Exposed remote API.


doConfigSubmit

public void doConfigSubmit(org.kohsuke.stapler.StaplerRequest req,
                           org.kohsuke.stapler.StaplerResponse rsp)
                    throws IOException,
                           javax.servlet.ServletException,
                           Descriptor.FormException
Accepts submission from the configuration page.

Throws:
IOException
javax.servlet.ServletException
Descriptor.FormException

doDoDelete

public void doDoDelete(org.kohsuke.stapler.StaplerRequest req,
                       org.kohsuke.stapler.StaplerResponse rsp)
                throws IOException,
                       javax.servlet.ServletException
Deletes this user from Hudson.

Throws:
IOException
javax.servlet.ServletException

doRssAll

public void doRssAll(org.kohsuke.stapler.StaplerRequest req,
                     org.kohsuke.stapler.StaplerResponse rsp)
              throws IOException,
                     javax.servlet.ServletException
Throws:
IOException
javax.servlet.ServletException

doRssFailed

public void doRssFailed(org.kohsuke.stapler.StaplerRequest req,
                        org.kohsuke.stapler.StaplerResponse rsp)
                 throws IOException,
                        javax.servlet.ServletException
Throws:
IOException
javax.servlet.ServletException

doRssLatest

public void doRssLatest(org.kohsuke.stapler.StaplerRequest req,
                        org.kohsuke.stapler.StaplerResponse rsp)
                 throws IOException,
                        javax.servlet.ServletException
Throws:
IOException
javax.servlet.ServletException

getACL

public ACL getACL()
Description copied from interface: AccessControlled
Obtains the ACL associated with this object.

Specified by:
getACL in interface AccessControlled
Returns:
never null.

checkPermission

public void checkPermission(Permission permission)
Description copied from interface: AccessControlled
Convenient short-cut for getACL().checkPermission(permission)

Specified by:
checkPermission in interface AccessControlled

hasPermission

public boolean hasPermission(Permission permission)
Description copied from interface: AccessControlled
Convenient short-cut for getACL().hasPermission(permission)

Specified by:
hasPermission in interface AccessControlled

canDelete

public boolean canDelete()
With ADMINISTER permission, can delete users with persisted data but can't delete self.


getAuthorities

@Nonnull
public List<String> getAuthorities()
Checks for authorities (groups) associated with this user. If the caller lacks Jenkins.ADMINISTER, or any problems arise, returns an empty list. SecurityRealm.AUTHENTICATED_AUTHORITY and the username, if present, are omitted.

Returns:
a possibly empty list
Since:
1.498

getDescriptorByName

public Descriptor getDescriptorByName(String className)
Description copied from interface: DescriptorByNameOwner
Exposes all Descriptors by its name to URL.

Implementation should always delegate to Jenkins.getDescriptorByName(String).

Specified by:
getDescriptorByName in interface DescriptorByNameOwner
Parameters:
className - Either Descriptor.getId() (recommended) or the short name.

getDynamic

public Object getDynamic(String token)

getPropertyActions

public List<Action> getPropertyActions()
Return all properties that are also actions.

Returns:
the list can be empty but never null. read only.

getTransientActions

public List<Action> getTransientActions()
Return all transient actions associated with this user.

Returns:
the list can be empty but never null. read only.


Copyright © 2004-2013. All Rights Reserved.