use of org.eclipse.ecf.core.security.NameCallback in project ecf by eclipse.
the class HttpClientFileSystemBrowser method getFileRequestCredentials.
/**
* Retrieves the credentials for requesting the file.
* @return the {@link Credentials} necessary to retrieve the file
* @throws UnsupportedCallbackException if the callback fails
* @throws IOException if IO fails
* @since 5.0
*/
protected Credentials getFileRequestCredentials() throws UnsupportedCallbackException, IOException {
if (connectContext == null)
return null;
final CallbackHandler callbackHandler = connectContext.getCallbackHandler();
if (callbackHandler == null)
return null;
final NameCallback usernameCallback = new NameCallback(USERNAME_PREFIX);
final ObjectCallback passwordCallback = new ObjectCallback();
callbackHandler.handle(new Callback[] { usernameCallback, passwordCallback });
username = usernameCallback.getName();
password = (String) passwordCallback.getObject();
return new UsernamePasswordCredentials(username, password);
}
use of org.eclipse.ecf.core.security.NameCallback in project ecf by eclipse.
the class HttpClientRetrieveFileTransfer method getFileRequestCredentials.
/**
* @return Credentials file request credentials
* @throws UnsupportedCallbackException if some problem
* @throws IOException if some problem
* @since 5.0
*/
protected Credentials getFileRequestCredentials() throws UnsupportedCallbackException, IOException {
if (connectContext == null)
return null;
final CallbackHandler callbackHandler = connectContext.getCallbackHandler();
if (callbackHandler == null)
return null;
final NameCallback usernameCallback = new NameCallback(USERNAME_PREFIX);
final ObjectCallback passwordCallback = new ObjectCallback();
callbackHandler.handle(new Callback[] { usernameCallback, passwordCallback });
username = usernameCallback.getName();
password = (String) passwordCallback.getObject();
return new UsernamePasswordCredentials(username, password);
}
use of org.eclipse.ecf.core.security.NameCallback in project ecf by eclipse.
the class AbstractBBContainer method getCredentialsFromConnectContext.
protected IBBCredentials getCredentialsFromConnectContext(IConnectContext connectContext) throws ContainerConnectException {
try {
if (connectContext == null) {
return null;
}
Callback[] callbacks = new Callback[2];
callbacks[0] = new NameCallback("Username");
callbacks[1] = new ObjectCallback();
CallbackHandler handler = connectContext.getCallbackHandler();
if (handler != null) {
handler.handle(callbacks);
}
NameCallback nc = (NameCallback) callbacks[0];
ObjectCallback cb = (ObjectCallback) callbacks[1];
return new Credentials(nc.getName(), (String) cb.getObject());
} catch (Exception e) {
throw new ContainerConnectException("Exception in CallbackHandler.handle(<callbacks>)", e);
}
}
use of org.eclipse.ecf.core.security.NameCallback in project ecf by eclipse.
the class UrlConnectionRetrieveFileTransfer method setupAuthentication.
protected void setupAuthentication() throws IOException, UnsupportedCallbackException {
if (connectContext == null)
return;
final CallbackHandler callbackHandler = connectContext.getCallbackHandler();
if (callbackHandler == null)
return;
final NameCallback usernameCallback = new NameCallback(USERNAME_PREFIX);
final ObjectCallback passwordCallback = new ObjectCallback();
// Call callback with username and password callbacks
callbackHandler.handle(new Callback[] { usernameCallback, passwordCallback });
username = usernameCallback.getName();
Object o = passwordCallback.getObject();
if (!(o instanceof String))
throw new UnsupportedCallbackException(passwordCallback, Messages.UrlConnectionRetrieveFileTransfer_UnsupportedCallbackException);
password = (String) passwordCallback.getObject();
// Now set authenticator to our authenticator with user and password
Authenticator.setDefault(new UrlConnectionAuthenticator());
}
use of org.eclipse.ecf.core.security.NameCallback in project ecf by eclipse.
the class URLFileSystemBrowser method setupAuthentication.
protected void setupAuthentication() throws IOException, UnsupportedCallbackException {
if (connectContext == null)
return;
final CallbackHandler callbackHandler = connectContext.getCallbackHandler();
if (callbackHandler == null)
return;
final NameCallback usernameCallback = new NameCallback(USERNAME_PREFIX);
final ObjectCallback passwordCallback = new ObjectCallback();
// Call callback with username and password callbacks
callbackHandler.handle(new Callback[] { usernameCallback, passwordCallback });
username = usernameCallback.getName();
Object o = passwordCallback.getObject();
if (!(o instanceof String))
throw new UnsupportedCallbackException(passwordCallback, Messages.UrlConnectionRetrieveFileTransfer_UnsupportedCallbackException);
password = (String) passwordCallback.getObject();
// Now set authenticator to our authenticator with user and password
Authenticator.setDefault(new UrlConnectionAuthenticator());
}
Aggregations