From c614c7979d770747fff63dca3d1c246b3654f906 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 18 Dec 2007 06:55:31 +0000 Subject: [PATCH] added another AuthorizationStrategy implementation that discriminates anonymous users. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@6339 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/Functions.java | 18 ++++++- .../security/AuthorizationStrategy.java | 1 + ...trolOnceLoggedInAuthorizationStrategy.java | 48 +++++++++++++++++++ .../security/full-control-once-logged-in.html | 9 ++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/hudson/security/FullControlOnceLoggedInAuthorizationStrategy.java create mode 100644 war/resources/help/security/full-control-once-logged-in.html diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 03c6d937f7..3f41cc3c09 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -26,6 +26,7 @@ import hudson.tasks.Builder; import hudson.tasks.Publisher; import hudson.security.SecurityRealm; import hudson.security.AuthorizationStrategy; +import hudson.security.Permission; import org.apache.commons.jexl.parser.ASTSizeFunction; import org.apache.commons.jexl.util.Introspector; import org.kohsuke.stapler.Ancestor; @@ -412,13 +413,26 @@ public class Functions { return Util.xmlEscape(s); } - public static void adminCheck(StaplerRequest req, StaplerResponse rsp, Object required) throws IOException, ServletException { - if(required!=null && !Hudson.adminCheck(req,rsp)) { + public static void adminCheck(StaplerRequest req, StaplerResponse rsp, Object required, Permission permission) throws IOException, ServletException { + // this is legacy --- all views should be eventually converted to + // the permission based model. + if((required!=null || (permission!=null && !Hudson.newSecurity)) && !Hudson.adminCheck(req,rsp)) { // check failed. commit the FORBIDDEN response, then abort. rsp.setStatus(HttpServletResponse.SC_FORBIDDEN); rsp.getOutputStream().close(); throw new ServletException("Unauthorized access"); } + + // make sure the user owns the necessary permission to access this page. + if(permission!=null) { + if(!Hudson.getInstance().getACL().hasPermission(permission)) { + // check failed. commit the FORBIDDEN response, then abort. + // if we just throw an exception, JEXL will eat it so it won't have the effect. + rsp.setStatus(HttpServletResponse.SC_FORBIDDEN); + rsp.getOutputStream().close(); + throw new ServletException("Unauthorized access"); + } + } } /** diff --git a/core/src/main/java/hudson/security/AuthorizationStrategy.java b/core/src/main/java/hudson/security/AuthorizationStrategy.java index 35db07df41..ef12625583 100644 --- a/core/src/main/java/hudson/security/AuthorizationStrategy.java +++ b/core/src/main/java/hudson/security/AuthorizationStrategy.java @@ -93,6 +93,7 @@ public abstract class AuthorizationStrategy implements Describable getDescriptor() { + return DESCRIPTOR; + } + + public static final Descriptor DESCRIPTOR = new Descriptor(FullControlOnceLoggedInAuthorizationStrategy.class) { + public String getDisplayName() { + return "Logged-in users can do anything"; + } + + public AuthorizationStrategy newInstance(StaplerRequest req, JSONObject formData) throws FormException { + return new FullControlOnceLoggedInAuthorizationStrategy(); + } + + public String getHelpFile() { + return "/help/security/full-control-once-logged-in.html"; + } + }; + + static { + LIST.add(DESCRIPTOR); + } +} diff --git a/war/resources/help/security/full-control-once-logged-in.html b/war/resources/help/security/full-control-once-logged-in.html new file mode 100644 index 0000000000..dacfcb8741 --- /dev/null +++ b/war/resources/help/security/full-control-once-logged-in.html @@ -0,0 +1,9 @@ +
+ In this mode, every logged-in user gets full control of Hudson. The only user + who won't have full control is anonymous user, who only gets read access. + +

+ This mode is useful to force users to log in before taking actions, so that + you can keep record of who has done what. This setting can be also used in + public-facing Hudson, where you only allow trusted users to have user accounts. +

\ No newline at end of file -- GitLab