package net.catcert.psa.util;

import org.apache.ws.security.WSPasswordCallback;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;

import java.io.IOException;


/**
 * PWCallback for RampartConfig
 * @author suport tècnic CATCert
 *
 */
public class PWCBHandler implements CallbackHandler {

	public void handle(Callback[] callbacks) throws IOException,
	UnsupportedCallbackException {
		for (int i = 0; i < callbacks.length; i++) {
			WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i];
			String id = pwcb.getIdentifer();
			if("oid.2.5.4.5=87654321x, cn=ajuntament d'exemple, ou=ajuntament d'exemple, ou=serveis publics de certificacio cda-1, ou=vegeu https://www.catcert.net/vercda-1 c(03), o=generalitat de catalunya, c=es".equals(id)) {
				pwcb.setPassword("1111");
			} else if("cda_xifra_pre".equals(id)) {
				pwcb.setPassword("111111");
			}
		}
	}

}


