提交 4e5d7839 编写于 作者: K kohsuke

added a convenience method.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@6328 71c3de6d-444a-0410-be80-ed276b4c234a
上级 03d6a8e4
......@@ -32,6 +32,7 @@ import org.kohsuke.stapler.Ancestor;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.acegisecurity.providers.anonymous.AnonymousAuthenticationToken;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
......@@ -723,4 +724,11 @@ public class Functions {
}
private static final Pattern LINE_END = Pattern.compile("\r?\n");
/**
* Checks if the current user is anonymous.
*/
public static boolean isAnonymous() {
return Hudson.getAuthentication() instanceof AnonymousAuthenticationToken;
}
}
......@@ -62,6 +62,7 @@ import hudson.widgets.Widget;
import net.sf.json.JSONObject;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.ui.AbstractProcessingFilter;
import org.acegisecurity.Authentication;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
......@@ -1798,8 +1799,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
if(!Hudson.adminCheck(req,rsp))
return;
LOGGER.severe(String.format("Shutting down VM as requested by {0} from {1}",
SecurityContextHolder.getContext().getAuthentication(),
req.getRemoteAddr()));
getAuthentication(), req.getRemoteAddr()));
rsp.setStatus(HttpServletResponse.SC_OK);
rsp.setContentType("text/plain");
PrintWriter w = rsp.getWriter();
......@@ -1809,6 +1809,14 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
System.exit(0);
}
/**
* Gets the {@link Authentication} object that represents the user
* associated with the current request.
*/
public static Authentication getAuthentication() {
return SecurityContextHolder.getContext().getAuthentication();
}
/**
* Configure the logging level.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册