/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.ftpserver.impl;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.security.cert.Certificate;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import org.apache.ftpserver.ftplet.DataType;
import org.apache.ftpserver.ftplet.FileSystemView;
import org.apache.ftpserver.ftplet.FtpFile;
import org.apache.ftpserver.ftplet.FtpReply;
import org.apache.ftpserver.ftplet.FtpSession;
import org.apache.ftpserver.ftplet.Structure;
import org.apache.ftpserver.ftplet.User;
import org.apache.ftpserver.listener.Listener;
import org.apache.mina.core.filterchain.IoFilterChain;
import org.apache.mina.core.future.CloseFuture;
import org.apache.mina.core.future.ReadFuture;
import org.apache.mina.core.future.WriteFuture;
import org.apache.mina.core.service.IoHandler;
import org.apache.mina.core.service.IoService;
import org.apache.mina.core.service.TransportMetadata;
import org.apache.mina.core.session.AbstractIoSession;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.core.session.IoSessionConfig;
import org.apache.mina.core.write.WriteRequest;
import org.apache.mina.core.write.WriteRequestQueue;
import org.apache.mina.filter.ssl.SslFilter;
/**
* <strong>Internal class, do not use directly.</strong>
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
*
*/
public class FtpIoSession implements IoSession {
/**
* Contains user name between USER and PASS commands
*/
public static final String ATTRIBUTE_PREFIX = "org.apache.ftpserver.";
private static final String ATTRIBUTE_USER_ARGUMENT = ATTRIBUTE_PREFIX
+ "user-argument";
private static final String ATTRIBUTE_SESSION_ID = ATTRIBUTE_PREFIX
+ "session-id";
private static final String ATTRIBUTE_USER = ATTRIBUTE_PREFIX + "user";
private static final String ATTRIBUTE_LANGUAGE = ATTRIBUTE_PREFIX
+ "language";
private static final String ATTRIBUTE_LOGIN_TIME = ATTRIBUTE_PREFIX
+ "login-time";
private static final String ATTRIBUTE_DATA_CONNECTION = ATTRIBUTE_PREFIX
+ "data-connection";
private static final String ATTRIBUTE_FILE_SYSTEM = ATTRIBUTE_PREFIX
+ "file-system";
private static final String ATTRIBUTE_RENAME_FROM = ATTRIBUTE_PREFIX
+ "rename-from";
private static final String ATTRIBUTE_FILE_OFFSET = ATTRIBUTE_PREFIX
+ "file-offset";
private static final String ATTRIBUTE_DATA_TYPE = ATTRIBUTE_PREFIX
+ "data-type";
private static final String ATTRIBUTE_STRUCTURE = ATTRIBUTE_PREFIX
+ "structure";
private static final String ATTRIBUTE_FAILED_LOGINS = ATTRIBUTE_PREFIX
+ "failed-logins";
private static final String ATTRIBUTE_LISTENER = ATTRIBUTE_PREFIX
+ "listener";
private static final String ATTRIBUTE_MAX_IDLE_TIME = ATTRIBUTE_PREFIX
+ "max-idle-time";
private static final String ATTRIBUTE_LAST_ACCESS_TIME = ATTRIBUTE_PREFIX
+ "last-access-time";
private static final String ATTRIBUTE_CACHED_REMOTE_ADDRESS = ATTRIBUTE_PREFIX
+ "cached-remote-address";
private IoSession wrappedSession;
private FtpServerContext context;
/**
* Last reply that was sent to the client, if any.
*/
private FtpReply lastReply = null;
/* Begin wrapped IoSession methods */
/**
* @see IoSession#close()
*/
public CloseFuture close() {
return wrappedSession.close();
}
/**
* @see IoSession#close(boolean)
*/
public CloseFuture close(boolean immediately) {
return wrappedSession.close(immediately);
}
/**
* @see IoSession#containsAttribute(Object)
*/
public boolean containsAttribute(Object key) {
return wrappedSession.containsAttribute(key);
}
/**
* @see IoSession#getAttachment()
*/
@SuppressWarnings("deprecation")
public Object getAttachment() {
return wrappedSession.getAttachment();
}
/**
* @see IoSession#getAttribute(Object)
*/
public Object getAttribute(Object key) {
return wrappedSession.getAttribute(key);
}
/**
* @see IoSession#getAttribute(Object, Object)
*/
public Object getAttribute(Object key, Object defaultValue) {
return wrappedSession.getAttribute(key, defaultValue);
}
/**
* @see IoSession#getAttributeKeys()
*/
public Set<Object> getAttributeKeys() {
return wrappedSession.getAttributeKeys();
}
/**
* @see IoSession#getBothIdleCount()
*/
public int getBothIdleCount() {
return wrappedSession.getBothIdleCount();
}
/**
* @see IoSession#getCloseFuture()
*/
public CloseFuture getCloseFuture() {
return wrappedSession.getCloseFuture();
}
/**
* @see IoSession#getConfig()
*/
public IoSessionConfig getConfig() {
return wrappedSession.getConfig();
}
/**
* @see IoSession#getCreationTime()
*/
public long getCreationTime() {
return wrappedSession.getCreationTime();
}
/**
* @see IoSession#getFilterChain()
*/
public IoFilterChain getFilterChain() {
return wrappedSession.getFilterChain();
}
/**
* @see IoSession#getHandler()
*/
public IoHandler getHandler() {
return wrappedSession.getHandler();
}
/**
* @see IoSession#getId()
*/
public long getId() {
return wrappedSession.getId();
}
/**
* @see IoSession#getIdleCount(IdleStatus)
*/
public int getIdleCount(IdleStatus status) {
return wrappedSession.getIdleCount(status);
}
/**
* @see IoSession#getLastBothIdleTime()
*/
public long getLastBothIdleTime() {
return wrappedSession.getLastBothIdleTime();
}
/**
* @see IoSession#getLastIdleTime(IdleStatus)
*/
public long getLastIdleTime(IdleStatus status) {
return wrappedSession.getLastIdleTime(status);
}
/**
* @see IoSession#getLastIoTime()
*/
public long getLastIoTime() {
return wrappedSession.getLastIoTime();
}
/**
* @see IoSession#getLastReadTime()
*/
public long getLastReadTime() {
return wrappedSession.getLastReadTime();
}
/**
* @see IoSession#getLastReaderIdleTime()
*/
public long getLastReaderIdleTime() {
return wrappedSession.getLastReaderIdleTime();
}
/**
* @see IoSession#getLastWriteTime()
*/
public long getLastWriteTime() {
return wrappedSession.getLastWriteTime();
}
/**
* @see IoSession#getLastWriterIdleTime()
*/
public long getLastWriterIdleTime() {
return wrappedSession.getLastWriterIdleTime();
}
/**
* @see IoSession#getLocalAddress()
*/
public SocketAddress getLocalAddress() {
return wrappedSession.getLocalAddress();