Takuya Ono
takuy****@users*****
2005年 2月 23日 (水) 22:27:17 JST
Index: BetaProject/src/org/jent/checksmtp/ApplicationProperties.java diff -u BetaProject/src/org/jent/checksmtp/ApplicationProperties.java:1.1.1.1 BetaProject/src/org/jent/checksmtp/ApplicationProperties.java:1.2 --- BetaProject/src/org/jent/checksmtp/ApplicationProperties.java:1.1.1.1 Mon Feb 21 08:44:04 2005 +++ BetaProject/src/org/jent/checksmtp/ApplicationProperties.java Wed Feb 23 22:27:17 2005 @@ -15,11 +15,12 @@ * <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> @@ -27,12 +28,13 @@ 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"; @@ -109,6 +111,17 @@ { 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() { Index: BetaProject/src/org/jent/checksmtp/LDAPSearch.java diff -u BetaProject/src/org/jent/checksmtp/LDAPSearch.java:1.2 BetaProject/src/org/jent/checksmtp/LDAPSearch.java:1.3 --- BetaProject/src/org/jent/checksmtp/LDAPSearch.java:1.2 Tue Feb 22 01:11:06 2005 +++ BetaProject/src/org/jent/checksmtp/LDAPSearch.java Wed Feb 23 22:27:17 2005 @@ -6,8 +6,10 @@ 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; @@ -27,8 +29,9 @@ 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, @@ -38,12 +41,36 @@ 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 = ""; @@ -51,7 +78,10 @@ return ans; } if ( ctx==null - || (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) { + || ( (lastProviderUrl != null) + && (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) + ) + ) { init(); } @@ -94,16 +124,17 @@ 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."); Index: BetaProject/src/org/jent/checksmtp/Processer.java diff -u BetaProject/src/org/jent/checksmtp/Processer.java:1.2 BetaProject/src/org/jent/checksmtp/Processer.java:1.3 --- BetaProject/src/org/jent/checksmtp/Processer.java:1.2 Tue Feb 22 01:11:06 2005 +++ BetaProject/src/org/jent/checksmtp/Processer.java Wed Feb 23 22:27:17 2005 @@ -116,6 +116,8 @@ //IGNORE close Exception } } + //LDAP Connection close. + LDAPSearch.close(); } } Index: BetaProject/src/org/jent/checksmtp/SMTPclient.java diff -u BetaProject/src/org/jent/checksmtp/SMTPclient.java:1.1.1.1 BetaProject/src/org/jent/checksmtp/SMTPclient.java:1.2 --- BetaProject/src/org/jent/checksmtp/SMTPclient.java:1.1.1.1 Mon Feb 21 08:44:03 2005 +++ BetaProject/src/org/jent/checksmtp/SMTPclient.java Wed Feb 23 22:27:17 2005 @@ -23,9 +23,14 @@ 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!! }