@ExportedBean public class User extends AbstractModelObject implements AccessControlled, DescriptorByNameOwner, Saveable, Comparable<User>, ModelObjectWithContextMenu
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.)
Modifier and Type | Class and Description |
---|---|
static class |
User.CanonicalIdResolver |
static class |
User.FullNameIdResolver
Resolve user ID from full name
|
ModelObjectWithContextMenu.ContextMenu, ModelObjectWithContextMenu.ContextMenuVisibility, ModelObjectWithContextMenu.MenuItem
Modifier and Type | Field and Description |
---|---|
static XStream2 |
XSTREAM
Used to load/save user configuration.
|
Modifier and Type | Method and Description |
---|---|
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.
|
ModelObjectWithContextMenu.ContextMenu |
doContextMenu(org.kohsuke.stapler.StaplerRequest request,
org.kohsuke.stapler.StaplerResponse response)
Generates the context menu.
|
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.
|
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
UserProperty s 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
Build s 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
Descriptor s 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
AbstractProject s that this user has committed to. |
Map<Descriptor<UserProperty>,UserProperty> |
getProperties()
Gets the user properties configured for this user.
|
<T extends UserProperty> |
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) |
static IdStrategy |
idStrategy()
Returns the
IdStrategy for use with User instances. |
org.acegisecurity.Authentication |
impersonate()
Creates an
Authentication object that represents this user. |
static void |
rekey()
Called when changing the
IdStrategy . |
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() |
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError
public static final XStream2 XSTREAM
@Nonnull public static IdStrategy idStrategy()
IdStrategy
for use with User
instances.public int compareTo(User that)
compareTo
in interface Comparable<User>
@Exported public String getId()
public String getUrl()
public String getSearchUrl()
SearchItem
SearchItem
.getSearchUrl
in interface SearchItem
@Exported(visibility=999) public String getAbsoluteUrl()
@Exported(visibility=999) public String getFullName()
public void setFullName(String name)
@Exported public String getDescription()
public Map<Descriptor<UserProperty>,UserProperty> getProperties()
public void addProperty(UserProperty p) throws IOException
IOException
@Exported(name="property", inline=true) public List<UserProperty> getAllProperties()
UserProperty
s exposed primarily for the remoting API.public <T extends UserProperty> T getProperty(Class<T> clazz)
public org.acegisecurity.Authentication impersonate() throws org.acegisecurity.userdetails.UsernameNotFoundException
Authentication
object that represents this user.
This method checks with SecurityRealm
if the user is a valid user that can login to the security realm.
If SecurityRealm
is a kind that does not support querying information about other users, this will
use LastGrantedAuthoritiesProperty
to pick up the granted authorities as of the last time the user has
logged in.org.acegisecurity.userdetails.UsernameNotFoundException
- If this user is not a valid user in the backend SecurityRealm
.public void doSubmitDescription(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
@Nonnull public static User getUnknown()
This is used to avoid null User
instance.
public static User get(String idOrFullName, boolean create)
get(String, boolean, java.util.Map)
User
object by its id or full name.public static User get(String idOrFullName, boolean create, Map context)
User
object by its id or full name.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@Nonnull public static User get(String idOrFullName)
User
object by its id or full name.@CheckForNull public static User current()
User
object representing the currently logged-in user, or null
if the current user is anonymous.public static Collection<User> getAll()
public static void reload()
public static void clear()
public static void rekey()
IdStrategy
.public String getDisplayName()
getDisplayName
in interface ModelObject
@WithBridgeMethods(value=java.util.List.class) public RunList getBuilds()
Build
s that include changes by this user,
by the timestamp order.public Set<AbstractProject<?,?>> getProjects()
AbstractProject
s that this user has committed to.protected final XmlFile getConfigFile()
public void save() throws IOException
save
in interface Saveable
IOException
- if the persistence failed.public void delete() throws IOException
IOException
- if we fail to delete.public Api getApi()
public void doConfigSubmit(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException, Descriptor.FormException
IOException
javax.servlet.ServletException
Descriptor.FormException
public void doDoDelete(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public void doRssAll(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public void doRssFailed(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public void doRssLatest(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
IOException
javax.servlet.ServletException
public ACL getACL()
AccessControlled
getACL
in interface AccessControlled
public void checkPermission(Permission permission)
AccessControlled
getACL().checkPermission(permission)
checkPermission
in interface AccessControlled
public boolean hasPermission(Permission permission)
AccessControlled
getACL().hasPermission(permission)
hasPermission
in interface AccessControlled
public boolean canDelete()
@Nonnull public List<String> getAuthorities()
Jenkins.ADMINISTER
, or any problems arise, returns an empty list.
SecurityRealm.AUTHENTICATED_AUTHORITY
and the username, if present, are omitted.public Descriptor getDescriptorByName(String className)
DescriptorByNameOwner
Descriptor
s by its name to URL.
Implementation should always delegate to Jenkins.getDescriptorByName(String)
.
getDescriptorByName
in interface DescriptorByNameOwner
className
- Either Descriptor.getId()
(recommended) or the short name.public List<Action> getPropertyActions()
public List<Action> getTransientActions()
public ModelObjectWithContextMenu.ContextMenu doContextMenu(org.kohsuke.stapler.StaplerRequest request, org.kohsuke.stapler.StaplerResponse response) throws Exception
ModelObjectWithContextMenu
return new ContextMenu().from(this,request,response);
,
which implements the default behaviour. See ModelObjectWithContextMenu.ContextMenu.from(ModelObjectWithContextMenu, StaplerRequest, StaplerResponse)
for more details of what it does. This should suit most implementations.doContextMenu
in interface ModelObjectWithContextMenu
Exception
Copyright © 2014. All rights reserved.