public CloudStackUserDaoImpl() {}
@Override
public String getSecretKeyByAccessKey( String accessKey ) {
CloudStackUserVO user = null;
String cloudSecretKey = null;
SearchBuilder <CloudStackUserVO> searchByAccessKey = createSearchBuilder();
searchByAccessKey.and("apiKey", searchByAccessKey.entity().getApiKey(), SearchCriteria.Op.EQ);
searchByAccessKey.done();
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
try {
txn.start();
SearchCriteria<CloudStackUserVO> sc = searchByAccessKey.create();
sc.setParameters("apiKey", accessKey);
user = findOneBy(sc);
if ( user != null && user.getSecretKey() != null) {
// if the cloud db is encrypted, decrypt the secret_key returned by cloud db before signature generation
if( EncryptionSecretKeyCheckerUtil.useEncryption() ) {
StandardPBEStringEncryptor encryptor = EncryptionSecretKeyCheckerUtil.getEncryptor();
cloudSecretKey = encryptor.decrypt( user.getSecretKey() );
} else {
cloudSecretKey = user.getSecretKey();
}
}
return cloudSecretKey;
} finally {
txn.commit();