本文整理汇总了Java中org.apache.ftpserver.ftplet.User类的典型用法代码示例。如果您正苦于以下问题:Java User类的具体用法?Java User怎么用?Java User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
User类属于org.apache.ftpserver.ftplet包,在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllUserNames
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
@Override
public String[] getAllUserNames() throws FtpException
{
DetachedCriteria criteria = DetachedCriteria.forClass (
fr.gael.dhus.database.object.User.class);
criteria.add (Restrictions.eq ("deleted", false));
List<fr.gael.dhus.database.object.User> users = userService.getUsers (
criteria, 0, 0);
List<String> names = new LinkedList<> ();
for (fr.gael.dhus.database.object.User user : users)
{
names.add (user.getUsername ());
}
return names.toArray(new String[names.size()]);
}
示例2: createFileSystemView
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
@Override
public FileSystemView createFileSystemView(User user) throws FtpException {
final String home = user.getHomeDirectory();
final String owner = user.getName();
final String group = user.getName();
final int streamSize = FTPFile.DEFAULT_SIZE;
synchronized (this) {
if (mViews.isEmpty()) {
return new FTPFileSystemView(home, owner, group, streamSize);
} else {
final FTPFileSystemView view = mViews.remove(0);
view.init(home, owner, group, streamSize);
return view;
}
}
}
示例3: from
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
static FTPUser from(User user) {
final String name = user.getName();
final String password = user.getPassword();
final String homeDirectory = user.getHomeDirectory();
final boolean enable = user.getEnabled();
final int idleSec = user.getMaxIdleTime();
boolean hasWritePermission = false;
List<? extends Authority> authorities = user.getAuthorities();
if (authorities != null) {
for (Authority authority : authorities) {
if (authority instanceof WritePermission) {
hasWritePermission = true;
break;
}
}
}
return new FTPUser(name, password, homeDirectory, false,
enable, idleSec, hasWritePermission,
0, 0, 10, 10);
}
示例4: create
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
public User create() {
BaseUser user = new BaseUser();
user.setEnabled(mEnable);
user.setHomeDirectory(mHomeDirectory);
user.setMaxIdleTime(mIdleSec);
user.setName(mName);
if (!TextUtils.isEmpty(mPassword))
user.setPassword(mPassword);
final ArrayList<Authority> authorities = new ArrayList<>();
if (mHasWritePermission)
authorities.add(new WritePermission());
authorities.add(new TransferRatePermission(mMaxDownloadRate, mMaxUploadRate));
authorities.add(new ConcurrentLoginPermission(mMaxConcurrentLogin,
mMaxConcurrentLoginPerIP));
user.setAuthorities(authorities);
return user;
}
示例5: authenticate
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
/**
* Tries to do the login using a client generated on the fly
*/
@Override
public User authenticate(Authentication authentication)
throws AuthenticationFailedException {
if (authentication instanceof UsernamePasswordAuthentication) {
UsernamePasswordAuthentication auth = (UsernamePasswordAuthentication) authentication;
AdministratorGeoStoreClient client = new AdministratorGeoStoreClient();
client.setUsername(auth.getUsername());
client.setPassword(auth.getPassword());
client.setGeostoreRestUrl(this.client.getGeostoreRestUrl());
it.geosolutions.geostore.core.model.User gsUser = client
.getUserDetails();
User user = new GeoStoreFTPUser(gsUser, authoritiesProvider);
return user;
} else {
LOGGER.error("Unrecognized authentication type: "
+ authentication.getClass().getName());
throw new AuthenticationFailedException(
"Unrecognized authentication type: "
+ authentication.getClass().getName());
}
}
示例6: authenticate
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
@Override
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
if (authentication instanceof UsernamePasswordAuthentication) {
UsernamePasswordAuthentication usernameAndPassword = (UsernamePasswordAuthentication) authentication;
String username = usernameAndPassword.getUsername();
User user = users.get(username);
if (null == user) {
throw new AuthenticationFailedException("unknown user '" + username + "'");
}
String password = usernameAndPassword.getPassword();
if (getPasswordEncryptor().matches(password, user.getPassword())) {
return user;
} else {
throw new AuthenticationFailedException("password wrong");
}
}
throw new AuthenticationFailedException("try harder");
}
示例7: addUser
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
public FtpServerBuilder addUser(final String username, final String password, final File home, final boolean write) throws FtpException {
UserFactory userFactory = new UserFactory();
userFactory.setHomeDirectory(home.getAbsolutePath());
userFactory.setName(username);
userFactory.setPassword(password);
if (write) {
List<Authority> authorities = new ArrayList<Authority>();
Authority writePermission = new WritePermission();
authorities.add(writePermission);
userFactory.setAuthorities(authorities);
}
User user = userFactory.createUser();
ftpServerFactory.getUserManager().save(user);
return this;
}
示例8: getPassword
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
/**
* Get user password. Returns the encrypted value.
*
* <pre>
* If the password value is not null
* password = new password
* else
* if user does exist
* password = old password
* else
* password = ""
* </pre>
*/
private String getPassword(User usr) {
String name = usr.getName();
String password = usr.getPassword();
if (password != null) {
password = getPasswordEncryptor().encrypt(password);
} else {
String blankPassword = getPasswordEncryptor().encrypt("");
if (doesExist(name)) {
String key = PREFIX + name + '.' + ATTR_PASSWORD;
password = userDataProp.getProperty(key, blankPassword);
} else {
password = blankPassword;
}
}
return password;
}
示例9: createFileSystemView
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
/**
* Create the appropriate user file system view.
*/
public FileSystemView createFileSystemView(User user) throws FtpException {
synchronized (user) {
// create home if does not exist
if (createHome) {
String homeDirStr = user.getHomeDirectory();
File homeDir = new File(homeDirStr);
if (homeDir.isFile()) {
LOG.warn("Not a directory :: " + homeDirStr);
throw new FtpException("Not a directory :: " + homeDirStr);
}
if ((!homeDir.exists()) && (!homeDir.mkdirs())) {
LOG.warn("Cannot create user home :: " + homeDirStr);
throw new FtpException("Cannot create user home :: "
+ homeDirStr);
}
}
FileSystemView fsView = new NativeFileSystemView(user,
caseInsensitive);
return fsView;
}
}
示例10: NativeFtpFile
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
/**
* Constructor, internal do not use directly.
*/
protected NativeFtpFile(final String fileName, final File file,
final User user) {
if (fileName == null) {
throw new IllegalArgumentException("fileName can not be null");
}
if (file == null) {
throw new IllegalArgumentException("file can not be null");
}
if (fileName.length() == 0) {
throw new IllegalArgumentException("fileName can not be empty");
} else if (fileName.charAt(0) != '/') {
throw new IllegalArgumentException(
"fileName must be an absolut path");
}
this.fileName = fileName;
this.file = file;
this.user = user;
}
示例11: NativeFileSystemView
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
/**
* Constructor - internal do not use directly, use {@link NativeFileSystemFactory} instead
*/
public NativeFileSystemView(User user, boolean caseInsensitive)
throws FtpException {
if (user == null) {
throw new IllegalArgumentException("user can not be null");
}
if (user.getHomeDirectory() == null) {
throw new IllegalArgumentException(
"User home directory can not be null");
}
this.caseInsensitive = caseInsensitive;
// add last '/' if necessary
String rootDir = user.getHomeDirectory();
rootDir = normalizeSeparateChar(rootDir);
rootDir = appendSlash(rootDir);
LOG.debug("Native filesystem view created for user \"{}\" with root \"{}\"", user.getName(), rootDir);
this.rootDir = rootDir;
this.user = user;
currDir = "/";
}
示例12: getUserByName
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
/**
* Get the user object. Fetch the row from the table.
*/
public User getUserByName(String name) throws FtpException {
Statement stmt = null;
ResultSet rs = null;
try {
BaseUser user = selectUserByName(name);
if(user != null) {
// reset the password, not to be sent to API users
user.setPassword(null);
}
return user;
} catch (SQLException ex) {
LOG.error("DbUserManager.getUserByName()", ex);
throw new FtpException("DbUserManager.getUserByName()", ex);
} finally {
closeQuitely(rs);
closeQuitely(stmt);
}
}
示例13: testRefresh
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
public void testRefresh() throws FileNotFoundException, IOException {
Properties users = new Properties();
users.load(new FileInputStream(USERS_FILE));
String originalSetting = users.getProperty("ftpserver.user.user1.homedirectory");
users.setProperty("ftpserver.user.user1.homedirectory", "refresh_test");
users.store(new FileOutputStream(USERS_FILE), null);
PropertiesUserManager pum = (PropertiesUserManager) userManager;
pum.refresh();
User modifiedUser = pum.getUserByName("user1");
assertEquals("Home directory should have been \"refresh_test\" after call to refresh().","refresh_test",modifiedUser.getHomeDirectory());
// set everything back again
users.load(new FileInputStream(USERS_FILE));
users.setProperty("ftpserver.user.user1.homedirectory", originalSetting);
users.store(new FileOutputStream(USERS_FILE), null);
pum.refresh();
//check everything is back again
modifiedUser = pum.getUserByName("user1");
assertEquals("Home directory should have reset back to \""+originalSetting+"\" after second call to refresh().",originalSetting,modifiedUser.getHomeDirectory());
}
示例14: testSaveWithExistingUser
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
public void testSaveWithExistingUser() throws Exception {
BaseUser user = new BaseUser();
user.setName("user2");
user.setHomeDirectory("newhome");
userManager.save(user);
User actualUser = userManager.getUserByName("user2");
assertEquals("user2", actualUser.getName());
assertNull(actualUser.getPassword());
assertEquals("newhome", actualUser.getHomeDirectory());
assertEquals(0, getMaxDownloadRate(actualUser));
assertEquals(0, actualUser.getMaxIdleTime());
assertEquals(0, getMaxLoginNumber(actualUser));
assertEquals(0, getMaxLoginPerIP(actualUser));
assertEquals(0, getMaxUploadRate(actualUser));
assertNull(user.authorize(new WriteRequest()));
assertTrue(actualUser.getEnabled());
}
示例15: testSaveWithDefaultValues
import org.apache.ftpserver.ftplet.User; //导入依赖的package包/类
public void testSaveWithDefaultValues() throws Exception {
BaseUser user = new BaseUser();
user.setName("newuser");
user.setPassword("newpw");
userManager.save(user);
User actualUser = userManager.getUserByName("newuser");
assertEquals(user.getName(), actualUser.getName());
assertNull(actualUser.getPassword());
assertEquals("/", actualUser.getHomeDirectory());
assertEquals(true, actualUser.getEnabled());
assertNull(user.authorize(new WriteRequest()));
assertEquals(0, getMaxDownloadRate(actualUser));
assertEquals(0, actualUser.getMaxIdleTime());
assertEquals(0, getMaxLoginNumber(actualUser));
assertEquals(0, getMaxLoginPerIP(actualUser));
assertEquals(0, getMaxUploadRate(actualUser));
}