use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.
the class EsbJmsListenerChecker method doCheck.
public static void doCheck(IbisManager ibisManager, PlatformTransactionManager txManager, String logPrefix) {
long idleTimeout = AppConstants.getInstance().getInt("check.esbJmsListeners.idleTimeout", 300) * 1000;
for (Configuration configuration : ibisManager.getConfigurations()) {
String msg;
List<String> jmsRealmNames = new ArrayList<String>();
for (IAdapter adapter : configuration.getRegisteredAdapters()) {
if (adapter instanceof Adapter) {
for (Iterator receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
IReceiver receiver = (IReceiver) receiverIt.next();
if (receiver instanceof ReceiverBase) {
ReceiverBase rb = (ReceiverBase) receiver;
if (rb.getRunState().equals(RunStateEnum.STARTED)) {
// if (true) {
long lastMessageDate = rb.getLastMessageDate();
if (lastMessageDate == 0 || System.currentTimeMillis() - lastMessageDate > idleTimeout) {
IListener listener = rb.getListener();
if (listener instanceof EsbJmsListener) {
EsbJmsListener esbJmsListener = (EsbJmsListener) listener;
if (esbJmsListener.getMessageProtocol().equals("FF")) {
Object managedConnectionFactory = null;
try {
managedConnectionFactory = esbJmsListener.getManagedConnectionFactory();
if (managedConnectionFactory == null) {
msg = logPrefix + "could not get managed connection factory";
warn(adapter, msg);
} else {
String contextFactoryClassname = getContextFactoryClassname(managedConnectionFactory);
String providerURL = getProviderURL(managedConnectionFactory);
String authDataAlias = getAuthDataAlias(managedConnectionFactory);
String username = null;
String password = null;
msg = logPrefix + "found esbJmsListener [" + esbJmsListener.getName() + "] with managedConnectionFactoryClassname [" + managedConnectionFactory.getClass().getName() + "] having contextFactoryClassname [" + contextFactoryClassname + "] providerURL [" + providerURL + "] authDataAlias [" + authDataAlias + "]";
if (authDataAlias != null) {
CredentialFactory cf = new CredentialFactory(authDataAlias, null, null);
username = cf.getUsername();
password = cf.getPassword();
}
if (contextFactoryClassname != null && contextFactoryClassname.equals("com.tibco.tibjms.naming.TibjmsInitialContextFactory")) {
log.debug(msg + ", checking...");
long age = getTibcoQueueFirstMessageAge(providerURL, authDataAlias, username, password, esbJmsListener.getPhysicalDestinationShortName(), esbJmsListener.getMessageSelector());
if (age > idleTimeout) {
msg = logPrefix + "most probably esbJmsListener [" + esbJmsListener.getName() + "] has lost connection with queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
warn(adapter, msg);
}
} else {
log.debug(msg + ", ignoring...");
}
}
} catch (Throwable t) {
msg = logPrefix + "exception on checking queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
warn(adapter, msg, t);
}
}
}
}
}
}
}
}
}
}
}
use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.
the class FtpSession method openSftpClient.
private void openSftpClient(String remoteDirectory) throws FtpConnectException {
try {
// Set the connection properties and if necessary the proxy properties
SshConnectionProperties sshProp = new SshConnectionProperties();
sshProp.setHost(host);
sshProp.setPort(port);
if (StringUtils.isNotEmpty(prefCSEncryption))
sshProp.setPrefCSEncryption(prefCSEncryption);
if (StringUtils.isNotEmpty(prefSCEncryption))
sshProp.setPrefCSEncryption(prefSCEncryption);
if (!StringUtils.isEmpty(proxyHost)) {
sshProp.setTransportProvider(proxyTransportType);
sshProp.setProxyHost(proxyHost);
sshProp.setProxyPort(proxyPort);
CredentialFactory pcf = new CredentialFactory(getProxyAuthAlias(), proxyUsername, proxyPassword);
if (!StringUtils.isEmpty(pcf.getUsername())) {
sshProp.setProxyUsername(pcf.getUsername());
sshProp.setProxyPassword(pcf.getPassword());
}
}
// make a secure connection with the remote host
sshClient = new SshClient();
if (StringUtils.isNotEmpty(knownHostsPath)) {
AbstractKnownHostsKeyVerification hv = null;
if (consoleKnownHostsVerifier) {
hv = new ConsoleKnownHostsKeyVerification(knownHostsPath);
} else {
hv = new SftpHostVerification(knownHostsPath);
}
sshClient.connect(sshProp, hv);
} else {
sshClient.connect(sshProp, new IgnoreHostKeyVerification());
}
SshAuthenticationClient sac;
if (!isKeyboardInteractive()) {
// pass the authentication information
sac = getSshAuthentication();
} else {
// TODO: detecteren dat sshClient.getAvailableAuthMethods("ftpmsg")
// wel keyboard-interactive terug geeft, maar geen password en dan deze methode
// gebruiken
final CredentialFactory credentialFactory = new CredentialFactory(getAuthAlias(), getUsername(), getPassword());
KBIAuthenticationClient kbiAuthenticationClient = new KBIAuthenticationClient();
kbiAuthenticationClient.setUsername(credentialFactory.getUsername());
kbiAuthenticationClient.setKBIRequestHandler(new KBIRequestHandler() {
public void showPrompts(String name, String instruction, KBIPrompt[] prompts) {
// deze 3 regels in x.zip naar Zenz gemaild, hielp ook niet
if (prompts == null) {
return;
}
for (int i = 0; i < prompts.length; i++) {
prompts[i].setResponse(credentialFactory.getPassword());
}
}
});
sac = kbiAuthenticationClient;
}
int result = sshClient.authenticate(sac);
if (result != AuthenticationProtocolState.COMPLETE) {
closeSftpClient();
throw new IOException("Could not authenticate to sftp server " + result);
}
// use the connection for sftp
sftpClient = sshClient.openSftpClient();
if (!StringUtils.isEmpty(remoteDirectory)) {
sftpClient.cd(remoteDirectory);
}
} catch (Exception e) {
closeSftpClient();
throw new FtpConnectException(e);
}
}
use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.
the class FtpSession method openFtpClient.
private void openFtpClient(String remoteDirectory) throws FtpConnectException {
try {
// set proxy properties
if (!StringUtils.isEmpty(proxyHost)) {
System.getProperties().put("ftpProxySet", "true");
System.getProperties().put("ftpProxyHost", proxyHost);
System.getProperties().put("ftpProxyPort", "" + proxyPort);
}
// connect and logic using normal, non-secure ftp
ftpClient = createFTPClient();
ftpClient.connect(host, port);
if (isPassive()) {
ftpClient.enterLocalPassiveMode();
}
CredentialFactory usercf = new CredentialFactory(getAuthAlias(), getUsername(), getPassword());
ftpClient.login(usercf.getUsername(), usercf.getPassword());
if (!StringUtils.isEmpty(remoteDirectory)) {
ftpClient.changeWorkingDirectory(remoteDirectory);
checkReply("changeWorkingDirectory " + remoteDirectory);
}
if (StringUtils.isNotEmpty(fileType)) {
ftpClient.setFileType(getFileTypeIntValue());
checkReply("setFileType " + remoteDirectory);
}
} catch (Exception e) {
closeFtpClient();
throw new FtpConnectException(e);
}
}
use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.
the class EsbUtils method getEsbConnectionFactoryInfo.
private static EsbConnectionFactoryInfo getEsbConnectionFactoryInfo(EsbJmsListener esbJmsListener) {
String cfUrl = null;
String cfUserName = null;
String cfPassword = null;
Object managedConnectionFactory = null;
try {
managedConnectionFactory = esbJmsListener.getManagedConnectionFactory();
} catch (JmsException e) {
log.warn("error occured during getting managed connection factory: " + e.getMessage());
}
if (managedConnectionFactory == null) {
log.warn("could not get managed connection factory");
} else {
String contextFactoryClassname = getContextFactoryClassname(managedConnectionFactory);
if (contextFactoryClassname == null) {
log.warn("could not get context factory");
} else {
cfUrl = getProviderURL(managedConnectionFactory);
String authDataAlias = getAuthDataAlias(managedConnectionFactory);
if (authDataAlias != null) {
CredentialFactory cf = new CredentialFactory(authDataAlias, null, null);
cfUserName = cf.getUsername();
cfPassword = cf.getPassword();
}
if (!contextFactoryClassname.equals("com.tibco.tibjms.naming.TibjmsInitialContextFactory")) {
log.warn("did not expect context factory of type [" + contextFactoryClassname + "]");
} else {
return new EsbConnectionFactoryInfo(managedConnectionFactory, contextFactoryClassname, cfUrl, cfUserName, cfPassword);
}
}
}
return null;
}
use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.
the class EsbUtils method getPoolingDataSource.
public static PoolingDataSource getPoolingDataSource(JdbcTransactionalStorage errorStorage) {
String dsUrl = null;
String dsUserName = null;
String dsPassword = null;
java.sql.Connection errorStorageConnection = null;
try {
errorStorageConnection = errorStorage.getConnection();
} catch (JdbcException e) {
log.warn("error occured during getting errorStorage connection: " + e.getMessage());
}
if (errorStorageConnection == null) {
log.warn("could not get errorStorage connection");
} else {
DatabaseMetaData md;
try {
md = errorStorageConnection.getMetaData();
dsUrl = md.getURL();
// dsUserName = md.getUserName();
// dsPassword = md.getPassword();
} catch (SQLException e) {
log.warn("error occured during getting errorStorage metadata: " + e.getMessage());
}
if (dsUrl == null) {
log.warn("could not get errorStorage url");
} else {
// onderstaande is nodig omdat het niet mogelijk is het
// password op te vragen uit het DatabaseMetaData object of
// uit het Connection object
String confResString = null;
try {
confResString = Misc.getConfigurationResources();
if (confResString != null) {
confResString = XmlUtils.removeNamespaces(confResString);
}
} catch (IOException e) {
log.warn("error getting configuration resources: " + e.getMessage());
}
String authDataAlias = null;
if (confResString != null) {
String dsName = null;
try {
dsName = errorStorage.getDataSourceNameToUse();
} catch (JdbcException e) {
log.warn("error getting datasource name to use: " + e.getMessage());
}
if (dsName != null) {
String xpathExpression = "XMI/JDBCProvider/factories[@jndiName='" + dsName + "']/@authDataAlias";
try {
Transformer t = XmlUtils.createXPathEvaluator(xpathExpression);
authDataAlias = XmlUtils.transformXml(t, confResString);
} catch (Exception e) {
log.warn("error getting datasource authDataAlias: " + e.getMessage());
}
}
}
if (StringUtils.isEmpty(authDataAlias)) {
log.warn("could not get errorStorage authDataAlias");
} else {
CredentialFactory cf = new CredentialFactory(authDataAlias, null, null);
dsUserName = cf.getUsername();
dsPassword = cf.getPassword();
return setupJdbcDataSource(dsUrl, dsUserName, dsPassword);
}
}
}
return null;
}
Aggregations