Hiding password input in Ant
When writting Ant scripts I always have Ant prompt for passwords be it for SVN, SFTP, or anything else that needs to be logged into. Typically would have the following:
<input message="Please enter SVN password:" addproperty="svn.password" />
The only problem is that it echos the password back at you, there has to be a better way. So of to Google I went and found this with an interesting Ant script fragment:
<input message="secure-input:" addproperty="the.password">
<handler classname="org.apache.tools.ant.input.SecureInputHandler" />
</input>
I did not know there could be nested elements in <input>. Apparently Ant 1.7 added <handler> nested element for <input>. But nowhere is there any documentation on "SecureInputHandler".
So I tried out the fragment and as the post noted there are a few requirements to get it to work:
- Ant 1.7.1
- Java 6, if it is run on Java 5 it will fallback to a "normal" <input>
One downside, I have not been able to get it to work from within Eclipse 3.5 (since Ant 1.7.1 is bundled with it) and using Java 6 runtime. Eclipse will just hang when it gets to the "SecureInputHandler" and you have to stop the build script. It does work great from command line which is how I run all my Ant scripts anyway so it is not a real issue for me, but might be for others.
2 Comments
David Epler wrote on 11/12/09 3:03 PM
@Jim, I did read that post but I was looking for a solution that required no additional libraries/taskdefs.The other solution I did find was:
<input message="Enter Password:" addproperty="password"/>
<exec executable="sh">
<arg line="-c 'stty echo isig < /dev/tty'"/>
</exec>
The above worked and fit my requirements, but just felt like more of a hack.
Also thanks for the Ant Wiki that you maintain, it is an excellent resource.
Jim Priest wrote on 11/12/09 1:30 PM
Very cool! For another solution check out this older blog post:http://www.thecrumb.com/2007/02/07/using-ant-while-hiding-your-svn-password/