Project

General

Profile

« Previous | Next » 

Revision 31086686

Added by Anahit Babadshanjan over 15 years ago

View differences:

cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/AccountStore.java
18 18

  
19 19
import org.apache.log4j.Logger;
20 20

  
21

  
21 22
public class AccountStore {
22 23
	private static Logger logger = Logger.getLogger(AccountStore.class);
23 24
	
......
95 96
		saveAccounts(accounts);
96 97
	}
97 98
	
99
	public static String readOrStorePassword(String dbms, String strServer, String userName, String pwd){
100
		AccountStore accounts = new AccountStore();
101
		boolean doStore = false;
102
		try {
103
			if (pwd == null){
104
				pwd = accounts.getPassword(dbms, strServer, userName);
105
				if(pwd == null){
106
					doStore = true;
107
					pwd = CdmUtils.readInputLine("Please insert password for " + CdmUtils.Nz(userName) + ": ");
108
				} else {
109
					logger.info("using stored password for  "+CdmUtils.Nz(userName));
110
				}
111
			}
112
			// on success store userName, pwd in property file
113
			if(doStore){
114
				accounts.setPassword(dbms, strServer, userName, pwd);
115
				logger.info("password stored in " + accounts.getAccountsFileName());
116
			}
117
		} catch (Exception e) {
118
			if(doStore){
119
				accounts.removePassword(dbms, strServer, userName);
120
				logger.info("password removed from " + accounts.getAccountsFileName());
121
			}
122
			logger.error(e);
123
			return null;
124
		}
125
		return pwd;
126
	}
127
	
98 128
	public static void main(String[] args) {
99 129
		AccountStore a = new AccountStore();
100 130
//		BerlinModel - EditWp6

Also available in: Unified diff