It's all about the answers!

Ask a question

Is there support for password files in the Plain Java Client API?


Nicolas Poisson (1023) | asked Jun 26 '14, 8:51 a.m.
 Hi,

We are running automated builds (Maven) through the Jazz Build Engine, which uses a password file, which is fine for CLI and Ant scripts, however there does not seem to be OOTB support for password files through the RTC Plain Java Client API (4.0.3). Am I stuck having to write a custom LoginHandler that decrypts the password? Or is there an easier way around this?

Thanks

Accepted answer


permanent link
Kevin Ramer (4.5k9186201) | answered Jun 26 '14, 11:01 a.m.
edited Jun 26 '14, 12:44 p.m.
There is an ObfuscationHelper class in the Plain Java api.  A couple of lines is all you'd need

e.g.

  import com.ibm.team.repository.common.ObfuscationHelper;


  props = this.getProperties(path);
  String pw=props.getProperty("password");
  String ctpw=new String(ObfuscationHelper.decrypt(pw.getBytes()));

  teamRepository = login(repositoryID, props.getProperty("userID"),ctpw );
 

And you'd need some way to do the encrypt (  ObfuscationHelper.encrypt or ObfuscationHelper.encryptString )

Or as the SCM and build tool kits likely use, you can just use the hashed password from one of those and decrypt it as I've shown.
Nicolas Poisson selected this answer as the correct answer

2 other answers



permanent link
sam detweiler (12.5k6195201) | answered Jun 26 '14, 8:54 a.m.
edited Jul 12 '14, 2:10 p.m.
see above,

here is a sample pgm to encryt and decrypt the string..

package com.sd.tools;

import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;

import com.ibm.team.repository.common.util.ObfuscationHelper;

public class EncodePassword
{

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        // TODO Auto-generated method stub
        if(args.length==1)
        {
                String enpw = ObfuscationHelper.encryptString(args[0]);
                // you would use this output in any password file
                System.out.println(enpw);

                // here is how you would decrypt it for use in your application.
                // you could get this string from the commandline, or a file,
                // or a properties file (pw= string)
               String userpw=enpw;  (the encrypted or plain text password)
               try
                   {
                   // try to decrypt
                   userpw=ObfuscationHelper.decryptString(userpw);
                   }
                catch(Exception ex)
                   {
                    // nothing to do, target variable not overwritten on error
                   }
                System.out.println("pw="+userpw);
            }
        }
        else
            System.out.println("need password string");
    }

}


permanent link
Morten Madsen (3053250) | answered Aug 14 '15, 10:55 a.m.
An implementation of a decryption of a password file inside an ANT task extending the AbstractTeamBuildTask from RTC would look like:
if (getPasswordFile() != null)
{
    logger.info("Detected password file. Decrypting password");

	logger.info(String.format("password file is [%s]", getPasswordFile().toString()));
	
	final Properties properties = new Properties();
	final FileInputStream in = new FileInputStream(getPasswordFile());
    properties.loadFromXML(in);
    in.close();
	  
    for (Object key : properties.keySet())
    {
	logger.info(String.format("Key = [%s]", key.toString()));
    }
	  
    setPassword(ObfuscationHelper.decryptString(properties.getProperty("password")));
}

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.