use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.
the class CmisSender method connect.
private Session connect(String userName, String password) {
log.debug(getLogPrefix() + "connecting with url [" + getUrl() + "] repository [" + getRepository() + "]");
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Map<String, String> parameter = new HashMap<String, String>();
parameter.put(SessionParameter.USER, userName);
parameter.put(SessionParameter.PASSWORD, password);
if (getBindingType().equalsIgnoreCase("atompub")) {
parameter.put(SessionParameter.ATOMPUB_URL, getUrl());
parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
} else if (getBindingType().equalsIgnoreCase("browser")) {
parameter.put(SessionParameter.BROWSER_URL, getUrl());
parameter.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());
} else {
parameter.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, getUrl() + "/RepositoryService.svc?wsdl");
parameter.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, getUrl() + "/NavigationService.svc?wsdl");
parameter.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, getUrl() + "/ObjectService.svc?wsdl");
parameter.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, getUrl() + "/VersioningService.svc?wsdl");
parameter.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, getUrl() + "/DiscoveryService.svc?wsdl");
parameter.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, getUrl() + "/RelationshipService.svc?wsdl");
parameter.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, getUrl() + "/MultiFilingService.svc?wsdl");
parameter.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, getUrl() + "/PolicyService.svc?wsdl");
parameter.put(SessionParameter.WEBSERVICES_ACL_SERVICE, getUrl() + "/ACLService.svc?wsdl");
parameter.put(SessionParameter.BINDING_TYPE, BindingType.WEBSERVICES.value());
}
parameter.put(SessionParameter.REPOSITORY_ID, getRepository());
// SSL
if (getCertificate() != null || getTruststore() != null || isAllowSelfSignedCertificates()) {
CredentialFactory certificateCf = new CredentialFactory(getCertificateAuthAlias(), null, getCertificatePassword());
CredentialFactory truststoreCf = new CredentialFactory(getTruststoreAuthAlias(), null, getTruststorePassword());
parameter.put("certificateUrl", getCertificate());
parameter.put("certificatePassword", certificateCf.getPassword());
parameter.put("keystoreType", getKeystoreType());
parameter.put("keyManagerAlgorithm", getKeyManagerAlgorithm());
parameter.put("truststoreUrl", getTruststore());
parameter.put("truststorePassword", truststoreCf.getPassword());
parameter.put("truststoreType", getTruststoreType());
parameter.put("trustManagerAlgorithm", getTrustManagerAlgorithm());
}
// SSL+
parameter.put("isAllowSelfSignedCertificates", "" + isAllowSelfSignedCertificates());
parameter.put("isVerifyHostname", "" + isVerifyHostname());
parameter.put("isIgnoreCertificateExpiredException", "" + isIgnoreCertificateExpiredException());
// PROXY
if (StringUtils.isNotEmpty(getProxyHost())) {
CredentialFactory pcf = new CredentialFactory(getProxyAuthAlias(), getProxyUserName(), getProxyPassword());
parameter.put("proxyHost", getProxyHost());
parameter.put("proxyPort", "" + getProxyPort());
parameter.put("proxyUserName", pcf.getUsername());
parameter.put("proxyPassword", pcf.getPassword());
}
// Custom IBIS HttpSender to support ssl connections and proxies
parameter.put(SessionParameter.HTTP_INVOKER_CLASS, "nl.nn.adapterframework.extensions.cmis.CmisHttpInvoker");
Session session = sessionFactory.createSession(parameter);
log.debug(getLogPrefix() + "connected with repository [" + getRepositoryInfo(session) + "]");
return session;
}
use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.
the class CmisSender method getSession.
public Session getSession(ParameterResolutionContext prc) throws SenderException {
if (session == null || !isKeepSession()) {
String authAlias_work = null;
String userName_work = null;
String password_work = null;
ParameterValueList pvl = null;
try {
if (prc != null && paramList != null) {
pvl = prc.getValues(paramList);
if (pvl != null) {
ParameterValue pv = pvl.getParameterValue("authAlias");
if (pv != null) {
authAlias_work = (String) pv.getValue();
}
pv = pvl.getParameterValue("userName");
if (pv != null) {
userName_work = (String) pv.getValue();
}
pv = pvl.getParameterValue("password");
if (pv != null) {
password_work = (String) pv.getValue();
}
}
}
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + "Sender [" + getName() + "] caught exception evaluating parameters", e);
}
if (authAlias_work == null) {
authAlias_work = getAuthAlias();
}
if (userName_work == null) {
userName_work = getUserName();
}
if (password_work == null) {
password_work = getPassword();
}
CredentialFactory cf = new CredentialFactory(authAlias_work, userName_work, password_work);
session = connect(cf.getUsername(), cf.getPassword());
}
return session;
}
use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.
the class FtpSession method getSshAuthentication.
private SshAuthenticationClient getSshAuthentication() throws Exception {
if (StringUtils.isNotEmpty(privateKeyFilePath)) {
PublicKeyAuthenticationClient pk = new PublicKeyAuthenticationClient();
CredentialFactory pkcf = new CredentialFactory(getPrivateKeyAuthAlias(), getUsername(), getPrivateKeyPassword());
pk.setUsername(pkcf.getUsername());
SshPrivateKeyFile pkFile = SshPrivateKeyFile.parse(new File(privateKeyFilePath));
pk.setKey(pkFile.toPrivateKey(pkcf.getPassword()));
return pk;
}
CredentialFactory usercf = new CredentialFactory(getAuthAlias(), getUsername(), getPassword());
if (StringUtils.isNotEmpty(usercf.getPassword())) {
PasswordAuthenticationClient pac = new PasswordAuthenticationClient();
pac.setUsername(usercf.getUsername());
pac.setPassword(usercf.getPassword());
return pac;
}
throw new Exception("Unknown authentication type, either the password or the privateKeyFile must be filled");
}
use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.
the class MqttFacade method configure.
public void configure() throws ConfigurationException {
if (StringUtils.isEmpty(getClientId())) {
throw new ConfigurationException("clientId must be specified");
}
if (StringUtils.isEmpty(getBrokerUrl())) {
throw new ConfigurationException("brokerUrl must be specified");
}
if (StringUtils.isEmpty(getTopic())) {
throw new ConfigurationException("topic must be specified");
}
if (StringUtils.isEmpty(getPersistenceDirectory())) {
throw new ConfigurationException("persistenceDirectory must be specified");
}
connectOptions = new MqttConnectOptions();
connectOptions.setCleanSession(isCleanSession());
connectOptions.setAutomaticReconnect(isAutomaticReconnect());
connectOptions.setConnectionTimeout(getTimeout());
connectOptions.setKeepAliveInterval(getKeepAliveInterval());
// Default: 0, V3.1: 3, V3.1.1: 4
connectOptions.setMqttVersion(MqttConnectOptions.MQTT_VERSION_DEFAULT);
if (!StringUtils.isEmpty(getAuthAlias()) || (!StringUtils.isEmpty(getUsername()) && !StringUtils.isEmpty(getPassword()))) {
CredentialFactory credentialFactory = new CredentialFactory(getAuthAlias(), getUsername(), getPassword());
connectOptions.setUserName(credentialFactory.getUsername());
connectOptions.setPassword(credentialFactory.getPassword().toCharArray());
}
MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(getPersistenceDirectory());
try {
client = new MqttClient(brokerUrl, clientId, dataStore);
} catch (MqttException e) {
throw new ConfigurationException("Could not create client", e);
}
}
use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.
the class ExchangeMailListener method configure.
public void configure() throws ConfigurationException {
try {
exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
CredentialFactory cf = new CredentialFactory(getAuthAlias(), getUserName(), getPassword());
ExchangeCredentials credentials = new WebCredentials(cf.getUsername(), cf.getPassword());
exchangeService.setCredentials(credentials);
if (StringUtils.isNotEmpty(getMailAddress())) {
exchangeService.autodiscoverUrl(getMailAddress());
} else {
exchangeService.setUrl(new URI(getUrl()));
}
FolderId inboxId;
if (StringUtils.isNotEmpty(getMailAddress())) {
Mailbox mailbox = new Mailbox(getMailAddress());
inboxId = new FolderId(WellKnownFolderName.Inbox, mailbox);
} else {
inboxId = new FolderId(WellKnownFolderName.Inbox);
}
FindFoldersResults findFoldersResultsIn;
FolderView folderViewIn = new FolderView(10);
if (StringUtils.isNotEmpty(getInputFolder())) {
SearchFilter searchFilterIn = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, getInputFolder());
findFoldersResultsIn = exchangeService.findFolders(inboxId, searchFilterIn, folderViewIn);
if (findFoldersResultsIn.getTotalCount() == 0) {
throw new ConfigurationException("no (in) folder found with name [" + getInputFolder() + "]");
} else if (findFoldersResultsIn.getTotalCount() > 1) {
throw new ConfigurationException("multiple (in) folders found with name [" + getInputFolder() + "]");
}
} else {
findFoldersResultsIn = exchangeService.findFolders(inboxId, folderViewIn);
}
folderIn = findFoldersResultsIn.getFolders().get(0);
if (StringUtils.isNotEmpty(getFilter())) {
if (!getFilter().equalsIgnoreCase("NDR")) {
throw new ConfigurationException("illegal value for filter [" + getFilter() + "], must be 'NDR' or empty");
}
}
if (StringUtils.isNotEmpty(getOutputFolder())) {
SearchFilter searchFilterOut = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, getOutputFolder());
FolderView folderViewOut = new FolderView(10);
FindFoldersResults findFoldersResultsOut = exchangeService.findFolders(inboxId, searchFilterOut, folderViewOut);
if (findFoldersResultsOut.getTotalCount() == 0) {
throw new ConfigurationException("no (out) folder found with name [" + getOutputFolder() + "]");
} else if (findFoldersResultsOut.getTotalCount() > 1) {
throw new ConfigurationException("multiple (out) folders found with name [" + getOutputFolder() + "]");
}
folderOut = findFoldersResultsOut.getFolders().get(0);
}
} catch (Exception e) {
throw new ConfigurationException(e);
}
}
Aggregations