本文整理汇总了Java中org.apache.commons.vfs2.UserAuthenticationData类的典型用法代码示例。如果您正苦于以下问题:Java UserAuthenticationData类的具体用法?Java UserAuthenticationData怎么用?Java UserAuthenticationData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UserAuthenticationData类属于org.apache.commons.vfs2包,在下文中一共展示了UserAuthenticationData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createClient
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
/**
* Creates the client.
*
* @return the grid ftp client
*
* @throws FileSystemException the file system exception
*/
protected GridFTPClient createClient() throws FileSystemException {
final GenericFileName rootName = getRoot();
UserAuthenticationData authData = null;
try {
authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, GsiFtpFileProvider.AUTHENTICATOR_TYPES);
String username = UserAuthenticatorUtils
.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())).toString();
String password = UserAuthenticatorUtils
.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())).toString();
return GsiFtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), username, password, getFileSystemOptions());
} finally {
UserAuthenticatorUtils.cleanup(authData);
}
}
示例2: getStaticWorkingUserAuthForSmb
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
protected UserAuthenticationData getStaticWorkingUserAuthForSmb(AuthStore authStore, String url) {
LOGGER.debug("Checking if have credentials for {}", url);
VFSURIParser parser = new VFSURIParser(url);
if (parser.getHostname() != null) {
Collection<UserAuthenticationDataWrapper> userAuthenticationDatas = authStore.getUserAuthenticationDatas(parser.getProtocol().toString(),
parser.getHostname());
LOGGER.debug("Credentials count: {}", userAuthenticationDatas.size());
if (userAuthenticationDatas.size() > 0) {
UserAuthenticationData authenticationDataFromStore = userAuthenticationDatas.iterator().next();
LOGGER.debug("Returning static authenticator for {}", url);
return authenticationDataFromStore;
}
}
LOGGER.debug("Do not have credentials for {}", url);
return null;
}
示例3: testLoad
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
@Test
public void testLoad() throws Exception {
//given
MemoryAuthStore memoryAuthStore = new MemoryAuthStore();
InputStream resourceAsStream = this.getClass().getResourceAsStream("credentials.xml");
//when
authStoreUtils.load(memoryAuthStore, resourceAsStream);
//then
assertEquals(memoryAuthStore.getAll().size(), 3);
UserAuthenticationDataWrapper userAuthenticationData1 = memoryAuthStore.getUserAuthenticationData(new UserAuthenticationInfo("ftp", "host1", "stefan"));
assertEquals(userAuthenticationData1.getData(UserAuthenticationData.USERNAME), "Stefan".toCharArray());
LOGGER.info("Password for stefan:" + new String(userAuthenticationData1.getData(UserAuthenticationData.PASSWORD)));
assertEquals(userAuthenticationData1.getData(UserAuthenticationData.PASSWORD), "Password".toCharArray());
assertEquals(userAuthenticationData1.getData(new UserAuthenticationData.Type("path")), "c:\\file".toCharArray());
}
示例4: getData
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
/**
* gets data of given type from the UserAuthenticationData or null if there is no data or data
* of this type available.
* @param data The UserAuthenticationData.
* @param type The type of the element to retrieve.
* @param overriddenValue The default value.
* @return The data of the given type as a character array or null if the data is not available.
*/
public static char[] getData(UserAuthenticationData data, UserAuthenticationData.Type type,
char[] overriddenValue)
{
if (overriddenValue != null)
{
return overriddenValue;
}
if (data == null)
{
return null;
}
return data.getData(type);
}
示例5: createNfsFile
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
private XFile createNfsFile(final FileName fileName)
throws MalformedURLException, FileSystemException
{
final NfsFileName NfsFileName = (NfsFileName) fileName;
final String path = NfsFileName.getUriWithoutAuth();
UserAuthenticationData authData = null;
XFile file;
try
{
// no auth for nfs
/*authData = UserAuthenticatorUtils.authenticate(
getFileSystem().getFileSystemOptions(),
NfsFileProvider.AUTHENTICATOR_TYPES);*/
file = new XFile(path);
/*if (file.isDirectory() && !file.toString().endsWith("/"))
{
file = new XFile(path + "/");
}*/
return file;
}
finally
{
UserAuthenticatorUtils.cleanup(authData); // might be null
}
}
示例6: requestAuthentication
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
@Override
public UserAuthenticationData requestAuthentication(UserAuthenticationData.Type[] types) {
LOGGER.debug("Requested for authentication");
for (UserAuthenticationData.Type type : types) {
LOGGER.debug("Requested for authentication: %s",type);
}
if (data == null) {
return super.requestAuthentication(types);
} else {
return data;
}
}
示例7: userSelectedHook
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
@Override
protected void userSelectedHook(UserAuthenticationData userAuthenticationData) {
char[] domain = new char[0];
if (userAuthenticationData != null) {
domain = userAuthenticationData.getData(UserAuthenticationData.DOMAIN);
}
fieldTf.setText(new String(domain));
}
示例8: requestAuthentication
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
@Override
public UserAuthenticationData requestAuthentication(UserAuthenticationData.Type[] types) {
UserAuthenticationData userAuthenticationData = getStaticWorkingUserAuthForSmb(sessionAuthStore, getUrl());
if (userAuthenticationData ==null){
userAuthenticationData = otrosUserAuthenticator.requestAuthentication(types);
}
return userAuthenticationData;
}
示例9: requestAuthentication
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
@Override
public UserAuthenticationData requestAuthentication(Type[] types) {
try {
Runnable doRun = new Runnable() {
@Override
public void run() {
if (saveCredentialsCheckBox == null) {
saveCredentialsCheckBox = new JCheckBox(Messages.getMessage("authenticator.savePassword"), true);
}
JPanel authOptionPanel = getOptionsPanel();
JPanel panel = new JPanel(new BorderLayout());
panel.add(authOptionPanel);
panel.add(saveCredentialsCheckBox, BorderLayout.SOUTH);
String[] options = {Messages.getMessage("general.okButtonText"), Messages.getMessage("general.cancelButtonText")};
int showConfirmDialog = JOptionPane.showOptionDialog(null, panel, Messages.getMessage("authenticator.enterCredentials"),
JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
if (showConfirmDialog != JOptionPane.OK_OPTION) {
throw new AuthorisationCancelledException("Authorization cancelled by user");
}
data = new UserAuthenticationDataWrapper();
getAuthenticationData(data);
}
};
if (SwingUtilities.isEventDispatchThread()) {
doRun.run();
} else {
SwingUtilities.invokeAndWait(doRun);
}
} catch (Exception e) {
if (Throwables.getRootCause(e) instanceof AuthorisationCancelledException) {
throw (AuthorisationCancelledException) Throwables.getRootCause(e);
}
}
return data;
}
示例10: getAuthenticationData
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
@Override
protected void getAuthenticationData(UserAuthenticationData authenticationData) {
super.getAuthenticationData(authenticationData);
authenticationData.setData(UserAuthenticationDataWrapper.SSH_KEY, sshKeyFileField.getText().trim().toCharArray());
if (StringUtils.isNotBlank(sshKeyFileField.getText())) {
try {
SftpFileSystemConfigBuilder.getInstance().setIdentities(getFileSystemOptions(), new File[]{new File(sshKeyFileField.getText())});
//TODO set user auth data file path
} catch (FileSystemException e) {
e.printStackTrace();
}
}
}
示例11: userSelectedHook
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
@Override
protected void userSelectedHook(UserAuthenticationData userAuthenticationData) {
if (userAuthenticationData != null) {
char[] sshKeyPath = userAuthenticationData.getData(UserAuthenticationDataWrapper.SSH_KEY);
String path = "";
if (sshKeyPath != null && sshKeyPath.length > 0) {
path = new String(sshKeyPath);
}
sshKeyFileField.setText(path);
}
}
示例12: requestAuthentication
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
@Override
public UserAuthenticationData requestAuthentication(Type[] arg0) {
LOGGER.info("Received request for authentication");
UserAuthenticationDataWrapper data = new UserAuthenticationDataWrapper();
for (Type type : arg0) {
data.setData(type, userAuthenticationData.getData(type));
userAuthenticationDataWrapper.setData(type, userAuthenticationData.getData(type));
}
return data;
}
示例13: userSelected
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
private void userSelected(String user) {
UserAuthenticationData userAuthenticationData = getAuthStore().getUserAuthenticationData(new UserAuthenticationInfo(getVfsUriParser().getProtocol().getName(), getVfsUriParser().getHostname(), user));
char[] passChars = new char[0];
if (userAuthenticationData != null && userAuthenticationData.getData(UserAuthenticationData.PASSWORD) != null) {
passChars = userAuthenticationData.getData(UserAuthenticationData.PASSWORD);
}
passTx.setText(new String(passChars));
userSelectedHook(userAuthenticationData);
}
示例14: endElement
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (ENTRY.equals(localName)) {
authStore.add(info, userAuthenticationData);
} else if (USER_AUTHENTICATION_DATA.equals(localName)) {
// if (UserAuthenticationData.PASSWORD.equals(new UserAuthenticationData.Type(type))) {
// if (password == null){
// password = passwordProvider.getPassword("Enter password for password store");
// }
// if (password == null || password.length==0){
// throw new SAXException("Password for password store not entered");
// }
// Hex hex = new Hex();
// try {
// byte[] decode = (byte[]) hex.decode(data.trim());
// byte[] decrypted = decrypt(decode, password);
// char[] passwordWithSalt = bytesToChars(decrypted);
// char[] password = removeSalt(passwordWithSalt);
// data = new String(password);
// } catch (Exception e) {
// password=null;
// throw new SAXException("Can't decrypt password", e);
// }
// }
userAuthenticationData.setData(new UserAuthenticationData.Type(type), data.toCharArray());
} else if (DATA.equals(localName)) {
data = sb.toString();
} else if (TYPE.equals(localName)) {
type = sb.toString();
}
sb.setLength(0);
}
示例15: testSave
import org.apache.commons.vfs2.UserAuthenticationData; //导入依赖的package包/类
@Test(enabled = false)
public void testSave() throws Exception {
//given
AuthStore authStore = new MemoryAuthStore();
UserAuthenticationDataWrapper authenticationData1 = new UserAuthenticationDataWrapper();
authenticationData1.setData(UserAuthenticationData.USERNAME, "Stefan".toCharArray());
authenticationData1.setData(UserAuthenticationData.PASSWORD, "Password".toCharArray());
authenticationData1.setData(new UserAuthenticationData.Type("path"), "c:\\file".toCharArray());
UserAuthenticationDataWrapper authenticationData2 = new UserAuthenticationDataWrapper();
authenticationData2.setData(UserAuthenticationData.USERNAME, "Stefaan".toCharArray());
authenticationData2.setData(UserAuthenticationData.PASSWORD, "Passwodrd".toCharArray());
authenticationData2.setData(UserAuthenticationData.DOMAIN, "MS".toCharArray());
UserAuthenticationDataWrapper authenticationData3 = new UserAuthenticationDataWrapper();
authenticationData3.setData(UserAuthenticationData.USERNAME, "Stefan".toCharArray());
authenticationData3.setData(UserAuthenticationData.PASSWORD, "[email protected]".toCharArray());
authenticationData3.setData(UserAuthenticationData.DOMAIN, "MSzx!X%a".toCharArray());
authStore.add(new UserAuthenticationInfo("ftp", "host1", "stefan"), authenticationData1);
authStore.add(new UserAuthenticationInfo("ftp", "host1", "stefan9"), authenticationData1);
authStore.add(new UserAuthenticationInfo("sftp", "host1a", "astefan"), authenticationData1);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
String expected = IOUtils.toString(this.getClass().getResourceAsStream("credentials.xml"));
expected = expected.replaceAll(">\\s+", ">").replaceAll("\\s+<", "<").replaceAll("<Type>password</Type><Data>.*?<", "<Type>password</Type><Data><").trim();
//when
authStoreUtils.save(authStore, bout);
//then
System.out.println(new String(bout.toByteArray()));
String result = new String(bout.toByteArray()).replaceAll(">\\s+", ">").replaceAll("\\s+<", "<").replaceAll("<Type>password</Type><Data>.*?<", "<Type>password</Type><Data><").trim();
assertEquals(result, expected);
}