<commit_before>/*
 * 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;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.ftpserver.filesystem.NativeFileSystemManager;
import org.apache.ftpserver.ftplet.Authority;
import org.apache.ftpserver.ftplet.Component;
import org.apache.ftpserver.ftplet.DefaultFtpletContainer;
import org.apache.ftpserver.ftplet.EmptyConfiguration;
import org.apache.ftpserver.ftplet.FileSystemManager;
import org.apache.ftpserver.ftplet.FtpStatistics;
import org.apache.ftpserver.ftplet.Ftplet;
import org.apache.ftpserver.ftplet.FtpletContainer;
import org.apache.ftpserver.ftplet.UserManager;
import org.apache.ftpserver.interfaces.CommandFactory;
import org.apache.ftpserver.interfaces.FtpServerContext;
import org.apache.ftpserver.interfaces.IpRestrictor;
import org.apache.ftpserver.interfaces.MessageResource;
import org.apache.ftpserver.iprestrictor.FileIpRestrictor;
import org.apache.ftpserver.listener.Listener;
import org.apache.ftpserver.listener.mina.MinaListener;
import org.apache.ftpserver.message.MessageResourceImpl;
import org.apache.ftpserver.usermanager.BaseUser;
import org.apache.ftpserver.usermanager.ConcurrentLoginPermission;
import org.apache.ftpserver.usermanager.PropertiesUserManager;
import org.apache.ftpserver.usermanager.TransferRatePermission;
import org.apache.ftpserver.usermanager.WritePermission;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * FTP server configuration implementation. It holds all the components used.
 */
public class DefaultFtpServerContext implements FtpServerContext {

	private final Logger LOG = LoggerFactory
			.getLogger(DefaultFtpServerContext.class);

	private MessageResource messageResource;
	private IpRestrictor ipRestrictor;
	private UserManager userManager;
	private FileSystemManager fileSystemManager;
	private FtpletContainer ftpletContainer;
	private FtpStatistics statistics;
	private CommandFactory commandFactory;
	private ConnectionConfig connectionConfig = new DefaultConnectionConfig();

	private Map<String, Listener> listeners = new HashMap<String, Listener>();

	private static final Authority[] ADMIN_AUTHORITIES = new Authority[] { new WritePermission() };

	private static final Authority[] ANON_AUTHORITIES = new Authority[] {
			new ConcurrentLoginPermission(20, 2),
			new TransferRatePermission(4800, 4800) };

	/**
	 * Constructor - set the root configuration.
	 */
	public DefaultFtpServerContext() throws Exception {
		this(true);
	}

	public DefaultFtpServerContext(boolean createDefaultUsers) throws Exception {

		try {
			createListeners();

			// create all the components
			messageResource = new MessageResourceImpl();
			((MessageResourceImpl) messageResource)
					.configure();

			ipRestrictor = new FileIpRestrictor();
			((FileIpRestrictor) ipRestrictor)
					.configure(EmptyConfiguration.INSTANCE);

			userManager = new PropertiesUserManager();
			((PropertiesUserManager) userManager).configure();

			fileSystemManager = new NativeFileSystemManager();

			statistics = new FtpStatisticsImpl();

			commandFactory = new DefaultCommandFactory();

			// create user if necessary
			// TODO turn into a setter
			if (createDefaultUsers) {
				createDefaultUsers();<commit_msg>Cleaning up FtpStatisticsImpl and FileIpRestrictor<commit_after>/*
 * 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;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.ftpserver.filesystem.NativeFileSystemManager;
import org.apache.ftpserver.ftplet.Authority;
import org.apache.ftpserver.ftplet.Component;
import org.apache.ftpserver.ftplet.DefaultFtpletContainer;
import org.apache.ftpserver.ftplet.FileSystemManager;
import org.apache.ftpserver.ftplet.FtpStatistics;
import org.apache.ftpserver.ftplet.Ftplet;
import org.apache.ftpserver.ftplet.FtpletContainer;
import org.apache.ftpserver.ftplet.UserManager;
import org.apache.ftpserver.interfaces.CommandFactory;
import org.apache.ftpserver.interfaces.FtpServerContext;
import org.apache.ftpserver.interfaces.IpRestrictor;
import org.apache.ftpserver.interfaces.MessageResource;
import org.apache.ftpserver.iprestrictor.FileIpRestrictor;
import org.apache.ftpserver.listener.Listener;
import org.apache.ftpserver.listener.mina.MinaListener;
import org.apache.ftpserver.message.MessageResourceImpl;
import org.apache.ftpserver.usermanager.BaseUser;
import org.apache.ftpserver.usermanager.ConcurrentLoginPermission;
import org.apache.ftpserver.usermanager.PropertiesUserManager;
import org.apache.ftpserver.usermanager.TransferRatePermission;
import org.apache.ftpserver.usermanager.WritePermission;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * FTP server configuration implementation. It holds all the components used.
 */
public class DefaultFtpServerContext implements FtpServerContext {

	private final Logger LOG = LoggerFactory
			.getLogger(DefaultFtpServerContext.class);

	private MessageResource messageResource;
	private IpRestrictor ipRestrictor;
	private UserManager userManager;
	private FileSystemManager fileSystemManager;
	private FtpletContainer ftpletContainer;
	private FtpStatistics statistics;
	private CommandFactory commandFactory;
	private ConnectionConfig connectionConfig = new DefaultConnectionConfig();

	private Map<String, Listener> listeners = new HashMap<String, Listener>();

	private static final Authority[] ADMIN_AUTHORITIES = new Authority[] { new WritePermission() };

	private static final Authority[] ANON_AUTHORITIES = new Authority[] {
			new ConcurrentLoginPermission(20, 2),
			new TransferRatePermission(4800, 4800) };

	/**
	 * Constructor - set the root configuration.
	 */
	public DefaultFtpServerContext() throws Exception {
		this(true);
	}

	public DefaultFtpServerContext(boolean createDefaultUsers) throws Exception {

		try {
			createListeners();

			// create all the components
			messageResource = new MessageResourceImpl();
			((MessageResourceImpl) messageResource)
					.configure();

			ipRestrictor = new FileIpRestrictor();

			userManager = new PropertiesUserManager();
			((PropertiesUserManager) userManager).configure();

			fileSystemManager = new NativeFileSystemManager();

			statistics = new FtpStatisticsImpl();

			commandFactory = new DefaultCommandFactory();

			// create user if necessary
			// TODO turn into a setter
			if (createDefaultUsers) {
				createDefaultUsers();
{'fraction_non_alphanumeric': 0.0805552113025158, 'fraction_numerical': 0.004213657206593134, 'mean_word_length': 5.476725521669342, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6615309', 'n_tokens_mistral': 2313, 'n_tokens_neox': 2177, 'n_words': 614}