/** * 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; }
/** * @see Authority#authorize(AuthorizationRequest) */ public AuthorizationRequest authorize(final AuthorizationRequest request) { if (request instanceof WriteRequest) { WriteRequest writeRequest = (WriteRequest) request; String requestFile = writeRequest.getFile(); if (requestFile.startsWith(permissionRoot)) { return writeRequest; } else { return null; } } else { return null; } }
/** * 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(); }
"\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(
.authorize(new WriteRequest()) != null)); map.put(ATTR_MAX_IDLE_TIME, user.getMaxIdleTime());
userDataProp.setProperty(thisPrefix + ATTR_WRITE_PERM, usr.authorize(new WriteRequest()) != null); userDataProp.setProperty(thisPrefix + ATTR_MAX_IDLE_TIME, usr.getMaxIdleTime());
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());