Security Architecture of HudsonHudson has a security mechanism in place so that the deployer of Hudson can control who gets access to what part of Hudson. The key components of this mechanism are the followings:
So the overall picture is this; various objects in Hudson (such as Job, Hudson, User, View, etc.) are AccessControlled objects, and therefore they own ACLs. The code is then written in such a way that before a security-sensitive operation is performed, it checks ACL. For example, the following code is taken from the Hudson class, which lets you shut down the JVM by requesting http://server/hudson/exit. You can easily imagine that in a security sensitive environment you don't want random users to invoke this, so it makes sure that the caller has the "ADMINISTER" permission of the system before proceeding to do the work: /**
* Shutdown the system.
* @since 1.161
*/
public void doExit( StaplerRequest req, StaplerResponse rsp ) throws IOException {
checkPermission(ADMINISTER);
LOGGER.severe(String.format("Shutting down VM as requested by %s from %s",
getAuthentication(), req.getRemoteAddr()));
rsp.setStatus(HttpServletResponse.SC_OK);
rsp.setContentType("text/plain");
PrintWriter w = rsp.getWriter();
w.println("Shutting down");
w.close();
System.exit(0);
}
If the deployer configured no security mechanism, the checkPermission method simply becomes no-op. The deployer could configure matrix-based ACL, in which case every AccessControlled object will share the single ACL (whose contents is controlled by the configuration done by the deployer.) In more elaborate case, each AccessControlled object might have different ACLs. In all cases, this is the code you need to write. What do plugins need to do?
With these three information, you can now insert: AccessControlled ac = ... do the step 2 above ... Permission p = ... do the step 3 above ... ac.checkPermission(p) Checking permissions in Jelly filesIf your entire HTML page rendered by Jelly needs to be protected, you can use the attributes of the <l:layout> tag, like this: <l:layout permission="${it.ADMINISTER}">
The permission is always checked against the "it" object, so that needs to be an AccessControlled object. Disabling a part of page rendering if the user doesn't have a permissionSometimes you'd like to change the page rendering, based on the user's permissions. For example, if the user cannot delete a project, it doesn't make sense to show a link to do that. To do this, write Jelly like this: <j:if test="${h.hasPermission(it,it.ADMINISTER)}">
...
</j:if>
|
