hudson.model.Hudson.getAuthentication()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(156)

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

Hudson.getAuthentication介绍

[英]Gets the Authentication object that represents the user associated with the current request.
[中]获取表示与当前请求关联的用户的身份验证对象。

代码示例

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

/**
 * Checks if the current user is anonymous.
 */
public static boolean isAnonymous() {
  return Hudson.getAuthentication() instanceof AnonymousAuthenticationToken;
}

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

/**
 * Checks if the current security principal has this permission.
 *
 * @return false
 *      if the user doesn't have the permission.
 */
public final boolean hasPermission(Permission p) {
  return hasPermission(Hudson.getAuthentication(),p);
}

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

/**
 * If the current thread carries the {@link CNAuthentication} object as the context,
 * returns it. Or else null.
 */
public static CNAuthentication get() {
  return cast(Hudson.getAuthentication());
}

代码示例来源:origin: org.jvnet.hudson.plugins/favorite

public boolean isLoggedIn() {
    Authentication authentication = Hudson.getAuthentication();
    if (authentication.getName().equals("anonymous")) {
      return false;
    } else {
      return true;
    }
  }
}

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

/**
 * Checks if the current security principal has this permission.
 *
 * @return false
 *      if the user doesn't have the permission.
 */
public final boolean hasPermission(Permission p) {
  return hasPermission(Hudson.getAuthentication(),p);
}

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

/**
 * With ADMINISTER permission, can delete users with persisted data but can't delete self.
 */
public boolean canDelete() {
  return hasPermission(Hudson.ADMINISTER) && !id.equals(Hudson.getAuthentication().getName())
      && new File(getRootDir(), id).exists();
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-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 User current() {
  Authentication a = Hudson.getAuthentication();
  if(a instanceof AnonymousAuthenticationToken)
    return null;
  return get(a.getName());
}

代码示例来源:origin: com.marvelution.jira.plugins/jenkins-jira-plugin

/**
 * Check if the current user has the given {@link Permission} on the {@link AccessControlled} object given
 *
 * @param ac         the {@link AccessControlled} object
 * @param permission the {@link Permission}
 * @param <AC>
 * @return {@code true} if the user has the {@link Permission}, {@code false} otherwise
 */
protected <AC extends AccessControlled> boolean hasPermission(AC ac, Permission permission) {
  Authentication authentication = Hudson.getAuthentication();
  return authentication != Hudson.ANONYMOUS && ac.getACL().hasPermission(authentication, permission);
}

代码示例来源:origin: com.marvelution.jira.plugins/jenkins-jira-plugin

/**
 * Check if the current user has the given {@link Permission} on the {@link AccessControlled} object given
 *
 * @param ac         the {@link AccessControlled} object
 * @param permission the {@link Permission}
 * @param <AC>
 * @return {@code true} if the user has the {@link Permission}, {@code false} otherwise
 */
protected <AC extends AccessControlled> boolean hasPermission(AC ac, Permission permission) {
  return ac.getACL().hasPermission(Hudson.getAuthentication(), permission);
}

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

protected void main(Channel channel) throws IOException, InterruptedException {
    // capture the identity given by the transport, since this can be useful for SecurityRealm.createCliAuthenticator()
    channel.setProperty(CLICommand.TRANSPORT_AUTHENTICATION, getAuthentication());
    channel.setProperty(CliEntryPoint.class.getName(), new CliManagerImpl());
  }
});

代码示例来源:origin: hudson/hudson-2.x

protected void main(Channel channel) throws IOException, InterruptedException {
    // capture the identity given by the transport, since this can be useful for SecurityRealm.createCliAuthenticator()
    channel.setProperty(CLICommand.TRANSPORT_AUTHENTICATION, getAuthentication());
    channel.setProperty(CliEntryPoint.class.getName(), new CliManagerImpl());
  }
});

代码示例来源:origin: jenkinsci/promoted-builds-plugin

public boolean isInGroupList() {
  Set<String> groups = getUsersAsSet();
  GrantedAuthority[] authorities = Hudson.getAuthentication().getAuthorities();
  for (GrantedAuthority authority : authorities) {
    if (groups.contains(authority.getAuthority()))
      return true;
  }
  return false;
}

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

protected void main(Channel channel) throws IOException, InterruptedException {
    // capture the identity given by the transport, since this can be useful for SecurityRealm.createCliAuthenticator()
    channel.setProperty(CLICommand.TRANSPORT_AUTHENTICATION, getAuthentication());
    channel.setProperty(CliEntryPoint.class.getName(), new CliManagerImpl());
  }
});

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

@Override
protected int run() throws Exception {
  Authentication a = Hudson.getAuthentication();
  if (a==Hudson.ANONYMOUS)
    throw new CmdLineException("No credentials specified."); // this causes CLI to show the command line options.
  ClientAuthenticationCache store = new ClientAuthenticationCache(channel);
  store.set(a);
  return 0;
}

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

@Override
  protected int run() throws Exception {
    Authentication a = Hudson.getAuthentication();
    if (a == HudsonSecurityManager.ANONYMOUS) {
      throw new CmdLineException("No credentials specified."); // this causes CLI to show the command line options.
    }
    ClientAuthenticationCache store = new ClientAuthenticationCache(channel);
    store.set(a);

    return 0;
  }
}

代码示例来源:origin: hudson/hudson-2.x

@Override
protected int run() throws Exception {
  Authentication a = Hudson.getAuthentication();
  if (a==Hudson.ANONYMOUS)
    throw new CmdLineException("No credentials specified."); // this causes CLI to show the command line options.
  ClientAuthenticationCache store = new ClientAuthenticationCache(channel);
  store.set(a);
  return 0;
}

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

public HttpResponse doDoDisconnect(@QueryParameter String offlineMessage) throws IOException, ServletException {
  if (channel!=null) {
    //does nothing in case computer is already disconnected
    checkPermission(Hudson.ADMINISTER);
    offlineMessage = Util.fixEmptyAndTrim(offlineMessage);
    disconnect(OfflineCause.create(Messages._SlaveComputer_DisconnectedBy(
        Hudson.getAuthentication().getName(),
        offlineMessage!=null ? " : " + offlineMessage : "")
    ));
  }
  return new HttpRedirect(".");
}

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

public HttpResponse doDoDisconnect(@QueryParameter String offlineMessage) throws IOException, ServletException {
  if (channel!=null) {
    //does nothing in case computer is already disconnected
    checkPermission(Hudson.ADMINISTER);
    offlineMessage = Util.fixEmptyAndTrim(offlineMessage);
    disconnect(OfflineCause.create(Messages._SlaveComputer_DisconnectedBy(
        Hudson.getAuthentication().getName(),
        offlineMessage!=null ? " : " + offlineMessage : "")
    ));
  }
  return new HttpRedirect(".");
}

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

/**
 * Schedules the downgrade of this plugin.
 */
public Future<UpdateCenterJob> deployBackup() {
  Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
  UpdateCenter uc = Hudson.getInstance().getUpdateCenter();
  return uc.addJob(uc.new PluginDowngradeJob(this, UpdateSite.this, Hudson.getAuthentication()));
}
/**

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

/**
 * Schedules the downgrade of this plugin.
 */
public Future<UpdateCenterJob> deployBackup() {
  Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
  UpdateCenter uc = Hudson.getInstance().getUpdateCenter();
  return uc.addJob(uc.new PluginDowngradeJob(this, UpdateSite.this, Hudson.getAuthentication()));
}
/**

相关文章

Hudson类方法