/** * @throws FtpException * always, operation not supported * @see org.apache.ftpserver.ftplet.UserManager#save(org.apache.ftpserver.ftplet.User) */ public void save(User user) throws FtpException { throw new FtpException("No custom user handling on this instance"); }
/** * Copy constructor. */ public BaseUser(User user) { name = user.getName(); password = user.getPassword(); authorities = user.getAuthorities(); maxIdleTimeSec = user.getMaxIdleTime(); homeDir = user.getHomeDirectory(); isEnabled = user.getEnabled(); }
/** * Unregister a user that will be rejected on new connections * * @param userName * The user name of the user to unregister * @throws FtpException */ public void unregisterUser(final String userName) throws FtpException { this.userManager.delete(userName); }
/** * Extracts the working directory of the current session to an absolute file system path * (contrary to what {@link FileSystemView#getWorkingDirectory() returns, which is relative to * the user's home dir}) */ private File workingDir(FtpSession session) throws FtpException { FtpFile workingDirectory = session.getFileSystemView().getWorkingDirectory(); String home = session.getUser().getHomeDirectory(); String absolutePath = workingDirectory.getAbsolutePath().substring(1); File workingDir = new File(new File(home), absolutePath); return workingDir; }
/** * Notifies the {@link FTPCallback} of a finished request to append content to an existing file * * @see FTPCallback#onAppendEnd */ @Override public FtpletResult onAppendEnd(FtpSession session, FtpRequest request) throws FtpException, IOException { UserDetails user = user(session.getUser()); File workingDir = workingDir(session); String fileName = request.getArgument(); return toFtpResult(callback.onAppendEnd(user, workingDir, fileName)); }
@Override public FtpletResult beforeCommand(FtpSession session, FtpRequest request) throws FtpException { if (session.getUser() != null) { Class<? extends Authority> authority = commandAuthorityMap.get(request.getCommand()); if (authority != null && session.getUser().getAuthorities(authority).isEmpty()) { session.write(new DefaultFtpReply(FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "Permission denied")); return FtpletResult.SKIP; } } return null; }
/** * Execute command */ public void execute(final FtpIoSession session, final FtpServerContext context, final FtpRequest request) throws IOException, FtpException { session.resetState(); FileSystemView fsview = session.getFileSystemView(); String currDir = fsview.getWorkingDirectory().getAbsolutePath(); session.write(LocalizedFtpReply.translate(session, request, context, FtpReply.REPLY_257_PATHNAME_CREATED, "PWD", currDir)); }
/** * @see FileFormater#format(FtpFile) */ public String format(FtpFile file) { StringBuilder sb = new StringBuilder(); sb.append(file.getName()); sb.append(NEWLINE); return sb.toString(); } }
/** * Copy constructor. */ public HdfsUser(User user) { name = user.getName(); password = user.getPassword(); authorities = user.getAuthorities(); maxIdleTimeSec = user.getMaxIdleTime(); homeDir = user.getHomeDirectory(); isEnabled = user.getEnabled(); }
/** * Notifies the {@link FTPCallback} of make directory requests * * @see FTPCallback#onMakeDirStart */ @Override public FtpletResult onMkdirStart(FtpSession session, FtpRequest request) throws FtpException, IOException { UserDetails user = user(session.getUser()); File workingDir = workingDir(session); String dirName = request.getArgument(); return toFtpResult(callback.onMakeDirStart(user, workingDir, dirName)); }
/** * @see org.apache.ftpserver.ftplet.UserManager#getAdminName() */ public String getAdminName() throws FtpException { throw new FtpException("No custom user handling on this instance"); }
/** * Notifies the {@link FTPCallback} of requests to append content to an existing file * * @see FTPCallback#onAppendStart */ @Override public FtpletResult onAppendStart(FtpSession session, FtpRequest request) throws FtpException, IOException { UserDetails user = user(session.getUser()); File workingDir = workingDir(session); String fileName = request.getArgument(); return toFtpResult(callback.onAppendStart(user, workingDir, fileName)); }
/** * @see org.apache.ftpserver.ftplet.UserManager#getAllUserNames() */ public String[] getAllUserNames() throws FtpException { throw new FtpException("No custom user handling on this instance"); }
/** * Notifies the {@link FTPCallback} of file delete requests * * @see FTPCallback#onDeleteStart */ @Override public FtpletResult onDeleteStart(FtpSession session, FtpRequest request) throws FtpException, IOException { UserDetails user = user(session.getUser()); File workingDir = workingDir(session); String fileName = request.getArgument(); return toFtpResult(callback.onDeleteStart(user, workingDir, fileName)); }
/** * @throws FtpException * always, operation not supported. * @see org.apache.ftpserver.ftplet.UserManager#delete(java.lang.String) */ public void delete(String username) throws FtpException { throw new FtpException("No custom user handling on this instance"); }
/** * Notifies the {@link FTPCallback} of file upload requests * * @see FTPCallback#onUploadStart */ @Override public FtpletResult onUploadStart(FtpSession session, FtpRequest request) throws FtpException, IOException { UserDetails user = user(session.getUser()); File workingDir = workingDir(session); String fileName = request.getArgument(); return toFtpResult(callback.onUploadStart(user, workingDir, fileName)); }
/** * Notifies the {@link FTPCallback} of remove directory success * * @see FTPCallback#onRemoveDirEnd */ @Override public FtpletResult onRmdirEnd(FtpSession session, FtpRequest request) throws FtpException, IOException { UserDetails user = user(session.getUser()); File workingDir = workingDir(session); String dirName = request.getArgument(); return toFtpResult(callback.onRemoveDirEnd(user, workingDir, dirName)); }
/** * Notifies the {@link FTPCallback} of file download requests * * @see FTPCallback#onDownloadStart */ @Override public FtpletResult onDownloadStart(FtpSession session, FtpRequest request) throws FtpException, IOException { UserDetails user = user(session.getUser()); File workingDir = workingDir(session); String fileName = request.getArgument(); return toFtpResult(callback.onDownloadStart(user, workingDir, fileName)); }
/** * Notifies the {@link FTPCallback} of file download success * * @see FTPCallback#onDownloadEnd */ @Override public FtpletResult onDownloadEnd(FtpSession session, FtpRequest request) throws FtpException, IOException { UserDetails user = user(session.getUser()); File workingDir = workingDir(session); String fileName = request.getArgument(); return toFtpResult(callback.onDownloadEnd(user, workingDir, fileName)); }
/** * Notifies the {@link FTPCallback} of remove directory requests * * @see FTPCallback#onRemoveDirStart */ @Override public FtpletResult onRmdirStart(FtpSession session, FtpRequest request) throws FtpException, IOException { UserDetails user = user(session.getUser()); File workingDir = workingDir(session); String dirName = request.getArgument(); return toFtpResult(callback.onRemoveDirStart(user, workingDir, dirName)); }