();
+ authorities.add(AUTHENTICATED_AUTHORITY);
+ if (!StringUtils.isBlank(groupsCommandLine)) {
+ StringWriter out = new StringWriter();
+ LocalLauncher launcher = new LocalLauncher(new StreamTaskListener(out));
+ OutputStream scriptOut = new ByteArrayOutputStream();
+ if (launcher.launch().cmds(QuotedStringTokenizer.tokenize(groupsCommandLine)).stdout(scriptOut).envs("U=" + username).join() == 0) {
+ StringTokenizer tokenizer = new StringTokenizer(scriptOut.toString().trim(), groupsDelimiter);
+ while (tokenizer.hasMoreTokens()) {
+ final String token = tokenizer.nextToken().trim();
+ String[] args = new String[] { token, username };
+ LOGGER.log(Level.FINE, "granting: {0} to {1}", args);
+ authorities.add(new GrantedAuthorityImpl(token));
+ }
+
+ } else {
+ throw new BadCredentialsException(out.toString());
+ }
+ }
+ return authorities.toArray(new GrantedAuthority[0]);
+ } catch (InterruptedException e) {
+ throw new AuthenticationServiceException("Interrupted", e);
+ } catch (IOException e) {
+ throw new AuthenticationServiceException("Failed", e);
+ }
+ }
}
diff --git a/src/main/resources/hudson/plugins/script_realm/ScriptSecurityRealm/config.jelly b/src/main/resources/hudson/plugins/script_realm/ScriptSecurityRealm/config.jelly
index be9173b..fd6550d 100644
--- a/src/main/resources/hudson/plugins/script_realm/ScriptSecurityRealm/config.jelly
+++ b/src/main/resources/hudson/plugins/script_realm/ScriptSecurityRealm/config.jelly
@@ -22,7 +22,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/hudson/plugins/script_realm/ScriptSecurityRealm/help.html b/src/main/resources/hudson/plugins/script_realm/ScriptSecurityRealm/help.html
index a9ca7b9..79c9609 100644
--- a/src/main/resources/hudson/plugins/script_realm/ScriptSecurityRealm/help.html
+++ b/src/main/resources/hudson/plugins/script_realm/ScriptSecurityRealm/help.html
@@ -3,7 +3,7 @@
a custom authentication scheme, but don't want to write your own plugin.
- Each time the authentication is attemped,
+ Each time the authentication is attemped (which is once per session),
the specified script will be invoked with the username in the 'U' environment variable
and the password in the 'P' environment variable. If the script returns exit code 0,
the authentication is considered successful, and otherwise failure.
diff --git a/src/main/resources/index.jelly b/src/main/resources/index.jelly
index 95415c8..01e653c 100644
--- a/src/main/resources/index.jelly
+++ b/src/main/resources/index.jelly
@@ -1,3 +1,3 @@
- This plugin adds authentication via user-defined script.
+ This plugin adds authentication via user-defined script, in additon to the orignal script-realm, this one also supports groups.
\ No newline at end of file
diff --git a/src/main/webapp/help-groupsCommandLine.html b/src/main/webapp/help-groupsCommandLine.html
new file mode 100644
index 0000000..5589826
--- /dev/null
+++ b/src/main/webapp/help-groupsCommandLine.html
@@ -0,0 +1,12 @@
+
+ Delegates the groups resolution to a custom script.
+
+
+ Each time the authentication is attemped (which is once per session),
+ the specified script will be invoked with the username in the 'U' environment variable.
+ If the script returns exit code 0, the output will be tokenized by the delimiter (default: ',')
+ to create a groups with each token.
+
+
+ In case of the failure, the output from the process will be reported in the exception message.
+
\ No newline at end of file
diff --git a/src/main/webapp/help-groupsDelimiter.html b/src/main/webapp/help-groupsDelimiter.html
new file mode 100644
index 0000000..d3d073e
--- /dev/null
+++ b/src/main/webapp/help-groupsDelimiter.html
@@ -0,0 +1,3 @@
+
+ Delimiter to split the groups within the returned output of the groups script.
+
\ No newline at end of file
diff --git a/src/test/java/hudson/plugins/script_realm/ScriptSecurityRealmTest.java b/src/test/java/hudson/plugins/script_realm/ScriptSecurityRealmTest.java
index 228edca..321f0a0 100644
--- a/src/test/java/hudson/plugins/script_realm/ScriptSecurityRealmTest.java
+++ b/src/test/java/hudson/plugins/script_realm/ScriptSecurityRealmTest.java
@@ -8,12 +8,12 @@ import org.jvnet.hudson.test.HudsonTestCase;
*/
public class ScriptSecurityRealmTest extends HudsonTestCase {
public void test1() {
- new ScriptSecurityRealm("/bin/true").authenticate("test","test");
+ new ScriptSecurityRealm("/bin/true", null, null).authenticate("test","test");
}
public void test2() {
try {
- new ScriptSecurityRealm("/bin/false").authenticate("test","test");
+ new ScriptSecurityRealm("/bin/false", null, null).authenticate("test","test");
fail();
} catch (AuthenticationException e) {
// as expected