本文整理了Java中jenkins.model.Jenkins.getAuthentication()
方法的一些代码示例,展示了Jenkins.getAuthentication()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jenkins.getAuthentication()
方法的具体详情如下:
包路径:jenkins.model.Jenkins
类名称:Jenkins
方法名:getAuthentication
[英]Gets the Authentication object that represents the user associated with the current request.
[中]获取表示与当前请求关联的用户的身份验证对象。
代码示例来源:origin: jenkinsci/jenkins
/**
* Returns all the registered {@link TopLevelItemDescriptor}s that the current security principal is allowed to
* create within the specified item group.
*
* @since 1.607
*/
public static List<TopLevelItemDescriptor> all(ItemGroup c) {
return all(Jenkins.getAuthentication(), c);
}
代码示例来源: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
/**
* Checks if the current user is anonymous.
*/
public static boolean isAnonymous() {
return ACL.isAnonymous(Jenkins.getAuthentication());
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Checks if the current security principal has this permission.
*
* @return false
* if the user doesn't have the permission.
*/
public final boolean hasPermission(@Nonnull Permission p) {
Authentication a = Jenkins.getAuthentication();
if (a == SYSTEM) {
return true;
}
return hasPermission(a, p);
}
代码示例来源:origin: jenkinsci/jenkins
public RestartJenkinsJob(UpdateSite site) {
super(site);
this.authentication = Jenkins.getAuthentication().getName();
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Extension point to allow implementations of {@link UpdateSite} to create a custom
* {@link UpdateCenter.InstallationJob}.
*
* @param plugin the plugin to create the {@link UpdateCenter.InstallationJob} for.
* @param uc the {@link UpdateCenter}.
* @param dynamicLoad {@code true} if the plugin should be attempted to be dynamically loaded.
* @return the {@link UpdateCenter.InstallationJob}.
* @since 2.9
*/
protected UpdateCenter.InstallationJob createInstallationJob(Plugin plugin, UpdateCenter uc, boolean dynamicLoad) {
return uc.new InstallationJob(plugin, this, Jenkins.getAuthentication(), dynamicLoad);
}
代码示例来源:origin: jenkinsci/jenkins
public UserCause() {
this.authenticationName = Jenkins.getAuthentication().getName();
}
代码示例来源:origin: jenkinsci/jenkins
protected int run() {
Authentication a = Jenkins.getAuthentication();
stdout.println("Authenticated as: "+a.getName());
stdout.println("Authorities:");
for (GrantedAuthority ga : a.getAuthorities()) {
stdout.println(" "+ga.getAuthority());
}
return 0;
}
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public void run() {
try {
ACL.impersonate(ACL.SYSTEM);
LOGGER.info(String.format("Shutting down VM as requested by %s from %s",
getAuthentication().getName(), req != null ? req.getRemoteAddr() : "???"));
cleanUp();
System.exit(0);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to shut down Jenkins", e);
}
}
}.start();
代码示例来源:origin: jenkinsci/jenkins
@SuppressWarnings("deprecation")
@Override
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, Jenkins.getAuthentication());
channel.setProperty(CliEntryPoint.class.getName(), new CliManagerImpl(channel));
}
};
代码示例来源:origin: jenkinsci/jenkins
/**
* Logs out the user.
*/
public void doLogout( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
String user = getAuthentication().getName();
securityRealm.doLogout(req, rsp);
SecurityListener.fireLoggedOut(user);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Performs hudson downgrade.
*/
@RequirePOST
public void doRestart(StaplerResponse rsp) throws IOException, ServletException {
HudsonDowngradeJob job = new HudsonDowngradeJob(getCoreSource(), Jenkins.getAuthentication());
LOGGER.info("Scheduling the core downgrade");
addJob(job);
rsp.sendRedirect2(".");
}
代码示例来源:origin: jenkinsci/jenkins
private void interrupt(Result result, boolean forShutdown) {
Authentication a = Jenkins.getAuthentication();
if (a == ACL.SYSTEM)
interrupt(result, forShutdown, new CauseOfInterruption[0]);
else {
// worth recording who did it
// avoid using User.get() to avoid deadlock.
interrupt(result, forShutdown, new UserInterruption(a.getName()));
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Performs hudson downgrade.
*/
@RequirePOST
public void doDowngrade(StaplerResponse rsp) throws IOException, ServletException {
if(!isDowngradable()) {
sendError("Jenkins downgrade is not possible, probably backup does not exist");
return;
}
HudsonDowngradeJob job = new HudsonDowngradeJob(getCoreSource(), Jenkins.getAuthentication());
LOGGER.info("Scheduling the core downgrade");
addJob(job);
rsp.sendRedirect2(".");
}
代码示例来源:origin: jenkinsci/jenkins
@Override
protected int run() throws Exception {
Authentication a = Jenkins.getAuthentication();
if (a== Jenkins.ANONYMOUS)
throw new CmdLineException("No credentials specified."); // this causes CLI to show the command line options.
ClientAuthenticationCache store = new ClientAuthenticationCache(checkChannel());
store.set(a);
SecurityListener.fireLoggedIn(a.getName());
return 0;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* With ADMINISTER permission, can delete users with persisted data but can't delete self.
*/
public boolean canDelete() {
final IdStrategy strategy = idStrategy();
return hasPermission(Jenkins.ADMINISTER) && !strategy.equals(id, Jenkins.getAuthentication().getName())
&& UserIdMapper.getInstance().isMapped(id);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Schedules the downgrade of this plugin.
*/
public Future<UpdateCenterJob> deployBackup() {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
UpdateCenter uc = Jenkins.getInstance().getUpdateCenter();
return uc.addJob(uc.new PluginDowngradeJob(this, UpdateSite.this, Jenkins.getAuthentication()));
}
/**
代码示例来源:origin: jenkinsci/jenkins
/**
* Schedules a Jenkins upgrade.
*/
@RequirePOST
public void doUpgrade(StaplerResponse rsp) throws IOException, ServletException {
HudsonUpgradeJob job = new HudsonUpgradeJob(getCoreSource(), Jenkins.getAuthentication());
if(!Lifecycle.get().canRewriteHudsonWar()) {
sendError("Jenkins upgrade not supported in this running mode");
return;
}
LOGGER.info("Scheduling the core upgrade");
addJob(job);
rsp.sendRedirect2(".");
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Deletes this user from Hudson.
*/
@RequirePOST
public void doDoDelete(StaplerRequest req, StaplerResponse rsp) throws IOException {
checkPermission(Jenkins.ADMINISTER);
if (idStrategy().equals(id, Jenkins.getAuthentication().getName())) {
rsp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Cannot delete self");
return;
}
delete();
rsp.sendRedirect2("../..");
}
代码示例来源:origin: jenkinsci/jenkins
@Restricted(NoExternalUse.class)
public boolean hasCurrentUserRightToGenerateNewToken(User propertyOwner){
if (ADMIN_CAN_GENERATE_NEW_TOKENS && Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
return true;
}
User currentUser = User.current();
if (currentUser == null) {
// Anonymous
return false;
}
if (Jenkins.getAuthentication() == ACL.SYSTEM) {
// SYSTEM user is always eligible to see tokens
return true;
}
return User.idStrategy().equals(propertyOwner.getId(), currentUser.getId());
}
内容来源于网络,如有侵权,请联系作者删除!