本文整理汇总了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();
}
}