本文整理汇总了Java中org.apache.ftpserver.usermanager.impl.WriteRequest类的典型用法代码示例。如果您正苦于以下问题:Java WriteRequest类的具体用法?Java WriteRequest怎么用?Java WriteRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WriteRequest类属于org.apache.ftpserver.usermanager.impl包,在下文中一共展示了WriteRequest类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isWritable
import org.apache.ftpserver.usermanager.impl.WriteRequest; //导入依赖的package包/类
/**
* Check file write permission.
*/
public boolean isWritable() {
LOG.debug("Checking authorization for " + getAbsolutePath());
if (user.authorize(new WriteRequest(getAbsolutePath())) == null) {
LOG.debug("Not authorized");
return false;
}
LOG.debug("Checking if file exists");
if (file.exists()) {
LOG.debug("Checking can write: " + file.canWrite());
return file.canWrite();
}
LOG.debug("Authorized");
return true;
}
示例2: isRemovable
import org.apache.ftpserver.usermanager.impl.WriteRequest; //导入依赖的package包/类
/**
* Has delete permission.
*/
public boolean isRemovable() {
// root cannot be deleted
if ("/".equals(fileName)) {
return false;
}
/* Added 12/08/2008: in the case that the permission is not explicitly denied for this file
* we will check if the parent file has write permission as most systems consider that a file can
* be deleted when their parent directory is writable.
*/
String fullName = getAbsolutePath();
// we check FTPServer's write permission for this file.
if (user.authorize(new WriteRequest(fullName)) == null) {
return false;
}
// In order to maintain consistency, when possible we delete the last '/' character in the String
int indexOfSlash = fullName.lastIndexOf('/');
String parentFullName;
if (indexOfSlash == 0) {
parentFullName = "/";
} else {
parentFullName = fullName.substring(0, indexOfSlash);
}
// we check if the parent FileObject is writable.
NativeFtpFile parentObject = new NativeFtpFile(parentFullName, file
.getAbsoluteFile().getParentFile(), user);
return parentObject.isWritable();
}
示例3: save
import org.apache.ftpserver.usermanager.impl.WriteRequest; //导入依赖的package包/类
/**
* Save user data. Store the properties.
*/
public synchronized void save(User usr) throws FtpException {
// null value check
if (usr.getName() == null) {
throw new NullPointerException("User name is null.");
}
String thisPrefix = PREFIX + usr.getName() + '.';
// set other properties
userDataProp.setProperty(thisPrefix + ATTR_PASSWORD, getPassword(usr));
String home = usr.getHomeDirectory();
if (home == null) {
home = "/";
}
userDataProp.setProperty(thisPrefix + ATTR_HOME, home);
userDataProp.setProperty(thisPrefix + ATTR_ENABLE, usr.getEnabled());
userDataProp.setProperty(thisPrefix + ATTR_WRITE_PERM, usr
.authorize(new WriteRequest()) != null);
userDataProp.setProperty(thisPrefix + ATTR_MAX_IDLE_TIME, usr
.getMaxIdleTime());
TransferRateRequest transferRateRequest = new TransferRateRequest();
transferRateRequest = (TransferRateRequest) usr
.authorize(transferRateRequest);
if (transferRateRequest != null) {
userDataProp.setProperty(thisPrefix + ATTR_MAX_UPLOAD_RATE,
transferRateRequest.getMaxUploadRate());
userDataProp.setProperty(thisPrefix + ATTR_MAX_DOWNLOAD_RATE,
transferRateRequest.getMaxDownloadRate());
} else {
userDataProp.remove(thisPrefix + ATTR_MAX_UPLOAD_RATE);
userDataProp.remove(thisPrefix + ATTR_MAX_DOWNLOAD_RATE);
}
// request that always will succeed
ConcurrentLoginRequest concurrentLoginRequest = new ConcurrentLoginRequest(
0, 0);
concurrentLoginRequest = (ConcurrentLoginRequest) usr
.authorize(concurrentLoginRequest);
if (concurrentLoginRequest != null) {
userDataProp.setProperty(thisPrefix + ATTR_MAX_LOGIN_NUMBER,
concurrentLoginRequest.getMaxConcurrentLogins());
userDataProp.setProperty(thisPrefix + ATTR_MAX_LOGIN_PER_IP,
concurrentLoginRequest.getMaxConcurrentLoginsPerIP());
} else {
userDataProp.remove(thisPrefix + ATTR_MAX_LOGIN_NUMBER);
userDataProp.remove(thisPrefix + ATTR_MAX_LOGIN_PER_IP);
}
saveUserData();
}
示例4: startFtpServer
import org.apache.ftpserver.usermanager.impl.WriteRequest; //导入依赖的package包/类
@Before
public void startFtpServer() throws Exception {
recursiveDelete(resolvePath(FTP_ROOT_DIR).toFile());
File usersFile = USERS_FILE.toFile();
usersFile.createNewFile();
NativeFileSystemFactory fsf = new NativeFileSystemFactory();
fsf.setCreateHome(true);
PropertiesUserManagerFactory pumf = new PropertiesUserManagerFactory();
pumf.setAdminName("admin");
pumf.setPasswordEncryptor(new ClearTextPasswordEncryptor());
pumf.setFile(usersFile);
UserManager userMgr = pumf.createUserManager();
BaseUser user = new BaseUser();
user.setName("admin");
user.setPassword("admin");
user.setHomeDirectory(FTP_ROOT_DIR.toString());
List<Authority> authorities = new ArrayList<>();
WritePermission writePermission = new WritePermission();
writePermission.authorize(new WriteRequest());
authorities.add(writePermission);
user.setAuthorities(authorities);
userMgr.save(user);
ListenerFactory factory1 = new ListenerFactory();
factory1.setPort(PORT);
FtpServerFactory serverFactory = new FtpServerFactory();
serverFactory.setUserManager(userMgr);
serverFactory.setFileSystem(fsf);
serverFactory.setConnectionConfig(new ConnectionConfigFactory().createConnectionConfig());
serverFactory.addListener("default", factory1.createListener());
FtpServerFactory factory = serverFactory;
ftpServer = factory.createServer();
ftpServer.start();
}
示例5: execute
import org.apache.ftpserver.usermanager.impl.WriteRequest; //导入依赖的package包/类
/**
* Execute command.
*/
public void execute(final FtpIoSession session,
final FtpServerContext context, final FtpRequest request)
throws IOException, FtpException {
// reset state variables
session.resetState();
// only administrator can execute this
UserManager userManager = context.getUserManager();
boolean isAdmin = userManager.isAdmin(session.getUser().getName());
if (!isAdmin) {
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_530_NOT_LOGGED_IN, "SITE", null));
return;
}
// get the user name
String argument = request.getArgument();
int spIndex = argument.indexOf(' ');
if (spIndex == -1) {
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS,
"SITE.DESCUSER", null));
return;
}
String userName = argument.substring(spIndex + 1);
// check the user existance
UserManager usrManager = context.getUserManager();
User user = null;
try {
if (usrManager.doesExist(userName)) {
user = usrManager.getUserByName(userName);
}
} catch (FtpException ex) {
LOG.debug("Exception trying to get user from user manager", ex);
}
if (user == null) {
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"SITE.DESCUSER", userName));
return;
}
// send the user information
StringBuilder sb = new StringBuilder(128);
sb.append("\n");
sb.append("userid : ").append(user.getName()).append("\n");
sb.append("userpassword : ********\n");
sb.append("homedirectory : ").append(user.getHomeDirectory()).append(
"\n");
sb.append("writepermission : ").append(
user.authorize(new WriteRequest()) != null).append("\n");
sb.append("enableflag : ").append(user.getEnabled()).append("\n");
sb.append("idletime : ").append(user.getMaxIdleTime()).append(
"\n");
TransferRateRequest transferRateRequest = new TransferRateRequest();
transferRateRequest = (TransferRateRequest) session.getUser()
.authorize(transferRateRequest);
if (transferRateRequest != null) {
sb.append("uploadrate : ").append(
transferRateRequest.getMaxUploadRate()).append("\n");
sb.append("downloadrate : ").append(
transferRateRequest.getMaxDownloadRate()).append("\n");
} else {
sb.append("uploadrate : 0\n");
sb.append("downloadrate : 0\n");
}
sb.append('\n');
session.write(new DefaultFtpReply(FtpReply.REPLY_200_COMMAND_OKAY, sb
.toString()));
}