In the current version of Hudson, stdout needs to be set or else the process invocation will fail.

This commit is contained in:
kohsuke 2010-04-08 05:40:55 +00:00
parent 394ff24234
commit 5c9562cb24
2 changed files with 25 additions and 1 deletions

View file

@ -26,6 +26,7 @@ package hudson.plugins.script_realm;
import hudson.Extension;
import hudson.Launcher.LocalLauncher;
import hudson.model.Descriptor;
import hudson.model.TaskListener;
import hudson.security.AbstractPasswordBasedSecurityRealm;
import hudson.security.GroupDetails;
import hudson.security.SecurityRealm;
@ -38,6 +39,7 @@ import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.userdetails.User;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.apache.commons.io.output.NullOutputStream;
import org.kohsuke.stapler.DataBoundConstructor;
import org.springframework.dao.DataAccessException;
@ -59,7 +61,7 @@ public class ScriptSecurityRealm extends AbstractPasswordBasedSecurityRealm {
try {
StringWriter out = new StringWriter();
LocalLauncher launcher = new LocalLauncher(new StreamTaskListener(out));
if (launcher.launch().cmds(QuotedStringTokenizer.tokenize(commandLine))
if (launcher.launch().cmds(QuotedStringTokenizer.tokenize(commandLine)).stdout(new NullOutputStream())
.envs("U="+username,"P="+password).join()!=0)
throw new BadCredentialsException(out.toString());

View file

@ -0,0 +1,22 @@
package hudson.plugins.script_realm;
import org.acegisecurity.AuthenticationException;
import org.jvnet.hudson.test.HudsonTestCase;
/**
* @author Kohsuke Kawaguchi
*/
public class ScriptSecurityRealmTest extends HudsonTestCase {
public void test1() {
new ScriptSecurityRealm("/bin/true").authenticate("test","test");
}
public void test2() {
try {
new ScriptSecurityRealm("/bin/false").authenticate("test","test");
fail();
} catch (AuthenticationException e) {
// as expected
}
}
}