| 6 |
import java.util.regex.Pattern; |
import java.util.regex.Pattern; |
| 7 |
|
|
| 8 |
import javax.naming.Context; |
import javax.naming.Context; |
| 9 |
|
import javax.naming.NameNotFoundException; |
| 10 |
import javax.naming.NamingEnumeration; |
import javax.naming.NamingEnumeration; |
| 11 |
import javax.naming.NamingException; |
import javax.naming.NamingException; |
| 12 |
|
import javax.naming.TimeLimitExceededException; |
| 13 |
import javax.naming.directory.Attribute; |
import javax.naming.directory.Attribute; |
| 14 |
import javax.naming.directory.InitialDirContext; |
import javax.naming.directory.InitialDirContext; |
| 15 |
import javax.naming.directory.SearchControls; |
import javax.naming.directory.SearchControls; |
| 29 |
if ( ctx==null |
if ( ctx==null |
| 30 |
|| (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) { |
|| (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) { |
| 31 |
try { |
try { |
| 32 |
if ( ctx != null ) { ctx.close(); } |
if ( ctx != null ) { close(); } |
| 33 |
//InitialDirContext |
System.out.println("init LDAP connection."); |
| 34 |
|
//InitialDirContext |
| 35 |
lastProviderUrl = ApplicationProperties.getLdapProviderURL(); |
lastProviderUrl = ApplicationProperties.getLdapProviderURL(); |
| 36 |
Properties env = new Properties(); |
Properties env = new Properties(); |
| 37 |
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, |
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, |
| 41 |
ctx = new InitialDirContext(env); |
ctx = new InitialDirContext(env); |
| 42 |
} catch (NamingException e) { |
} catch (NamingException e) { |
| 43 |
System.err.println("LDAPSearch init error."); |
System.err.println("LDAPSearch init error."); |
| 44 |
|
lastProviderUrl = null; |
| 45 |
e.printStackTrace(); |
e.printStackTrace(); |
| 46 |
} |
} |
| 47 |
} |
} |
| 48 |
} |
} |
| 49 |
} |
} |
| 50 |
|
|
| 51 |
|
/** |
| 52 |
|
* LDAP connection close. |
| 53 |
|
* <P>LDAP connection open is automatical.</P> |
| 54 |
|
* <P>If you hope aboid LDAP Server cconnection timeout close, you call close().</P> |
| 55 |
|
*/ |
| 56 |
|
public static synchronized void close() |
| 57 |
|
{ |
| 58 |
|
try |
| 59 |
|
{ |
| 60 |
|
if (ctx != null) |
| 61 |
|
{ |
| 62 |
|
System.out.println("close LDAP connection."); |
| 63 |
|
ctx.close(); |
| 64 |
|
ctx = null; |
| 65 |
|
} |
| 66 |
|
} |
| 67 |
|
catch (NamingException e) |
| 68 |
|
{ |
| 69 |
|
System.err.println("LDAPSearch init error."); |
| 70 |
|
e.printStackTrace(); |
| 71 |
|
} |
| 72 |
|
} |
| 73 |
|
|
| 74 |
public static String search(String mail) { |
public static String search(String mail) { |
| 75 |
String ans = ""; |
String ans = ""; |
| 76 |
|
|
| 78 |
return ans; |
return ans; |
| 79 |
} |
} |
| 80 |
if ( ctx==null |
if ( ctx==null |
| 81 |
|| (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) { |
|| ( (lastProviderUrl != null) |
| 82 |
|
&& (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) |
| 83 |
|
) |
| 84 |
|
) { |
| 85 |
init(); |
init(); |
| 86 |
} |
} |
| 87 |
|
|
| 124 |
System.err.println("ANS=" + ans); |
System.err.println("ANS=" + ans); |
| 125 |
} |
} |
| 126 |
enum.close(); |
enum.close(); |
| 127 |
|
} catch (TimeLimitExceededException tlEx) { |
| 128 |
|
System.out.println("LDAP Search Time Limit."); |
| 129 |
|
//IGNORE Exception |
| 130 |
|
} catch (NameNotFoundException nnfEx) { |
| 131 |
|
System.out.println("LDAP Search Name Not Found."); |
| 132 |
|
//IGNORE Exception |
| 133 |
} catch (NamingException e) { |
} catch (NamingException e) { |
| 134 |
System.err.println("LDAP Search Error."); |
System.err.println("LDAP Search Error."); |
| 135 |
e.printStackTrace(); |
e.printStackTrace(); |
| 136 |
//ctx reflesh |
//ctx reflesh |
| 137 |
try { |
close(); |
|
ctx.close(); |
|
|
} catch (NamingException nEx) { |
|
|
//IGNORE Exception |
|
|
} |
|
|
ctx = null; |
|
| 138 |
} catch (UnsupportedEncodingException ueEx) { |
} catch (UnsupportedEncodingException ueEx) { |
| 139 |
UnsupportedEncodingException e = ueEx; |
UnsupportedEncodingException e = ueEx; |
| 140 |
System.err.println("LDAP SJIS Error."); |
System.err.println("LDAP SJIS Error."); |