hudson.model.User.get()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中hudson.model.User.get()方法的一些代码示例,展示了User.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。User.get()方法的具体详情如下:
包路径:hudson.model.User
类名称:User
方法名:get

User.get介绍

[英]Gets the User object by its id or full name.

Creates a user on-demand.

Use #getById when you know you have an ID. In this method Jenkins will try to resolve the User by full name with help of various hudson.tasks.UserNameResolver. This is slow (see JENKINS-23281).
[中]按id或全名获取用户对象。
按需创建用户。
当你知道自己有一个ID时,使用#getById。在这个方法中,Jenkins会在各种hudson的帮助下,尝试通过全名解析用户。任务。用户名解析程序。这很慢(见JENKINS-23281)。

代码示例

代码示例来源:origin: jenkinsci/jenkins

@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;
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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());
}

代码示例来源:origin: jenkinsci/jenkins

@Override
public String getShortDescription() {
  User user = User.get(startedBy, false);
  String userName = user != null ? user.getDisplayName() : startedBy;
  return Messages.BuildCommand_CLICause_ShortDescription(userName);
}

代码示例来源:origin: org.jenkins-ci.plugins/credentials

@Override
  public boolean hasPermission(@Nonnull Authentication a, @Nonnull Permission permission) {
    return user.equals(User.get(a.getName())) && user.getACL().hasPermission(a, permission);
  }
};

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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());
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

@Exported(visibility=3)
public String getUserName() {
  User u = User.get(authenticationName, false);
  return u != null ? u.getDisplayName() : authenticationName;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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());
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override
public String getShortDescription() {
  User user = User.get(startedBy, false);
  String userName = user != null ? user.getDisplayName() : startedBy;
  return Messages.BuildCommand_CLICause_ShortDescription(userName);
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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));
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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());
}

代码示例来源:origin: jenkinsci/jenkins

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;
  }
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

/**
 * Gets the {@link User} object by its id or full name.
 */
public static User get(String idOrFullName) {
  return get(idOrFullName, true);
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

/**
 * Gets the fallback "unknown" user instance. <p> This is used to avoid null
 * {@link User} instance.
 */
public static User getUnknown() {
  return get("unknown");
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * 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);
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * 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());
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * 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));
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * 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());
}

代码示例来源:origin: org.jenkins-ci.plugins/pipeline-input-step

/**
 * Gets the user who rejected this.
 */
@Exported
public @CheckForNull User getUser() {
  return userName != null ? User.get(userName) : null;
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

/**
 * 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;
}

代码示例来源:origin: jenkinsci/pipeline-model-definition-plugin

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();
    }
  });
}

相关文章