~ubuntu-branches/ubuntu/trusty/jenkins/trusty

« back to all changes in this revision

Viewing changes to core/src/main/java/hudson/security/GlobalSecurityConfiguration.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-13 12:35:19 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20130813123519-tizgfxcr70trl7r0
Tags: 1.509.2+dfsg-1
* New upstream release (Closes: #706725):
  - d/control: Update versioned BD's:
    * jenkins-executable-war >= 1.28.
    * jenkins-instance-identity >= 1.3.
    * libjenkins-remoting-java >= 2.23.
    * libjenkins-winstone-java >= 0.9.10-jenkins-44.
    * libstapler-java >= 1.207.
    * libjenkins-json-java >= 2.4-jenkins-1.
    * libstapler-adjunct-timeline-java >= 1.4.
    * libstapler-adjunct-codemirror-java >= 1.2.
    * libmaven-hpi-plugin-java >= 1.93.
    * libjenkins-xstream-java >= 1.4.4-jenkins-3.
  - d/maven.rules: Map to older version of animal-sniffer-maven-plugin.
  - Add patch for compatibility with guava >= 0.14.
  - Add patch to exclude asm4 dependency via jnr-posix.
  - Fixes the following security vulnerabilities:
    CVE-2013-2034, CVE-2013-2033, CVE-2013-2034, CVE-2013-1808
* d/patches/*: Switch to using git patch-queue for managing patches.
* De-duplicate jars between libjenkins-java and jenkins-external-job-monitor
  (Closes: #701163):
  - d/control: Add dependency between jenkins-external-job-monitor ->
    libjenkins-java.
  - d/rules: 
    Drop installation of jenkins-core in jenkins-external-job-monitor.
  - d/jenkins-external-job-monitor.{links,install}: Link to jenkins-core
    in /usr/share/java instead of included version.
* Wait longer for jenkins to stop during restarts (Closes: #704848):
  - d/jenkins.init: Re-sync init script from upstream codebase.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 */
24
24
package hudson.security;
25
25
 
 
26
import com.google.common.base.Predicate;
 
27
import hudson.BulkChange;
26
28
import hudson.Extension;
 
29
import hudson.Functions;
27
30
import hudson.markup.MarkupFormatter;
28
 
import jenkins.model.GlobalConfiguration;
 
31
import hudson.model.Descriptor;
 
32
import hudson.model.Descriptor.FormException;
 
33
import hudson.model.ManagementLink;
 
34
import hudson.util.FormApply;
 
35
 
 
36
import java.io.IOException;
 
37
import java.util.logging.Level;
 
38
import java.util.logging.Logger;
 
39
 
 
40
import javax.servlet.ServletException;
 
41
 
 
42
import jenkins.model.GlobalConfigurationCategory;
29
43
import jenkins.model.Jenkins;
30
44
import jenkins.util.ServerTcpPort;
31
45
import net.sf.json.JSONObject;
 
46
 
32
47
import org.kohsuke.stapler.StaplerRequest;
33
 
 
34
 
import java.io.IOException;
 
48
import org.kohsuke.stapler.StaplerResponse;
35
49
 
36
50
/**
37
51
 * Security configuration.
38
52
 *
39
53
 * @author Kohsuke Kawaguchi
40
54
 */
41
 
@Extension(ordinal=200)
42
 
public class GlobalSecurityConfiguration extends GlobalConfiguration {
 
55
@Extension(ordinal = Integer.MAX_VALUE - 210)
 
56
public class GlobalSecurityConfiguration extends ManagementLink {
 
57
    
 
58
    private static final Logger LOGGER = Logger.getLogger(GlobalSecurityConfiguration.class.getName());
 
59
 
43
60
    public MarkupFormatter getMarkupFormatter() {
44
61
        return Jenkins.getInstance().getMarkupFormatter();
45
62
    }
46
 
    
 
63
 
47
64
    public int getSlaveAgentPort() {
48
65
        return Jenkins.getInstance().getSlaveAgentPort();
49
66
    }
50
 
    
51
 
    @Override
52
 
    public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
 
67
 
 
68
    public synchronized void doConfigure(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
 
69
        // for compatibility reasons, the actual value is stored in Jenkins
 
70
        BulkChange bc = new BulkChange(Jenkins.getInstance());
 
71
        try{
 
72
            boolean result = configure(req, req.getSubmittedForm());
 
73
            LOGGER.log(Level.FINE, "security saved: "+result);
 
74
            Jenkins.getInstance().save();
 
75
            FormApply.success(req.getContextPath()+"/manage").generateResponse(req, rsp, null);
 
76
        } finally {
 
77
            bc.commit();
 
78
        }
 
79
    }
 
80
 
 
81
    public boolean configure(StaplerRequest req, JSONObject json) throws hudson.model.Descriptor.FormException {
53
82
        // for compatibility reasons, the actual value is stored in Jenkins
54
83
        Jenkins j = Jenkins.getInstance();
55
 
 
 
84
        j.checkPermission(Jenkins.ADMINISTER);
56
85
        if (json.has("useSecurity")) {
57
86
            JSONObject security = json.getJSONObject("useSecurity");
58
87
            j.setSecurityRealm(SecurityRealm.all().newInstanceFromRadioList(security, "realm"));
59
88
            j.setAuthorizationStrategy(AuthorizationStrategy.all().newInstanceFromRadioList(security, "authorization"));
60
 
 
61
89
            try {
62
90
                j.setSlaveAgentPort(new ServerTcpPort(security.getJSONObject("slaveAgentPort")).getPort());
63
91
            } catch (IOException e) {
64
 
                throw new FormException(e,"slaveAgentPortType");
 
92
                throw new hudson.model.Descriptor.FormException(e, "slaveAgentPortType");
65
93
            }
66
 
 
67
94
            if (security.has("markupFormatter")) {
68
95
                j.setMarkupFormatter(req.bindJSON(MarkupFormatter.class, security.getJSONObject("markupFormatter")));
69
96
            } else {
73
100
            j.disableSecurity();
74
101
        }
75
102
 
76
 
        return true;
77
 
    }
 
103
        // persist all the additional security configs
 
104
        boolean result = true;
 
105
        for(Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfig(FILTER)){
 
106
            result &= configureDescriptor(req,json,d);
 
107
        }
 
108
        
 
109
        return result;
 
110
    }
 
111
    
 
112
    private boolean configureDescriptor(StaplerRequest req, JSONObject json, Descriptor<?> d) throws FormException {
 
113
        // collapse the structure to remain backward compatible with the JSON structure before 1.
 
114
        String name = d.getJsonSafeClassName();
 
115
        JSONObject js = json.has(name) ? json.getJSONObject(name) : new JSONObject(); // if it doesn't have the property, the method returns invalid null object.
 
116
        json.putAll(js);
 
117
        return d.configure(req, js);
 
118
    }    
 
119
 
 
120
    @Override
 
121
    public String getDisplayName() {
 
122
        return Messages.GlobalSecurityConfiguration_DisplayName();
 
123
    }
 
124
    
 
125
    @Override
 
126
    public String getDescription() {
 
127
        return Messages.GlobalSecurityConfiguration_Description();
 
128
    }
 
129
 
 
130
    @Override
 
131
    public String getIconFileName() {
 
132
        return "secure.png";
 
133
    }
 
134
 
 
135
    @Override
 
136
    public String getUrlName() {
 
137
        return "configureSecurity";
 
138
    }
 
139
    
 
140
    @Override
 
141
    public Permission getRequiredPermission() {
 
142
        return Jenkins.ADMINISTER;
 
143
    }
 
144
 
 
145
    public static Predicate<GlobalConfigurationCategory> FILTER = new Predicate<GlobalConfigurationCategory>() {
 
146
        public boolean apply(GlobalConfigurationCategory input) {
 
147
            return input instanceof GlobalConfigurationCategory.Security;
 
148
        }
 
149
    };
78
150
}
79