001: /****************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one *
003: * or more contributor license agreements. See the NOTICE file *
004: * distributed with this work for additional information *
005: * regarding copyright ownership. The ASF licenses this file *
006: * to you under the Apache License, Version 2.0 (the *
007: * "License"); you may not use this file except in compliance *
008: * with the License. You may obtain a copy of the License at *
009: * *
010: * http://www.apache.org/licenses/LICENSE-2.0 *
011: * *
012: * Unless required by applicable law or agreed to in writing, *
013: * software distributed under the License is distributed on an *
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015: * KIND, either express or implied. See the License for the *
016: * specific language governing permissions and limitations *
017: * under the License. *
018: ****************************************************************/package org.apache.james.smtpserver;
019:
020: import org.apache.avalon.framework.configuration.Configuration;
021: import org.apache.avalon.framework.configuration.ConfigurationException;
022: import org.apache.avalon.framework.configuration.DefaultConfiguration;
023: import org.apache.james.test.util.Util;
024:
025: public class SMTPTestConfiguration extends DefaultConfiguration {
026:
027: private int m_smtpListenerPort;
028: private int m_maxMessageSizeKB = 0;
029: private String m_authorizedAddresses = "127.0.0.0/8";
030: private String m_authorizingMode = "false";
031: private boolean m_verifyIdentity = false;
032: private Integer m_connectionLimit = null;
033: private Integer m_connectionBacklog = null;
034: private boolean m_heloResolv = false;
035: private boolean m_ehloResolv = false;
036: private boolean m_senderDomainResolv = false;
037: private boolean m_checkAuthNetworks = false;
038: private boolean m_checkAuthClients = false;
039: private boolean m_heloEhloEnforcement = true;
040: private boolean m_reverseEqualsHelo = false;
041: private boolean m_reverseEqualsEhlo = false;
042: private int m_maxRcpt = 0;
043:
044: public SMTPTestConfiguration(int smtpListenerPort) {
045: super ("smptserver");
046:
047: m_smtpListenerPort = smtpListenerPort;
048: }
049:
050: public void setCheckAuthNetworks(boolean checkAuth) {
051: m_checkAuthNetworks = checkAuth;
052: }
053:
054: public void setMaxMessageSize(int kilobytes) {
055: m_maxMessageSizeKB = kilobytes;
056: }
057:
058: public int getMaxMessageSize() {
059: return m_maxMessageSizeKB;
060: }
061:
062: public String getAuthorizedAddresses() {
063: return m_authorizedAddresses;
064: }
065:
066: public void setAuthorizedAddresses(String authorizedAddresses) {
067: m_authorizedAddresses = authorizedAddresses;
068: }
069:
070: public void setAuthorizingNotRequired() {
071: m_authorizingMode = "false";
072: m_verifyIdentity = false;
073: }
074:
075: public void setAuthorizingRequired() {
076: m_authorizingMode = "true";
077: m_verifyIdentity = true;
078: }
079:
080: public void setAuthorizingAnnounce() {
081: m_authorizingMode = "announce";
082: m_verifyIdentity = true;
083: }
084:
085: public void setConnectionLimit(int iConnectionLimit) {
086: m_connectionLimit = new Integer(iConnectionLimit);
087: }
088:
089: public void setConnectionBacklog(int iConnectionBacklog) {
090: m_connectionBacklog = new Integer(iConnectionBacklog);
091: }
092:
093: public void setHeloResolv() {
094: m_heloResolv = true;
095: }
096:
097: public void setEhloResolv() {
098: m_ehloResolv = true;
099: }
100:
101: public void setReverseEqualsHelo() {
102: m_reverseEqualsHelo = true;
103: }
104:
105: public void setReverseEqualsEhlo() {
106: m_reverseEqualsEhlo = true;
107: }
108:
109: public void setSenderDomainResolv() {
110: m_senderDomainResolv = true;
111: }
112:
113: public void setCheckAuthClients(boolean ignore) {
114: m_checkAuthClients = ignore;
115: }
116:
117: public void setMaxRcpt(int maxRcpt) {
118: m_maxRcpt = maxRcpt;
119: }
120:
121: public void setHeloEhloEnforcement(boolean heloEhloEnforcement) {
122: m_heloEhloEnforcement = heloEhloEnforcement;
123: }
124:
125: public void init() throws ConfigurationException {
126:
127: setAttribute("enabled", true);
128:
129: addChild(Util.getValuedConfiguration("port", ""
130: + m_smtpListenerPort));
131: if (m_connectionLimit != null)
132: addChild(Util.getValuedConfiguration("connectionLimit", ""
133: + m_connectionLimit.intValue()));
134: if (m_connectionBacklog != null)
135: addChild(Util.getValuedConfiguration("connectionBacklog",
136: "" + m_connectionBacklog.intValue()));
137:
138: DefaultConfiguration handlerConfig = new DefaultConfiguration(
139: "handler");
140: handlerConfig.addChild(Util.getValuedConfiguration("helloName",
141: "myMailServer"));
142: handlerConfig.addChild(Util.getValuedConfiguration(
143: "connectiontimeout", "360000"));
144: handlerConfig.addChild(Util.getValuedConfiguration(
145: "authorizedAddresses", m_authorizedAddresses));
146: handlerConfig.addChild(Util.getValuedConfiguration(
147: "maxmessagesize", "" + m_maxMessageSizeKB));
148: handlerConfig.addChild(Util.getValuedConfiguration(
149: "authRequired", m_authorizingMode));
150: handlerConfig.addChild(Util.getValuedConfiguration(
151: "heloEhloEnforcement", m_heloEhloEnforcement + ""));
152: if (m_verifyIdentity)
153: handlerConfig.addChild(Util.getValuedConfiguration(
154: "verifyIdentity", "" + m_verifyIdentity));
155:
156: handlerConfig.addChild(Util
157: .createSMTPHandlerChainConfiguration());
158:
159: // Add Configuration for Helo checks and Ehlo checks
160: Configuration[] heloConfig = handlerConfig.getChild(
161: "handlerchain").getChildren("handler");
162: for (int i = 0; i < heloConfig.length; i++) {
163: if (heloConfig[i] instanceof DefaultConfiguration) {
164: String cmd = ((DefaultConfiguration) heloConfig[i])
165: .getAttribute("command", null);
166: if (cmd != null) {
167: if ("HELO".equals(cmd)) {
168: ((DefaultConfiguration) heloConfig[i])
169: .addChild(Util.getValuedConfiguration(
170: "checkResolvableHelo",
171: m_heloResolv + ""));
172: ((DefaultConfiguration) heloConfig[i])
173: .addChild(Util.getValuedConfiguration(
174: "checkReverseEqualsHelo",
175: m_reverseEqualsHelo + ""));
176: ((DefaultConfiguration) heloConfig[i])
177: .addChild(Util.getValuedConfiguration(
178: "checkAuthNetworks",
179: m_checkAuthNetworks + ""));
180: } else if ("EHLO".equals(cmd)) {
181: ((DefaultConfiguration) heloConfig[i])
182: .addChild(Util.getValuedConfiguration(
183: "checkResolvableEhlo",
184: m_ehloResolv + ""));
185: ((DefaultConfiguration) heloConfig[i])
186: .addChild(Util.getValuedConfiguration(
187: "checkReverseEqualsEhlo",
188: m_reverseEqualsEhlo + ""));
189: ((DefaultConfiguration) heloConfig[i])
190: .addChild(Util.getValuedConfiguration(
191: "checkAuthNetworks",
192: m_checkAuthNetworks + ""));
193: } else if ("MAIL".equals(cmd)) {
194: ((DefaultConfiguration) heloConfig[i])
195: .addChild(Util.getValuedConfiguration(
196: "checkValidSenderDomain",
197: m_senderDomainResolv + ""));
198: ((DefaultConfiguration) heloConfig[i])
199: .addChild(Util.getValuedConfiguration(
200: "checkAuthClients",
201: m_checkAuthClients + ""));
202: } else if ("RCPT".equals(cmd)) {
203: ((DefaultConfiguration) heloConfig[i])
204: .addChild(Util.getValuedConfiguration(
205: "maxRcpt", m_maxRcpt + ""));
206: }
207: }
208: }
209: }
210:
211: addChild(handlerConfig);
212: }
213:
214: }
|