forked from fcrespel/jenkins-cas-plugin
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Script Security plugin and sandbox for CAS 1.0 (SECURITY-488)
- Loading branch information
Showing
8 changed files
with
69 additions
and
40 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,24 +1,23 @@ | ||
package org.jenkinsci.plugins.cas.validation; | ||
|
||
import groovy.lang.GroovyShell; | ||
import groovy.lang.Script; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.jasig.cas.client.authentication.AttributePrincipal; | ||
import org.jasig.cas.client.authentication.AttributePrincipalImpl; | ||
import org.jasig.cas.client.validation.AbstractCasProtocolUrlBasedTicketValidator; | ||
import org.jasig.cas.client.validation.Assertion; | ||
import org.jasig.cas.client.validation.AssertionImpl; | ||
import org.jasig.cas.client.validation.TicketValidationException; | ||
import org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript; | ||
|
||
import groovy.lang.Binding; | ||
import jenkins.model.Jenkins; | ||
|
||
/** | ||
* Implementation of a Ticket Validator that can validate tickets conforming to the CAS 1.0 specification. | ||
|
@@ -31,9 +30,8 @@ public class Cas10RoleParsingTicketValidator extends AbstractCasProtocolUrlBased | |
|
||
public static final String DEFAULT_ROLE_ATTRIBUTE = "roles"; | ||
|
||
private String rolesValidationScript; | ||
private SecureGroovyScript rolesValidationScript; | ||
private String rolesAttribute = DEFAULT_ROLE_ATTRIBUTE; | ||
private Script parsedScript; | ||
|
||
public Cas10RoleParsingTicketValidator(final String casServerUrlPrefix) { | ||
super(casServerUrlPrefix); | ||
|
@@ -61,7 +59,7 @@ protected Assertion parseResponseFromServer(final String response) throws Ticket | |
reader.readLine(); | ||
final String name = reader.readLine(); | ||
|
||
List<String> roles = parseRolesFromValidationResponse(getParsedScript(), response); | ||
List<String> roles = parseRolesFromValidationResponse(rolesValidationScript, response); | ||
if (roles != null) { | ||
Map<String, Object> attributes = new HashMap<String, Object>(1); | ||
attributes.put(rolesAttribute, roles); | ||
|
@@ -71,7 +69,7 @@ protected Assertion parseResponseFromServer(final String response) throws Ticket | |
return new AssertionImpl(name); | ||
} | ||
|
||
} catch (final IOException e) { | ||
} catch (final Exception e) { | ||
This comment has been minimized.
Sorry, something went wrong.
jglick
Member
|
||
throw new TicketValidationException("Unable to parse response.", e); | ||
} | ||
} | ||
|
@@ -83,13 +81,14 @@ protected Assertion parseResponseFromServer(final String response) throws Ticket | |
* @return list of roles | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
public static List<String> parseRolesFromValidationResponse(Script script, String response) { | ||
public static List<String> parseRolesFromValidationResponse(SecureGroovyScript script, String response) throws Exception { | ||
if (script == null) | ||
return null; | ||
|
||
// Run the script to parse the response | ||
script.getBinding().setVariable("response", response); | ||
Collection coll = (Collection) script.run(); | ||
Binding binding = new Binding(); | ||
binding.setVariable("response", response); | ||
Collection coll = (Collection) script.evaluate(Jenkins.getInstance().getPluginManager().uberClassLoader, binding); | ||
if (coll == null || coll.isEmpty()) | ||
return null; | ||
|
||
|
@@ -104,30 +103,18 @@ public static List<String> parseRolesFromValidationResponse(Script script, Strin | |
return roles; | ||
} | ||
|
||
/** | ||
* Get the parsed Groovy roles validation script. | ||
* @return parsed Groovy script | ||
*/ | ||
protected synchronized Script getParsedScript() { | ||
if (parsedScript == null && StringUtils.isNotEmpty(rolesValidationScript)) { | ||
parsedScript = new GroovyShell().parse(rolesValidationScript); | ||
} | ||
return parsedScript; | ||
} | ||
|
||
/** | ||
* @return the rolesValidationScript | ||
*/ | ||
public String getRolesValidationScript() { | ||
public SecureGroovyScript getRolesValidationScript() { | ||
return rolesValidationScript; | ||
} | ||
|
||
/** | ||
* @param rolesValidationScript the rolesValidationScript to set | ||
*/ | ||
public void setRolesValidationScript(String rolesValidationScript) { | ||
public void setRolesValidationScript(SecureGroovyScript rolesValidationScript) { | ||
this.rolesValidationScript = rolesValidationScript; | ||
this.parsedScript = null; | ||
} | ||
|
||
/** | ||
|
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
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
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 |
---|---|---|
|
@@ -9,9 +9,12 @@ | |
<f:entry title="${%rolesValidationScript}" field="rolesValidationScript"> | ||
<f:textarea /> | ||
</f:entry> | ||
<f:entry title="${%sandbox}" field="sandbox"> | ||
<f:checkbox /> | ||
This comment has been minimized.
Sorry, something went wrong.
jglick
Member
|
||
</f:entry> | ||
<f:entry title="${%testValidationResponse}" field="testValidationResponse"> | ||
<f:textarea /> | ||
</f:entry> | ||
<f:validateButton title="${%testScript}" method="testScript" with="rolesValidationScript,testValidationResponse" /> | ||
<f:validateButton title="${%testScript}" method="testScript" with="rolesValidationScript,testValidationResponse,sandbox" /> | ||
</f:advanced> | ||
</j:jelly> |
1 change: 1 addition & 0 deletions
1
src/main/resources/org/jenkinsci/plugins/cas/protocols/Cas10Protocol/config.properties
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
description=<a href="{0}">CAS 1.0</a> is a text-based protocol. Custom extensions may provide support for roles, which can be parsed with a Groovy script. | ||
rolesValidationScript=Roles Validation Script | ||
testValidationResponse=Test Validation Response | ||
sandbox=Use Groovy sandbox | ||
testScript=Test Script |
1 change: 1 addition & 0 deletions
1
src/main/resources/org/jenkinsci/plugins/cas/protocols/Cas10Protocol/config_fr.properties
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
description=<a href="{0}">CAS 1.0</a> est un protocole basé sur du texte. Des extensions spécifiques peuvent apporter le support de rôles, qui peuvent être extraits à l''aide d''un script Groovy. | ||
rolesValidationScript=Script de validation des rôles | ||
testValidationResponse=Réponse de validation de test | ||
sandbox=Utiliser la sandbox Groovy | ||
testScript=Tester le script |
Will not be thrown, since you are not supporting classpaths.