/** * Checks if the current user is anonymous. */ public static boolean isAnonymous() { return HudsonSecurityManager.getAuthentication() instanceof AnonymousAuthenticationToken; }
/** * @deprecated As of release 3.0.0, replaced by * {@link HudsonSecurityManager#getAuthentication()} */ @Deprecated public static Authentication getAuthentication() { return HudsonSecurityManager.getAuthentication(); }
private Collection<? extends GrantedAuthority> getCurrentUserRoles() { Authentication authentication = HudsonSecurityManager.getAuthentication(); return authentication.getAuthorities(); }
private String getCurrentUser() { Authentication authentication = HudsonSecurityManager.getAuthentication(); return authentication.getName(); }
private String getCurrentUser() { Authentication authentication = HudsonSecurityManager.getAuthentication(); return authentication.getName(); }
private String getCurrentUser() { Authentication authentication = HudsonSecurityManager.getAuthentication(); return authentication.getName(); }
public UserCause() { this.authenticationName = HudsonSecurityManager.getAuthentication().getName(); }
/** * 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(HudsonSecurityManager.getAuthentication(), p); }
/** * 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 = HudsonSecurityManager.getAuthentication(); if (a instanceof AnonymousAuthenticationToken) { return null; } return get(a.getName()); } private static volatile long lastScanned;
/** * With ADMINISTER permission, can delete users with persisted data but * can't delete self. */ public boolean canDelete() { return hasPermission(Hudson.ADMINISTER) && !id.equals(HudsonSecurityManager.getAuthentication().getName()) && new File(getRootDir(), id).exists(); }
/** * Checks if the current security principal has this permission. * * <p> This is just a convenience function. * * @throws org.acegisecurity.AccessDeniedException if the user doesn't have * the permission. */ public final void checkPermission(Permission p) { Authentication a = HudsonSecurityManager.getAuthentication(); if (!hasPermission(a, p)) { throw new AccessDeniedException2(a, p); } }
public List<Team> findCurrentUserTeams() { //Check if we have to use TeamAwareSecurityRealm if (getTeamAwareSecurityRealm() != null) { return Arrays.asList(getTeamAwareSecurityRealm().GetCurrentUserTeam()); } Authentication authentication = HudsonSecurityManager.getAuthentication(); List<Team> userTeams = findUserTeams(authentication.getName()); Collection<? extends GrantedAuthority> gas = authentication.getAuthorities(); if (gas == null) { throw new IllegalStateException("authentication.getAuthorities() returned null array"); } for (GrantedAuthority ga : gas) { String grantedAuthority = ga.getAuthority(); userTeams.addAll(findUserTeams(grantedAuthority)); } return userTeams; }
/** * Deletes this user from Hudson. */ public void doDoDelete(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { requirePOST(); checkPermission(Hudson.ADMINISTER); if (id.equals(HudsonSecurityManager.getAuthentication().getName())) { rsp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Cannot delete self"); return; } delete(); rsp.sendRedirect2("../.."); }
public HttpResponse doDoDisconnect(@QueryParameter String offlineMessage) throws IOException, ServletException { if (channel != null) { //does nothing in case computer is already disconnected checkPermission(CONFIGURE); offlineMessage = Util.fixEmptyAndTrim(offlineMessage); disconnect(OfflineCause.create(Messages._SlaveComputer_DisconnectedBy( HudsonSecurityManager.getAuthentication().getName(), offlineMessage != null ? " : " + offlineMessage : ""))); } return new HttpRedirect("."); }
List<Team> getCurrentUserTeamsWithPermission(Permission permission) { //Check if we have to use TeamAwareSecurityRealm if (getTeamAwareSecurityRealm() != null) { return Arrays.asList(getTeamAwareSecurityRealm().GetCurrentUserTeam()); } List<Team> userTeamsWithPermission = new ArrayList<Team>(); Authentication authentication = HudsonSecurityManager.getAuthentication(); List<Team> userTeams = findCurrentUserTeams(); for (Team userTeam : userTeams) { TeamMember member = userTeam.findMember(authentication.getName()); if ((member != null) && member.hasPermission(permission)) { userTeamsWithPermission.add(userTeam); } } for (GrantedAuthority ga : authentication.getAuthorities()) { for (Team userTeam : userTeams) { TeamMember member = userTeam.findMember(ga.getAuthority()); if ((member != null) && member.hasPermission(permission)) { userTeamsWithPermission.add(userTeam); } } } return userTeamsWithPermission; }
public HttpResponse doToggleOffline(@QueryParameter String offlineMessage) throws IOException, ServletException { checkPermission(CONFIGURE); if (!temporarilyOffline) { offlineMessage = Util.fixEmptyAndTrim(offlineMessage); setTemporarilyOffline(!temporarilyOffline, OfflineCause.create(hudson.slaves.Messages._SlaveComputer_DisconnectedBy( HudsonSecurityManager.getAuthentication().getName(), offlineMessage != null ? " : " + offlineMessage : ""))); } else { setTemporarilyOffline(!temporarilyOffline, null); } return HttpResponses.redirectToDot(); }
/** * 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, HudsonSecurityManager.getAuthentication())); }
/** * Schedules the installation of this plugin. * * <p> This is mainly intended to be called from the UI. The actual * installation work happens asynchronously in another thread. */ public Future<UpdateCenterJob> deploy() { Hudson.getInstance().checkPermission(Hudson.ADMINISTER); UpdateCenter uc = Hudson.getInstance().getUpdateCenter(); for (Plugin dep : getNeededDependencies()) { LOGGER.log(Level.WARNING, "Adding dependent install of " + dep.name + " for plugin " + name); dep.deploy(); } return uc.addJob(uc.new InstallationJob(this, UpdateSite.this, HudsonSecurityManager.getAuthentication())); }
/** * Performs hudson downgrade. */ public void doDowngrade(StaplerResponse rsp) throws IOException, ServletException { requirePOST(); Hudson.getInstance().checkPermission(Hudson.ADMINISTER); if (!isDowngradable()) { sendError("Hudson downgrade is not possible, probably backup does not exist"); return; } HudsonDowngradeJob job = new HudsonDowngradeJob(getCoreSource(), HudsonSecurityManager.getAuthentication()); LOGGER.info("Scheduling the core downgrade"); addJob(job); rsp.sendRedirect2("."); }
/** * Schedules a Hudson upgrade. */ public void doUpgrade(StaplerResponse rsp) throws IOException, ServletException { requirePOST(); Hudson.getInstance().checkPermission(Hudson.ADMINISTER); HudsonUpgradeJob job = new HudsonUpgradeJob(getCoreSource(), HudsonSecurityManager.getAuthentication()); if (!Lifecycle.get().canRewriteHudsonWar()) { sendError("Hudson upgrade not supported in this running mode"); return; } LOGGER.info("Scheduling the core upgrade"); addJob(job); rsp.sendRedirect2("."); }