Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

 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

0 votes


Accepted answer

Permanent link
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

1 vote


2 other answers

Permanent link
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");
    }

}

0 votes


Permanent link
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")));
}

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 12,013

Question asked: Jun 26 '14, 8:51 a.m.

Question was seen: 6,495 times

Last updated: Aug 14 '15, 10:55 a.m.

Confirmation Cancel Confirm