/** * Copy constructor. */ public BaseUser(User user) { name = user.getName(); password = user.getPassword(); authorities = user.getAuthorities(); maxIdleTimeSec = user.getMaxIdleTime(); homeDir = user.getHomeDirectory(); isEnabled = user.getEnabled(); }
private UserDetails user(User ftpUser) { String username = ftpUser.getName(); String password = ftpUser.getPassword(); boolean isEnabled = ftpUser.getEnabled(); GrantedAuthority[] authorities = new GrantedAuthority[0]; boolean accountNonExpired = true; boolean credentialsNonExpired = true; boolean accountNonLocked = true; UserDetails userDetails = new org.springframework.security.core.userdetails.User(username, password, isEnabled, accountNonExpired, credentialsNonExpired, accountNonLocked, Arrays.asList(authorities)); return userDetails; }
/** * Create and register a temporary file in the home directory of the given user. The created file is empty. * * @param user * The owner of the file * @return The name of temporary file created, relative to the user home directory. * @throws IOException * The temporary file can not be created */ public String registerTempFile(final User user) throws IOException { final File userHomeDirectory = new File(user.getHomeDirectory()); final File tempFile = File.createTempFile(user.getName(), ".tmp", userHomeDirectory); return userHomeDirectory.toURI().relativize(tempFile.toURI()).toString(); }
if (user.getName() == null) { throw new NullPointerException("User name is null."); map.put(ATTR_LOGIN, escapeString(user.getName())); if(user.getPassword() != null) { password= getPasswordEncryptor().encrypt(user.getPassword()); } else { User userWithPassword = selectUserByName(user.getName()); password = userWithPassword.getPassword(); String home = user.getHomeDirectory(); if (home == null) { home = "/"; map.put(ATTR_ENABLE, String.valueOf(user.getEnabled())); .authorize(new WriteRequest()) != null)); map.put(ATTR_MAX_IDLE_TIME, user.getMaxIdleTime()); .authorize(transferRateRequest); 0, 0); concurrentLoginRequest = (ConcurrentLoginRequest) user .authorize(concurrentLoginRequest);
@Override public String getOwnerName() { logger.trace("[{}] getOwnerName()", name); return user.getName(); }
/** * Get user password. Returns the encrypted value. * <p/> * <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 = passwordEncryptor.encrypt(password); } else { String blankPassword = passwordEncryptor.encrypt(""); if (doesExist(name)) { String key = PREFIX + name + '.' + ATTR_PASSWORD; password = userDataProp.getProperty(key, blankPassword); } else { password = blankPassword; } } return password; }
/** * Create and register a file with the given name in the home directory of the given user. The created file is * empty. * * @param user * The owner of the file * @param filename * The file name. * @return <code>true</code> if the file was successfully created, <code>false</code> otherwise. * @throws IOException * An error occurs creating the file */ public boolean registerFile(final User user, final String filename) throws IOException { final File userHomeDirectory = new File(user.getHomeDirectory()); return new File(userHomeDirectory, filename).createNewFile(); }
if (userName.equals(user.getName())) { session.write(LocalizedFtpReply.translate(session, request, context, FtpReply.REPLY_230_USER_LOGGED_IN, "USER", stat.getCurrentUserLoginNumber(configUser, address) + 1); if (configUser.authorize(loginRequest) == null) { LOG.debug("User logged in too many sessions, user will be disconnected"); session
if(!authenticatedUser.getEnabled()) { session .write(LocalizedFtpReply session.setMaxIdleTime(authenticatedUser.getMaxIdleTime()); success = true; } else {
@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"); } }
/** * 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; }
@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; }
boolean isAdmin = userManager.isAdmin(session.getUser().getName()); if (!isAdmin) { session.write(LocalizedFtpReply.translate(session, request, context, 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"); .authorize(transferRateRequest);
@Override public String getGroupName() { logger.trace("[{}] getGroupName()", name); return user.getName(); }
/** * Create and register a temporary file in the home directory of the given user. The created file is empty. The * created file will have the given extension. * * @param user * The owner of the file * @param extension * The extension of the file to create. The '.' delimiting the base name and the extension will be * automatically added. * @return The name of temporary file created, relative to the user home directory. * @throws IOException * The temporary file can not be created */ public String registerTempFile(final User user, final String extension) throws IOException { final File userHomeDirectory = new File(user.getHomeDirectory()); final File tempFile = File.createTempFile(user.getName(), "." + extension, userHomeDirectory); return userHomeDirectory.toURI().relativize(tempFile.toURI()).toString(); }
/** * Method duplicated from {@link PropertiesUserManager#getUserByName(String)} */ private String getPassword(final 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; }
/** * Constructor - set the user object. */ protected HdfsFileSystemView(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 = NativeFileObject.normalizeSeparateChar(rootDir); if (!rootDir.endsWith("/")) { rootDir += '/'; } this.rootDir = rootDir; this.user = user; }
/** * 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(); }
public void save(final User usr) throws FtpException { if (usr.getName() == null) { throw new NullPointerException("User name is null."); String thisPrefix = PREFIX + usr.getName() + '.'; String home = usr.getHomeDirectory(); if (home == null) { 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) usr.authorize(transferRateRequest); concurrentLoginRequest = (ConcurrentLoginRequest) usr.authorize(concurrentLoginRequest);
/** * Copy constructor. */ public HdfsUser(User user) { name = user.getName(); password = user.getPassword(); authorities = user.getAuthorities(); maxIdleTimeSec = user.getMaxIdleTime(); homeDir = user.getHomeDirectory(); isEnabled = user.getEnabled(); }