MOD: Change properties name "org.jent.checksmtp.ldap.root" to "org.jent.checksmtp.ldap.baseDn".
ADD: Add properties "org.jent.checksmtp.enableRemoteConnect". It control permit connect from remote host.
ADD: Catch LDAP Time Limit and Not Found Exception
* <H3>Properties</H3>
* <DL>
* <DT> -.port <DD>Service port number. (Default:8725)
+ * <DT> -.enableRemoteConnect <DD>Permit connect from remote host. (Default:false)
* <DT> -.serverHost <DD>STMP Server host name. (Default:mail)
* <DT> -.serverPort <DD>STMP Server port. (Default:25)
* <DT> -.ladp <DD>If "true" use LDAP search. (Default:false)
* <DT> -.ldap.providerUrl <DD>LDAP Provider URL (Default:ldap://localhost:389
- * <DT> -.ldap.root <DD>LDAP Search root (Default:C=JP)
+ * <DT> -.ldap.baseDn <DD>LDAP Search root (Default:C=JP)
* <DT> -.ldap.isSjis<DD>Addhoc patch: When LDAP Server use SJIS, this propertiy set "true" (Default:false)
* <DT> -.ldap.attribues<DD>LDAP Search attribues separate by space (Defaut:cn)
* </DL>
public class ApplicationProperties
{
private static final String PREFIX = "org.jent.checksmtp";
+ private static final String SMTP_PORT = PREFIX + ".port";
+ private static final String SMTP_ENEBLE_REMOTE_CONNECT = PREFIX + ".enableRemoteConnect";
private static final String SMTP_SERVER_HOST = PREFIX + ".serverHost";
private static final String SMTP_SERVER_PORT = PREFIX + ".serverPort";
- private static final String SMTP_PORT = PREFIX + ".port";
private static final String LDAP_PREFIX = PREFIX + ".ldap";
private static final String LDAP_PROVIDER_URL = LDAP_PREFIX + ".providerUrl";
- private static final String LDAP_ROOT = LDAP_PREFIX + ".root";
+ private static final String LDAP_ROOT = LDAP_PREFIX + ".baseDn";
private static final String LDAP_IS_SJIS = LDAP_PREFIX + ".isSjis";
private static final String LDAP_IS_ATTRIBUTES = LDAP_PREFIX + ".attributes";
{
applicationProperties.setProperty(SMTP_PORT, new Integer(port).toString());
}
+
+ public static boolean getSmtpEnebleRemoteConnect()
+ {
+ String str = applicationProperties.getProperty(SMTP_ENEBLE_REMOTE_CONNECT);
+ return new Boolean(str).booleanValue();
+ }
+
+ public static void setSmtpEnableRemoteConnect(boolean obj)
+ {
+ applicationProperties.setProperty(SMTP_ENEBLE_REMOTE_CONNECT, Boolean.toString(obj));
+ }
public static String getLdapProviderURL()
{
import java.util.regex.Pattern;
import javax.naming.Context;
+import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
+import javax.naming.TimeLimitExceededException;
import javax.naming.directory.Attribute;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
if ( ctx==null
|| (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) {
try {
- if ( ctx != null ) { ctx.close(); }
- //InitialDirContext
+ if ( ctx != null ) { close(); }
+ System.out.println("init LDAP connection.");
+ //InitialDirContext
lastProviderUrl = ApplicationProperties.getLdapProviderURL();
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
ctx = new InitialDirContext(env);
} catch (NamingException e) {
System.err.println("LDAPSearch init error.");
+ lastProviderUrl = null;
e.printStackTrace();
}
}
}
}
+ /**
+ * LDAP connection close.
+ * <P>LDAP connection open is automatical.</P>
+ * <P>If you hope aboid LDAP Server cconnection timeout close, you call close().</P>
+ */
+ public static synchronized void close()
+ {
+ try
+ {
+ if (ctx != null)
+ {
+ System.out.println("close LDAP connection.");
+ ctx.close();
+ ctx = null;
+ }
+ }
+ catch (NamingException e)
+ {
+ System.err.println("LDAPSearch init error.");
+ e.printStackTrace();
+ }
+ }
+
public static String search(String mail) {
String ans = "";
return ans;
}
if ( ctx==null
- || (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) {
+ || ( (lastProviderUrl != null)
+ && (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL()))
+ )
+ ) {
init();
}
System.err.println("ANS=" + ans);
}
enum.close();
+ } catch (TimeLimitExceededException tlEx) {
+ System.out.println("LDAP Search Time Limit.");
+ //IGNORE Exception
+ } catch (NameNotFoundException nnfEx) {
+ System.out.println("LDAP Search Name Not Found.");
+ //IGNORE Exception
} catch (NamingException e) {
System.err.println("LDAP Search Error.");
e.printStackTrace();
//ctx reflesh
- try {
- ctx.close();
- } catch (NamingException nEx) {
- //IGNORE Exception
- }
- ctx = null;
+ close();
} catch (UnsupportedEncodingException ueEx) {
UnsupportedEncodingException e = ueEx;
System.err.println("LDAP SJIS Error.");
//IGNORE close Exception
}
}
+ //LDAP Connection close.
+ LDAPSearch.close();
}
}
System.err.println("Open SMTP waiting port. " + serverport);
try {
+ if ( ApplicationProperties.getSmtpEnebleRemoteConnect() ) {
+ System.out.println("Enable remote connection.");
+ server = new ServerSocket(serverport, 10);
+ } else {
server = new ServerSocket(serverport, 10,
InetAddress.getByAddress(
new byte[] { 127, 0, 0, 1 }));
+ }
} catch (IOException e) {
e.printStackTrace(); //Unexpected!!
}