Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split the security setup into a separate section
- Loading branch information
Showing
4 changed files
with
149 additions
and
61 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
core/src/main/java/hudson/security/GlobalSecurityConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2011, CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package hudson.security; | ||
|
||
import hudson.Extension; | ||
import hudson.markup.MarkupFormatter; | ||
import jenkins.model.GlobalConfiguration; | ||
import jenkins.model.Jenkins; | ||
import net.sf.json.JSONObject; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
/** | ||
* Security configuration. | ||
* | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
@Extension(ordinal=200) | ||
public class GlobalSecurityConfiguration extends GlobalConfiguration { | ||
@Override | ||
public boolean configure(StaplerRequest req, JSONObject json) throws FormException { | ||
// for compatibility reasons, the actual value is stored in Jenkins | ||
Jenkins j = Jenkins.getInstance(); | ||
|
||
if (json.has("useSecurity")) { | ||
JSONObject security = json.getJSONObject("useSecurity"); | ||
j.setSecurityRealm(SecurityRealm.all().newInstanceFromRadioList(security, "realm")); | ||
j.setAuthorizationStrategy(AuthorizationStrategy.all().newInstanceFromRadioList(security, "authorization")); | ||
|
||
if (security.has("markupFormatter")) { | ||
j.setMarkupFormatter(req.bindJSON(MarkupFormatter.class, security.getJSONObject("markupFormatter"))); | ||
} else { | ||
j.setMarkupFormatter(null); | ||
} | ||
} else { | ||
j.disableSecurity(); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
core/src/main/resources/hudson/security/GlobalSecurityConfiguration/config.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package hudson.security.csrf.GlobalCrumbIssuerConfiguration | ||
|
||
import hudson.security.SecurityRealm | ||
import hudson.security.AuthorizationStrategy | ||
|
||
def f=namespace(lib.FormTagLib) | ||
|
||
f.optionalBlock( field:"useSecurity", title:_("Enable security"), checked:app.useSecurity) { | ||
f.entry (title:_("TCP port for JNLP slave agents")) { | ||
|
||
int port = app.slaveAgentPort | ||
|
||
f.radio(name:"slaveAgentPortType", value:"fixed", id:"sat.fixed", | ||
chcked:port>0, onclick:"\$('sat.port').disabled=false") | ||
label("for":"sat.fixed", _$("Fixed")) | ||
text(" : ") | ||
input(type:"text", "class":"number", name:"slaveAgentPort", id:"sat.port", | ||
value: port>0 ? port : null, disabled: port>0 ? null : "true" ) | ||
|
||
raw(" ") //////////////////////////// | ||
|
||
f.radio(name:"slaveAgentPortType", value:"random", id:"sat.random", | ||
checked:port==0, onclick:"\$('sat.port').disabled=true") | ||
label("for":"sat.random", _$("Random")) | ||
|
||
raw(" ") //////////////////////////// | ||
|
||
f.radio(name:"slaveAgentPortType", value:"disable", id:"sat.disabled", | ||
checked:port==-1, onclick:"\$('sat.port').disabled=true") | ||
label("for":"sat.random", _$("Random")) | ||
|
||
// checked="${it.useSecurity}" help="/help/system-config/enableSecurity.html"> | ||
// help="/help/system-config/master-slave/slave-agent-port.html"> | ||
/* | ||
<input type="text" class="number" name="slaveAgentPort" id="sat.port" | ||
value="${it.slaveAgentPort gt 0 ? it.slaveAgentPort : null}" | ||
disabled="${it.slaveAgentPort gt 0 ? null : 'true'}"/> | ||
<st:nbsp /> | ||
<f:radio name="slaveAgentPortType" value="random" id="sat.random" | ||
checked="${it.slaveAgentPort==0}" onclick="$('sat.port').disabled=true" /> | ||
<label for="sat.random">${%Random}</label> | ||
<st:nbsp /> | ||
<f:radio name="slaveAgentPortType" value="disable" id="sat.disabled" | ||
checked="${it.slaveAgentPort==-1}" onclick="$('sat.port').disabled=true" /> | ||
<label for="sat.disabled">${%Disable}</label> | ||
</f:entry> | ||
*/ | ||
} | ||
|
||
f.dropdownDescriptorSelector(title:_("Markup Formatter"),field:"markupFormatter") | ||
|
||
f.entry(title:_("Access Control")) { | ||
table(style:"width:100%") { | ||
f.descriptorRadioList(title:_("Security Realm"),varName:"realm", instance:app.securityRealm, descriptors:SecurityRealm.all()) | ||
f.descriptorRadioList(title:_("Authorization"), varName:"authorization", instance:app.authorizationStrategy, descriptors:AuthorizationStrategy.all()) | ||
} | ||
} | ||
} | ||
|
||
/* | ||
<f:dropdownDescriptorSelector title="${%Markup Formatter}" field="markupFormatter" /> | ||
<f:entry title="${%Access Control}"> | ||
<table style="width:100%"> | ||
<f:descriptorRadioList title="${%Security Realm}" varName="realm" | ||
instance="${it.securityRealm}" | ||
descriptors="${h.securityRealmDescriptors}"/> | ||
<f:descriptorRadioList title="${%Authorization}" varName="authorization" | ||
instance="${it.authorizationStrategy}" | ||
descriptors="${h.authorizationStrategyDescriptors}"/> | ||
</table> | ||
</f:entry> | ||
</f:optionalBlock> | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters