1 /*****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
9 * *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, *
13 * software distributed under the License is distributed on an *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 * KIND, either express or implied. See the License for the *
16 * specific language governing permissions and limitations *
17 * under the License. *
18 ****************************************************************/
19
20
21 package org.apache.james.smtpserver;
22
23 import org.apache.avalon.framework.configuration.Configuration;
24 import org.apache.avalon.framework.configuration.ConfigurationException;
25 import org.apache.avalon.framework.configuration.DefaultConfiguration;
26 import org.apache.james.test.util.Util;
27
28 public class SMTPTestConfiguration extends DefaultConfiguration {
29
30 private int m_smtpListenerPort;
31 private int m_maxMessageSizeKB = 0;
32 private String m_authorizedAddresses = "127.0.0.0/8";
33 private String m_authorizingMode = "false";
34 private boolean m_verifyIdentity = false;
35 private Integer m_connectionLimit = null;
36 private Integer m_connectionBacklog = null;
37 private boolean m_heloResolv = false;
38 private boolean m_ehloResolv = false;
39 private boolean m_senderDomainResolv = false;
40 private boolean m_checkAuthNetworks = false;
41 private boolean m_checkAuthClients = false;
42 private boolean m_heloEhloEnforcement = true;
43 private boolean m_reverseEqualsHelo = false;
44 private boolean m_reverseEqualsEhlo = false;
45 private int m_maxRcpt = 0;
46
47
48 public SMTPTestConfiguration(int smtpListenerPort) {
49 super("smptserver");
50
51 m_smtpListenerPort = smtpListenerPort;
52 }
53
54 public void setCheckAuthNetworks(boolean checkAuth) {
55 m_checkAuthNetworks = checkAuth;
56 }
57
58
59 public void setMaxMessageSize(int kilobytes)
60 {
61 m_maxMessageSizeKB = kilobytes;
62 }
63
64 public int getMaxMessageSize() {
65 return m_maxMessageSizeKB;
66 }
67
68 public String getAuthorizedAddresses() {
69 return m_authorizedAddresses;
70 }
71
72 public void setAuthorizedAddresses(String authorizedAddresses) {
73 m_authorizedAddresses = authorizedAddresses;
74 }
75
76 public void setAuthorizingNotRequired() {
77 m_authorizingMode = "false";
78 m_verifyIdentity = false;
79 }
80
81 public void setAuthorizingRequired() {
82 m_authorizingMode = "true";
83 m_verifyIdentity = true;
84 }
85
86 public void setAuthorizingAnnounce() {
87 m_authorizingMode = "announce";
88 m_verifyIdentity = true;
89 }
90
91 public void setConnectionLimit(int iConnectionLimit) {
92 m_connectionLimit = new Integer(iConnectionLimit);
93 }
94
95 public void setConnectionBacklog(int iConnectionBacklog) {
96 m_connectionBacklog = new Integer(iConnectionBacklog);
97 }
98
99 public void setHeloResolv() {
100 m_heloResolv = true;
101 }
102
103 public void setEhloResolv() {
104 m_ehloResolv = true;
105 }
106
107 public void setReverseEqualsHelo() {
108 m_reverseEqualsHelo = true;
109 }
110
111 public void setReverseEqualsEhlo() {
112 m_reverseEqualsEhlo = true;
113 }
114
115 public void setSenderDomainResolv() {
116 m_senderDomainResolv = true;
117 }
118
119 public void setCheckAuthClients(boolean ignore) {
120 m_checkAuthClients = ignore;
121 }
122
123 public void setMaxRcpt(int maxRcpt) {
124 m_maxRcpt = maxRcpt;
125 }
126
127 public void setHeloEhloEnforcement(boolean heloEhloEnforcement) {
128 m_heloEhloEnforcement = heloEhloEnforcement;
129 }
130
131 public void init() throws ConfigurationException {
132
133 setAttribute("enabled", true);
134
135 addChild(Util.getValuedConfiguration("port", "" + m_smtpListenerPort));
136 if (m_connectionLimit != null) addChild(Util.getValuedConfiguration("connectionLimit", "" + m_connectionLimit.intValue()));
137 if (m_connectionBacklog != null) addChild(Util.getValuedConfiguration("connectionBacklog", "" + m_connectionBacklog.intValue()));
138
139 DefaultConfiguration handlerConfig = new DefaultConfiguration("handler");
140 handlerConfig.addChild(Util.getValuedConfiguration("helloName", "myMailServer"));
141 handlerConfig.addChild(Util.getValuedConfiguration("connectiontimeout", "360000"));
142 handlerConfig.addChild(Util.getValuedConfiguration("authorizedAddresses", m_authorizedAddresses));
143 handlerConfig.addChild(Util.getValuedConfiguration("maxmessagesize", "" + m_maxMessageSizeKB));
144 handlerConfig.addChild(Util.getValuedConfiguration("authRequired", m_authorizingMode));
145 handlerConfig.addChild(Util.getValuedConfiguration("heloEhloEnforcement", m_heloEhloEnforcement+""));
146 if (m_verifyIdentity) handlerConfig.addChild(Util.getValuedConfiguration("verifyIdentity", "" + m_verifyIdentity));
147
148 handlerConfig.addChild(Util.createSMTPHandlerChainConfiguration());
149
150
151 Configuration[] heloConfig = handlerConfig.getChild("handlerchain").getChildren("handler");
152 for (int i = 0; i < heloConfig.length; i++) {
153 if (heloConfig[i] instanceof DefaultConfiguration) {
154 String cmd = ((DefaultConfiguration) heloConfig[i]).getAttribute("command",null);
155 if (cmd != null) {
156 if ("HELO".equals(cmd)) {
157 ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkResolvableHelo",m_heloResolv+""));
158 ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkReverseEqualsHelo",m_reverseEqualsHelo+""));
159 ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkAuthNetworks",m_checkAuthNetworks+""));
160 } else if ("EHLO".equals(cmd)) {
161 ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkResolvableEhlo",m_ehloResolv+""));
162 ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkReverseEqualsEhlo",m_reverseEqualsEhlo+""));
163 ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkAuthNetworks",m_checkAuthNetworks+""));
164 } else if ("MAIL".equals(cmd)) {
165 ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkValidSenderDomain",m_senderDomainResolv+""));
166 ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkAuthClients",m_checkAuthClients+""));
167 } else if ("RCPT".equals(cmd)) {
168 ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("maxRcpt",m_maxRcpt+""));
169 }
170 }
171 }
172 }
173
174 addChild(handlerConfig);
175 }
176
177 }