@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
|
static class |
User.UserIDCanonicalIdResolver
Tries to verify if an ID is valid.
|
ModelObjectWithContextMenu.ContextMenu, ModelObjectWithContextMenu.ContextMenuVisibility, ModelObjectWithContextMenu.MenuItem| Modifier and Type | Field and Description |
|---|---|
static boolean |
ALLOW_NON_EXISTENT_USER_TO_LOGIN
Jenkins now refuses to let the user login if he/she doesn't exist in
SecurityRealm,
which was necessary to make sure users removed from the backend will get removed from the frontend. |
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(org.acegisecurity.Authentication a)
Gets the
User object representing the supplied Authentication or
null if the supplied Authentication is either anonymous or null |
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
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. |
static User |
getById(String id,
boolean create)
Gets the
User object by its id |
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> |
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 boolean |
isIdOrFullnameAllowed(String id)
Is the ID allowed? Some are prohibited for security reasons.
|
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 |
setDescription(String description)
Sets the description of the user.
|
void |
setFullName(String name)
Sets the human readable name of the user.
|
String |
toString() |
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendErrorpublic static final XStream2 XSTREAM
public static boolean ALLOW_NON_EXISTENT_USER_TO_LOGIN
SecurityRealm,
which was necessary to make sure users removed from the backend will get removed from the frontend.
Unfortunately this infringed some legitimate use cases of creating Jenkins-local users for automation purposes. This escape hatch switch can be enabled to resurrect that behaviour. JENKINS-22346.
@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()
@Nonnull public String getSearchUrl()
SearchItemSearchItem.getSearchUrl in interface SearchItem@Exported(visibility=999) @Nonnull public String getAbsoluteUrl()
@Exported(visibility=999) @Nonnull public String getFullName()
public void setFullName(String name)
@Exported @CheckForNull public String getDescription()
public void setDescription(String description)
public Map<Descriptor<UserProperty>,UserProperty> getProperties()
public void addProperty(@Nonnull UserProperty p) throws IOException
IOException@Exported(name="property",
inline=true)
public List<UserProperty> getAllProperties()
UserPropertys exposed primarily for the remoting API.public <T extends UserProperty> T getProperty(Class<T> clazz)
@Nonnull 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
IOExceptionjavax.servlet.ServletException@Nonnull public static User getUnknown()
This is used to avoid null User instance.
@Deprecated @Nullable public static User get(String idOrFullName, boolean create)
get(String, boolean, java.util.Map)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.null if a user does not exist and
create is false.@Nullable 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 IDnull if a user does not exist and
create is false.@Nonnull public static User get(String idOrFullName)
User object by its id or full name.
Use getById(java.lang.String, boolean) when you know you have an ID.@CheckForNull public static User current()
User object representing the currently logged-in user, or null
if the current user is anonymous.@CheckForNull public static User get(@CheckForNull org.acegisecurity.Authentication a)
User object representing the supplied Authentication or
null if the supplied Authentication is either anonymous or nulla - the supplied Authentication .User object for the supplied Authentication or null@Nullable public static User getById(String id, boolean create)
User object by its idid - the id of the user to retrieve and optionally create if it does not exist.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 id doesn't exist.id, or null if create is false
and the user does not exist.@Nonnull public static Collection<User> getAll()
public static void reload()
public static void clear()
public static void rekey()
IdStrategy.@Nonnull public String getDisplayName()
getDisplayName in interface ModelObject@WithBridgeMethods(value=java.util.List.class) @Nonnull public RunList getBuilds()
Builds that include changes by this user,
by the timestamp order.@Nonnull public Set<AbstractProject<?,?>> getProjects()
AbstractProjects that this user has committed to.protected final XmlFile getConfigFile()
public static boolean isIdOrFullnameAllowed(String id)
public void save()
throws IOException,
FormValidation
save in interface SaveableIOException - if the persistence failed.FormValidationpublic 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
IOExceptionjavax.servlet.ServletExceptionDescriptor.FormExceptionpublic void doDoDelete(org.kohsuke.stapler.StaplerRequest req,
org.kohsuke.stapler.StaplerResponse rsp)
throws IOException,
javax.servlet.ServletException
IOExceptionjavax.servlet.ServletExceptionpublic void doRssAll(org.kohsuke.stapler.StaplerRequest req,
org.kohsuke.stapler.StaplerResponse rsp)
throws IOException,
javax.servlet.ServletException
IOExceptionjavax.servlet.ServletExceptionpublic void doRssFailed(org.kohsuke.stapler.StaplerRequest req,
org.kohsuke.stapler.StaplerResponse rsp)
throws IOException,
javax.servlet.ServletException
IOExceptionjavax.servlet.ServletExceptionpublic void doRssLatest(org.kohsuke.stapler.StaplerRequest req,
org.kohsuke.stapler.StaplerResponse rsp)
throws IOException,
javax.servlet.ServletException
IOExceptionjavax.servlet.ServletExceptionpublic ACL getACL()
AccessControlledgetACL in interface AccessControlledpublic void checkPermission(Permission permission)
AccessControlledgetACL().checkPermission(permission)checkPermission in interface AccessControlledpublic boolean hasPermission(Permission permission)
AccessControlledgetACL().hasPermission(permission)hasPermission in interface AccessControlledpublic 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)
DescriptorByNameOwnerDescriptors by its name to URL.
Implementation should always delegate to Jenkins.getDescriptorByName(String).
getDescriptorByName in interface DescriptorByNameOwnerclassName - 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
ModelObjectWithContextMenureturn 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 ModelObjectWithContextMenuExceptionCopyright © 2019. All rights reserved.