use of javax.wbem.client.PasswordCredential in project coprhd-controller by CoprHD.
the class BrocadeNetworkSystemDevice method getWBEMClient.
private WBEMClient getWBEMClient(String ipaddress, String smisport, String username, String password, boolean useSSL) throws NetworkDeviceControllerException {
try {
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_049);
WBEMClient client = WBEMClientFactory.getClient(WBEMClientConstants.PROTOCOL_CIMXML);
String protocol = useSSL ? CimConstants.SECURE_PROTOCOL : CimConstants.DEFAULT_PROTOCOL;
CIMObjectPath path = CimObjectPathCreator.createInstance(protocol, ipaddress, smisport.toString(), BrocadeNetworkSMIS.getNamespace(), null, null);
final Subject subject = new Subject();
subject.getPrincipals().add(new UserPrincipal(username));
subject.getPrivateCredentials().add(new PasswordCredential(password));
client.initialize(path, subject, new Locale[] { Locale.US });
return client;
} catch (WBEMException ex) {
_log.info("Failed to connect to Brocade at IP: " + ipaddress + " because: " + ex.getLocalizedMessage());
throw NetworkDeviceControllerException.exceptions.getWBEMClientFailed(ipaddress, ex);
}
}
use of javax.wbem.client.PasswordCredential in project coprhd-controller by CoprHD.
the class DCNMDialog method getClient.
/**
* Initialize the client interface.
*
* @param ipaddress
* @param username
* @param password
* @param smisport
* @return WBEMClient
*/
public WBEMClient getClient(String ipaddress, String username, String password, Integer smisport) {
try {
WBEMClient client = WBEMClientFactory.getClient(WBEMClientConstants.PROTOCOL_CIMXML);
CIMObjectPath path = CimObjectPathCreator.createInstance("http", ipaddress, smisport.toString(), _namespace, null, null);
final Subject subject = new Subject();
subject.getPrincipals().add(new UserPrincipal(username));
subject.getPrivateCredentials().add(new PasswordCredential(password));
client.initialize(path, subject, new Locale[] { Locale.US });
_client = client;
return client;
} catch (WBEMException ex) {
_log.error("Can't open client: WBEMException: " + ex.getLocalizedMessage());
return null;
}
}
use of javax.wbem.client.PasswordCredential in project coprhd-controller by CoprHD.
the class HDSCommunicationInterface method getCIMClient.
/**
* Creates a new WEBClient for a given IP, based on AccessProfile
*
* @param accessProfile
* : AccessProfile for the providers
* @throws WBEMException
* : if WBEMException while creating the WBEMClient
* @throws SMIPluginException
* @return WBEMClient : initialized instance of WBEMClientCIMXML
*/
private WBEMClient getCIMClient(AccessProfile accessProfile) throws Exception {
String protocol = Boolean.valueOf(accessProfile.getSslEnable()) ? CimConstants.SECURE_PROTOCOL : CimConstants.DEFAULT_PROTOCOL;
CIMObjectPath path = CimObjectPathCreator.createInstance(protocol, accessProfile.getIpAddress(), Integer.toString(accessProfile.getPortNumber()), accessProfile.getInteropNamespace(), null, null);
try {
Subject subject = new Subject();
subject.getPrincipals().add(new UserPrincipal(accessProfile.getUserName()));
subject.getPrivateCredentials().add(new PasswordCredential(accessProfile.getPassword()));
wbemClient = WBEMClientFactory.getClient(CimConstants.CIM_CLIENT_PROTOCOL);
// Operations block by default, so a timeout must be set in case the
// CIM server becomes unreachable.
// Commenting out, as timeout had been moved to cimom.properties
// file
// _cimClient.setProperty(WBEMClientConstants.PROP_TIMEOUT,
// CimConstants.CIM_CLIENT_TIMEOUT);
wbemClient.initialize(path, subject, null);
} catch (Exception e) {
_logger.error("Could not establish connection for {}", accessProfile.getIpAddress(), e);
wbemClient.close();
throw e;
}
return wbemClient;
}
use of javax.wbem.client.PasswordCredential in project coprhd-controller by CoprHD.
the class CimConnection method connect.
/**
* Opens the connection and sets up indication subscriptions on the CIMOM.
* Call is synchronized by the caller {@link ConnectionManager}. If the
* passed flag indicates, prior to setting up the indication subscriptions
* for the connection, the subscription manager should attempt to delete any
* old/stale subscriptions that exist on the provider to which the
* connection is being made. The passed identifier is used by the
* subscription manager to identify the stale subscriptions to be deleted.
*
* Also registers this connection with the indication listener.
*
* @param subscriptionsIdentifier The identifier to be used to identify
* subscriptions on the provider.
* @param deleteStaleSubscriptions true to delete stale subscriptions on the
* provider to which the connection is being made.
*
* @throws Exception if the connection cannot be established or if there is
* a problem setting up subscriptions.
*/
public void connect(String subscriptionsIdentifier, boolean deleteStaleSubscriptions) throws Exception {
s_logger.info("Establising connection for {}", _connectionName);
String protocol = _useSSL ? CimConstants.SECURE_PROTOCOL : CimConstants.DEFAULT_PROTOCOL;
CIMObjectPath path = CimObjectPathCreator.createInstance(protocol, _host, Integer.toString(_port), _interopNS, null, null);
try {
Subject subject = new Subject();
subject.getPrincipals().add(new UserPrincipal(_user));
subject.getPrivateCredentials().add(new PasswordCredential(_pass_word));
_cimClient = WBEMClientFactory.getClient(CimConstants.CIM_CLIENT_PROTOCOL);
// Operations block by default, so a timeout must be set in case the
// CIM server becomes unreachable.
// Commenting out, as timeout had been moved to cimom.properties file
// _cimClient.setProperty(WBEMClientConstants.PROP_TIMEOUT, CimConstants.CIM_CLIENT_TIMEOUT);
_cimClient.initialize(path, subject, null);
} catch (Exception e) {
s_logger.error("Could not establish connection for {}", _host, e);
_cimClient.close();
throw e;
}
}
use of javax.wbem.client.PasswordCredential in project coprhd-controller by CoprHD.
the class CommunicationInterfaceTest method getCIMClient.
private void getCIMClient(AccessProfile accessProfile, WBEMClient cimClient) throws SMIPluginException {
try {
CIMObjectPath path = CimObjectPathCreator.createInstance(accessProfile.getProtocol(), accessProfile.getIpAddress(), accessProfile.getProviderPort(), accessProfile.getInteropNamespace(), null, null);
UserPrincipal userPr = new UserPrincipal(accessProfile.getUserName(), accessProfile.getIpAddress());
PasswordCredential pwCred = new PasswordCredential(accessProfile.getPassword(), accessProfile.getIpAddress());
Subject subject = new Subject();
subject.getPrincipals().add(userPr);
subject.getPublicCredentials().add(pwCred);
subject.getPrivateCredentials().add(pwCred);
cimClient.initialize(path, subject, new Locale[] { Locale.US });
} catch (WBEMException e) {
final int errorCode = e.getID() + SMIPluginException.ERRORCODE_START_WBEMEXCEPTION;
// _logger.error(fetchWBEMErrorMessage(e), errorCode);
throw new SMIPluginException("CIMOM Initializing Error", errorCode);
}
}
Aggregations