本文整理匯總了Java中javax.naming.directory.InitialDirContext.close方法的典型用法代碼示例。如果您正苦於以下問題:Java InitialDirContext.close方法的具體用法?Java InitialDirContext.close怎麽用?Java InitialDirContext.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.naming.directory.InitialDirContext
的用法示例。
在下文中一共展示了InitialDirContext.close方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getUserForLoginName
import javax.naming.directory.InitialDirContext; //導入方法依賴的package包/類
public User getUserForLoginName(String login) {
try {
InitialDirContext ctx = createContext();
User user = new User();
SearchResult next = getLDAPInformation(ctx, login.toLowerCase()).nextElement();
user.setLogin(login.toLowerCase());
user.setSurname(next.getAttributes().get("sn").get().toString());
user.setForename(next.getAttributes().get("givenName").get().toString());
user.setEmail(next.getAttributes().get("mail").get().toString().toLowerCase());
ctx.close();
return user;
} catch (Exception e) {
log.info("Login " + login + " nicht gefunden!");
}
return null;
}
示例2: closeDirectoryContext
import javax.naming.directory.InitialDirContext; //導入方法依賴的package包/類
public static void closeDirectoryContext(InitialDirContext initialDirContext) {
try {
initialDirContext.close();
} catch (NamingException e) {
LOGGER.warn("Could not close InitialDirContext correctly!", e);
}
}
示例3: authenticateUser
import javax.naming.directory.InitialDirContext; //導入方法依賴的package包/類
public boolean authenticateUser(String username, String password) {
if (ldapAuth) {
String[] domainArr = ldapDomain.split(",");
for (String domain : domainArr) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapUrl);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, domain + "\\" + username);
env.put(Context.SECURITY_CREDENTIALS, password);
try {
ctx = new InitialDirContext(env);
return true;
} catch (NamingException e) {
} finally {
if (ctx != null) {
try {
ctx.close();
} catch (NamingException ex) {
LOGGER.warn(ex.getMessage());
}
}
}
}
return false;
} else {
//DB authentication
EcUser user = uDao.findByUsernameAndPassword(username, password);
if (user == null) {
return false;
} else {
return true;
}
}
}
示例4: authenticateUser
import javax.naming.directory.InitialDirContext; //導入方法依賴的package包/類
public boolean authenticateUser(String ldapUrl, String username, String password, String domains) {
String[] domainArr = domains.split(",");
for (String domain : domainArr) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapUrl);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, domain + "\\" + username);
env.put(Context.SECURITY_CREDENTIALS, password);
try {
ctx = new InitialDirContext(env);
return true;
} catch (NamingException e) {
} finally {
if (ctx != null) {
try {
ctx.close();
} catch (NamingException ex) {
logger.warn(ex.getMessage());
}
}
}
}
return false;
}
示例5: start
import javax.naming.directory.InitialDirContext; //導入方法依賴的package包/類
/**
* start the connector
*/
public void start() throws Exception {
LOG.info("connecting...");
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
this.ldapURI = getUri();
LOG.debug(" URI [{}]", this.ldapURI);
env.put(Context.PROVIDER_URL, this.ldapURI.toString());
if (anonymousAuthentication) {
LOG.debug(" login credentials [anonymous]");
env.put(Context.SECURITY_AUTHENTICATION, "none");
} else {
LOG.debug(" login credentials [{}:******]", user);
env.put(Context.SECURITY_PRINCIPAL, user);
env.put(Context.SECURITY_CREDENTIALS, password);
}
boolean isConnected = false;
while (!isConnected) {
try {
context = new InitialDirContext(env);
isConnected = true;
} catch (CommunicationException err) {
if (failover) {
this.ldapURI = getUri();
LOG.error("connection error [{}], failover connection to [{}]", env.get(Context.PROVIDER_URL), this.ldapURI.toString());
env.put(Context.PROVIDER_URL, this.ldapURI.toString());
Thread.sleep(curReconnectDelay);
curReconnectDelay = Math.min(curReconnectDelay * 2, maxReconnectDelay);
} else {
throw err;
}
}
}
// add connectors from search results
LOG.info("searching for network connectors...");
LOG.debug(" base [{}]", base);
LOG.debug(" filter [{}]", searchFilter);
LOG.debug(" scope [{}]", searchControls.getSearchScope());
NamingEnumeration<SearchResult> results = context.search(base, searchFilter, searchControls);
while (results.hasMore()) {
addConnector(results.next());
}
// register persistent search event listener
if (searchEventListener) {
LOG.info("registering persistent search listener...");
EventDirContext eventContext = (EventDirContext) context.lookup("");
eventContext.addNamingListener(base, searchFilter, searchControls, this);
} else { // otherwise close context (i.e. connection as it is no longer needed)
context.close();
}
}