jenkins.model.Jenkins.getAuthentication()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(397)

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

Jenkins.getAuthentication介绍

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

代码示例

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

  1. /**
  2. * Returns all the registered {@link TopLevelItemDescriptor}s that the current security principal is allowed to
  3. * create within the specified item group.
  4. *
  5. * @since 1.607
  6. */
  7. public static List<TopLevelItemDescriptor> all(ItemGroup c) {
  8. return all(Jenkins.getAuthentication(), c);
  9. }

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

  1. /**
  2. * Gets the {@link User} object representing the currently logged-in user, or null
  3. * if the current user is anonymous.
  4. *
  5. * @since 1.172
  6. */
  7. public static @CheckForNull
  8. User current() {
  9. return get(Jenkins.getAuthentication());
  10. }

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

  1. /**
  2. * Checks if the current user is anonymous.
  3. */
  4. public static boolean isAnonymous() {
  5. return ACL.isAnonymous(Jenkins.getAuthentication());
  6. }

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

  1. /**
  2. * Checks if the current security principal has this permission.
  3. *
  4. * @return false
  5. * if the user doesn't have the permission.
  6. */
  7. public final boolean hasPermission(@Nonnull Permission p) {
  8. Authentication a = Jenkins.getAuthentication();
  9. if (a == SYSTEM) {
  10. return true;
  11. }
  12. return hasPermission(a, p);
  13. }

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

  1. public RestartJenkinsJob(UpdateSite site) {
  2. super(site);
  3. this.authentication = Jenkins.getAuthentication().getName();
  4. }

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

  1. /**
  2. * Extension point to allow implementations of {@link UpdateSite} to create a custom
  3. * {@link UpdateCenter.InstallationJob}.
  4. *
  5. * @param plugin the plugin to create the {@link UpdateCenter.InstallationJob} for.
  6. * @param uc the {@link UpdateCenter}.
  7. * @param dynamicLoad {@code true} if the plugin should be attempted to be dynamically loaded.
  8. * @return the {@link UpdateCenter.InstallationJob}.
  9. * @since 2.9
  10. */
  11. protected UpdateCenter.InstallationJob createInstallationJob(Plugin plugin, UpdateCenter uc, boolean dynamicLoad) {
  12. return uc.new InstallationJob(plugin, this, Jenkins.getAuthentication(), dynamicLoad);
  13. }

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

  1. public UserCause() {
  2. this.authenticationName = Jenkins.getAuthentication().getName();
  3. }

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

  1. protected int run() {
  2. Authentication a = Jenkins.getAuthentication();
  3. stdout.println("Authenticated as: "+a.getName());
  4. stdout.println("Authorities:");
  5. for (GrantedAuthority ga : a.getAuthorities()) {
  6. stdout.println(" "+ga.getAuthority());
  7. }
  8. return 0;
  9. }
  10. }

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

  1. @Override
  2. public void run() {
  3. try {
  4. ACL.impersonate(ACL.SYSTEM);
  5. LOGGER.info(String.format("Shutting down VM as requested by %s from %s",
  6. getAuthentication().getName(), req != null ? req.getRemoteAddr() : "???"));
  7. cleanUp();
  8. System.exit(0);
  9. } catch (Exception e) {
  10. LOGGER.log(Level.WARNING, "Failed to shut down Jenkins", e);
  11. }
  12. }
  13. }.start();

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

  1. @SuppressWarnings("deprecation")
  2. @Override
  3. protected void main(Channel channel) throws IOException, InterruptedException {
  4. // capture the identity given by the transport, since this can be useful for SecurityRealm.createCliAuthenticator()
  5. channel.setProperty(CLICommand.TRANSPORT_AUTHENTICATION, Jenkins.getAuthentication());
  6. channel.setProperty(CliEntryPoint.class.getName(), new CliManagerImpl(channel));
  7. }
  8. };

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

  1. /**
  2. * Logs out the user.
  3. */
  4. public void doLogout( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
  5. String user = getAuthentication().getName();
  6. securityRealm.doLogout(req, rsp);
  7. SecurityListener.fireLoggedOut(user);
  8. }

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

  1. /**
  2. * Performs hudson downgrade.
  3. */
  4. @RequirePOST
  5. public void doRestart(StaplerResponse rsp) throws IOException, ServletException {
  6. HudsonDowngradeJob job = new HudsonDowngradeJob(getCoreSource(), Jenkins.getAuthentication());
  7. LOGGER.info("Scheduling the core downgrade");
  8. addJob(job);
  9. rsp.sendRedirect2(".");
  10. }

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

  1. private void interrupt(Result result, boolean forShutdown) {
  2. Authentication a = Jenkins.getAuthentication();
  3. if (a == ACL.SYSTEM)
  4. interrupt(result, forShutdown, new CauseOfInterruption[0]);
  5. else {
  6. // worth recording who did it
  7. // avoid using User.get() to avoid deadlock.
  8. interrupt(result, forShutdown, new UserInterruption(a.getName()));
  9. }
  10. }

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

  1. /**
  2. * Performs hudson downgrade.
  3. */
  4. @RequirePOST
  5. public void doDowngrade(StaplerResponse rsp) throws IOException, ServletException {
  6. if(!isDowngradable()) {
  7. sendError("Jenkins downgrade is not possible, probably backup does not exist");
  8. return;
  9. }
  10. HudsonDowngradeJob job = new HudsonDowngradeJob(getCoreSource(), Jenkins.getAuthentication());
  11. LOGGER.info("Scheduling the core downgrade");
  12. addJob(job);
  13. rsp.sendRedirect2(".");
  14. }

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

  1. @Override
  2. protected int run() throws Exception {
  3. Authentication a = Jenkins.getAuthentication();
  4. if (a== Jenkins.ANONYMOUS)
  5. throw new CmdLineException("No credentials specified."); // this causes CLI to show the command line options.
  6. ClientAuthenticationCache store = new ClientAuthenticationCache(checkChannel());
  7. store.set(a);
  8. SecurityListener.fireLoggedIn(a.getName());
  9. return 0;
  10. }

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

  1. /**
  2. * With ADMINISTER permission, can delete users with persisted data but can't delete self.
  3. */
  4. public boolean canDelete() {
  5. final IdStrategy strategy = idStrategy();
  6. return hasPermission(Jenkins.ADMINISTER) && !strategy.equals(id, Jenkins.getAuthentication().getName())
  7. && UserIdMapper.getInstance().isMapped(id);
  8. }

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

  1. /**
  2. * Schedules the downgrade of this plugin.
  3. */
  4. public Future<UpdateCenterJob> deployBackup() {
  5. Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
  6. UpdateCenter uc = Jenkins.getInstance().getUpdateCenter();
  7. return uc.addJob(uc.new PluginDowngradeJob(this, UpdateSite.this, Jenkins.getAuthentication()));
  8. }
  9. /**

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

  1. /**
  2. * Schedules a Jenkins upgrade.
  3. */
  4. @RequirePOST
  5. public void doUpgrade(StaplerResponse rsp) throws IOException, ServletException {
  6. HudsonUpgradeJob job = new HudsonUpgradeJob(getCoreSource(), Jenkins.getAuthentication());
  7. if(!Lifecycle.get().canRewriteHudsonWar()) {
  8. sendError("Jenkins upgrade not supported in this running mode");
  9. return;
  10. }
  11. LOGGER.info("Scheduling the core upgrade");
  12. addJob(job);
  13. rsp.sendRedirect2(".");
  14. }

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

  1. /**
  2. * Deletes this user from Hudson.
  3. */
  4. @RequirePOST
  5. public void doDoDelete(StaplerRequest req, StaplerResponse rsp) throws IOException {
  6. checkPermission(Jenkins.ADMINISTER);
  7. if (idStrategy().equals(id, Jenkins.getAuthentication().getName())) {
  8. rsp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Cannot delete self");
  9. return;
  10. }
  11. delete();
  12. rsp.sendRedirect2("../..");
  13. }

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

  1. @Restricted(NoExternalUse.class)
  2. public boolean hasCurrentUserRightToGenerateNewToken(User propertyOwner){
  3. if (ADMIN_CAN_GENERATE_NEW_TOKENS && Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
  4. return true;
  5. }
  6. User currentUser = User.current();
  7. if (currentUser == null) {
  8. // Anonymous
  9. return false;
  10. }
  11. if (Jenkins.getAuthentication() == ACL.SYSTEM) {
  12. // SYSTEM user is always eligible to see tokens
  13. return true;
  14. }
  15. return User.idStrategy().equals(propertyOwner.getId(), currentUser.getId());
  16. }

相关文章

Jenkins类方法