@SuppressWarnings("deprecation") private Object readResolve() throws ObjectStreamException { if (user != null) { String id = user.getId(); if (id != null) { userId = id; } else { // The user field is not properly deserialized so id may be missing. Look the user up by fullname User user = User.get(this.user.getFullName(), true, Collections.emptyMap()); userId = user.getId(); } this.user = null; } return this; } }
/** * Gets user, who caused the interruption. * @return User or {@code null} if it has not been found * @since 2.31 */ @CheckForNull public User getUserOrNull() { return User.get(user, false, Collections.emptyMap()); }
@Override public String getShortDescription() { User user = User.get(startedBy, false); String userName = user != null ? user.getDisplayName() : startedBy; return Messages.BuildCommand_CLICause_ShortDescription(userName); }
@Override public boolean hasPermission(@Nonnull Authentication a, @Nonnull Permission permission) { return user.equals(User.get(a.getName())) && user.getACL().hasPermission(a, permission); } };
/** * Gets the {@link User} object by its id or full name. * * @param create If true, this method will never return null for valid input * (by creating a new {@link User} object if none exists.) * If false, this method will return null if {@link User} object * with the given name doesn't exist. * @return Requested user. May be {@code null} if a user does not exist and * {@code create} is false. * @deprecated use {@link User#get(String, boolean, java.util.Map)} */ @Deprecated public static @Nullable User get(String idOrFullName, boolean create) { return get(idOrFullName, create, Collections.emptyMap()); }
@Exported(visibility=3) public String getUserName() { User u = User.get(authenticationName, false); return u != null ? u.getDisplayName() : authenticationName; }
/** * Get the user by ID or Full Name. * <p> * If the user does not exist, creates a new one on-demand. * * <p> * Use {@link #getById} when you know you have an ID. * In this method Jenkins will try to resolve the {@link User} by full name with help of various * {@link hudson.tasks.UserNameResolver}. * This is slow (see JENKINS-23281). * * @param idOrFullName User ID or full name * @return User instance. It will be created on-demand. * @since 2.91 */ public static @Nonnull User getOrCreateByIdOrFullName(@Nonnull String idOrFullName) { return get(idOrFullName, true, Collections.emptyMap()); }
@Override public String getShortDescription() { User user = User.get(startedBy, false); String userName = user != null ? user.getDisplayName() : startedBy; return Messages.BuildCommand_CLICause_ShortDescription(userName); }
/** * Gets the user of the given name. * * @return the user of the given name (which may or may not be an id), if that person exists; else null * @see User#get(String,boolean) * @see User#getById(String, boolean) */ public @CheckForNull User getUser(String name) { return User.get(name, User.ALLOW_USER_CREATION_VIA_URL && hasPermission(ADMINISTER)); }
/** * Gets the {@link User} object representing the currently logged-in user, or null * if the current user is anonymous. * * @since 1.172 */ public static @CheckForNull User current() { return get(Jenkins.getAuthentication()); }
public synchronized void run() { if (!(status instanceof Pending)) { return; } status = new Running(); try { // safeRestart records the current authentication for the log, so set it to the managing user try (ACLContext acl = ACL.as(User.get(authentication, false, Collections.emptyMap()))) { Jenkins.getInstance().safeRestart(); } } catch (RestartNotSupportedException exception) { // ignore if restart is not allowed status = new Failure(); error = exception; } }
/** * Gets the {@link User} object by its id or full name. */ public static User get(String idOrFullName) { return get(idOrFullName, true); }
/** * Gets the fallback "unknown" user instance. <p> This is used to avoid null * {@link User} instance. */ public static User getUnknown() { return get("unknown"); }
/** * Gets the {@link User} object by its id or full name. * Use {@link #getById} when you know you have an ID. */ public static @Nonnull User get(String idOrFullName) { return get(idOrFullName,true); }
/** * Gets user, who caused the interruption. * @return User or {@code null} if it has not been found * @since 2.31 */ @CheckForNull public User getUserOrNull() { return User.get(user, false, Collections.emptyMap()); }
/** * Gets the user of the given name. * * @return the user of the given name (which may or may not be an id), if that person exists; else null * @see User#get(String,boolean) * @see User#getById(String, boolean) */ public @CheckForNull User getUser(String name) { return User.get(name, User.ALLOW_USER_CREATION_VIA_URL && hasPermission(ADMINISTER)); }
/** * Gets the {@link User} object representing the currently logged-in user, or null * if the current user is anonymous. * @since 1.172 */ public static @CheckForNull User current() { return get(Jenkins.getAuthentication()); }
/** * Gets the user who rejected this. */ @Exported public @CheckForNull User getUser() { return userName != null ? User.get(userName) : null; }
/** * Creates a new user account by registering a password to the user. * @param userName * @param password * @return * @throws java.io.IOException */ public User createAccount(String userName, String password) throws IOException { User user = User.get(userName); user.addProperty(Details.fromPlainPassword(password)); return user; }
private static boolean canRestart(WorkflowRun b, String user) { final RestartDeclarativePipelineAction a = b.getAction(RestartDeclarativePipelineAction.class); return ACL.impersonate(User.get(user).impersonate(), new NotReallyRoleSensitiveCallable<Boolean,RuntimeException>() { @Override public Boolean call() throws RuntimeException { return a.isRestartEnabled(); } }); }