| 21 |
private LDAPSearch() { |
private LDAPSearch() { |
| 22 |
} |
} |
| 23 |
|
|
| 24 |
static private void init() { |
static synchronized private void init() { |
| 25 |
if ( !ApplicationProperties.getLdap() ) { |
if ( ApplicationProperties.getLdap() ) { |
| 26 |
//InitialDirContext |
//not initialized ctx or LDAP Provider URL was changed. |
| 27 |
lastProviderUrl = ApplicationProperties.getLdapProviderURL(); |
if ( ctx==null |
| 28 |
Properties env = new Properties(); |
|| (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) { |
| 29 |
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, |
try { |
| 30 |
"com.sun.jndi.ldap.LdapCtxFactory"); |
if ( ctx != null ) { ctx.close(); } |
| 31 |
env.put(Context.PROVIDER_URL, lastProviderUrl); |
//InitialDirContext |
| 32 |
|
lastProviderUrl = ApplicationProperties.getLdapProviderURL(); |
| 33 |
try { |
Properties env = new Properties(); |
| 34 |
ctx = new InitialDirContext(env); |
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, |
| 35 |
} catch (NamingException e) { |
"com.sun.jndi.ldap.LdapCtxFactory"); |
| 36 |
System.err.println("LDAPSearch init error."); |
env.put(Context.PROVIDER_URL, lastProviderUrl); |
| 37 |
e.printStackTrace(); |
|
| 38 |
|
ctx = new InitialDirContext(env); |
| 39 |
|
} catch (NamingException e) { |
| 40 |
|
System.err.println("LDAPSearch init error."); |
| 41 |
|
e.printStackTrace(); |
| 42 |
|
} |
| 43 |
} |
} |
| 44 |
} |
} |
| 45 |
} |
} |
| 50 |
if (!ApplicationProperties.getLdap()) { |
if (!ApplicationProperties.getLdap()) { |
| 51 |
return ans; |
return ans; |
| 52 |
} |
} |
| 53 |
synchronized (LDAPSearch.class ) { |
if ( ctx==null |
| 54 |
//not initialized ctx or LDAP Provider URL was changed. |
|| (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) { |
| 55 |
if ( ctx==null |
init(); |
|
|| (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) { |
|
|
init(); |
|
|
} |
|
| 56 |
} |
} |
| 57 |
|
|
| 58 |
Pattern pattern = Pattern.compile("[ \t]+"); //Attributes separate by space. |
Pattern pattern = Pattern.compile("[ \t]+"); //Attributes separate by space. |
| 97 |
} catch (NamingException e) { |
} catch (NamingException e) { |
| 98 |
System.err.println("LDAP Search Error."); |
System.err.println("LDAP Search Error."); |
| 99 |
e.printStackTrace(); |
e.printStackTrace(); |
| 100 |
|
//ctx reflesh |
| 101 |
|
try { |
| 102 |
|
ctx.close(); |
| 103 |
|
} catch (NamingException nEx) { |
| 104 |
|
//IGNORE Exception |
| 105 |
|
} |
| 106 |
|
ctx = null; |
| 107 |
} catch (UnsupportedEncodingException ueEx) { |
} catch (UnsupportedEncodingException ueEx) { |
| 108 |
UnsupportedEncodingException e = ueEx; |
UnsupportedEncodingException e = ueEx; |
| 109 |
System.err.println("LDAP SJIS Error."); |
System.err.println("LDAP SJIS Error."); |
| 110 |
e.printStackTrace(); |
e.printStackTrace(); |
| 111 |
} |
} catch (NullPointerException npEx) { //for failsafe. |
| 112 |
|
NullPointerException e = npEx; |
| 113 |
|
System.err.println("LDAP Unexpected Error."); |
| 114 |
|
e.printStackTrace(); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
return ans; |
return ans; |
| 118 |
} |
} |