`
- 浏览:
26768 次
- 性别:
- 来自:
广州
-
- package com.common.ldapconnection;
-
-
import java.util.List;
-
import java.util.Vector;
-
-
-
-
-
-
-
-
public class LdapOperUtils {
-
-
-
private static Logger log = Logger.getLogger(LdapOperUtils.class.getName());
-
-
-
-
-
-
-
-
private static DirContext getLdapDirContext(Env env) throws BaseException {
-
-
if (env == null) {
- String[] args = {
-
"env"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter env NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
-
- }
-
-
DirContext dirContext = null;
-
- dirContext = LdapConnectionFactory.getDirContext(env);
-
return dirContext;
- }
-
-
-
-
-
-
-
-
private static DirContext getLdapDirContext(String dirContextName,Env env)
-
throws BaseException {
-
-
if (StringUtils.isEmpty(dirContextName)) {
- String[] args = {
-
"dirContextName"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter dirContextName NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
-
- }
-
-
DirContext dirContext = null;
-
- dirContext = LdapConnectionFactory.getDirContext(dirContextName,env);
-
-
return dirContext;
-
- }
-
-
-
-
-
-
-
public static void closeEnvLdapDirContext(DirContext dirContext)
-
throws BaseException {
-
- closeLdapDirContext(dirContext);
- }
-
-
-
-
-
-
-
private static void closeLdapDirContext(DirContext dirContext) throws
- BaseException {
-
-
if (dirContext == null) {
- String[] args = {
-
"dirContext"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter conn NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
try {
-
- dirContext.close();
-
} catch (NamingException ex) {
-
-
if (log.isDebugEnabled()) {
-
log.debug("Not close DirContext " + ex);
- }
-
-
log.error("Not close DirContext " + ex);
- ex.printStackTrace();
-
try {
-
- dirContext.close();
-
} catch (NamingException ex1) {
-
-
if (log.isDebugEnabled()) {
-
log.debug("Not again close DirContext " + ex);
- }
-
-
log.error("Not again close DirContext " + ex);
- ex.printStackTrace();
-
-
throw new BaseException("error.common.dao.ldap.closedircontext", null);
- }
- }
- }
-
-
-
-
-
-
private LdapOperUtils() {
- }
-
-
-
-
-
-
-
-
-
-
-
public static void addContext(DirContext context, String cn, Map attMap) throws
- NamingException, BaseException {
-
-
-
if (context == null) {
- String[] args = {
-
"context"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter context NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
-
if (StringUtils.isEmpty(cn)) {
- String[] args = {
-
"cn"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter cn NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
-
if (attMap == null) {
- String[] args = {
-
"attMap"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter attMap NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
-
if (attMap.isEmpty()) {
-
return;
- }
-
-
- Set keySet = attMap.keySet();
- Iterator keyIterator = keySet.iterator();
-
Attributes attrs = new BasicAttributes();
-
-
while (keyIterator.hasNext()) {
-
-
- String key = (String) keyIterator.next();
-
Attribute att = null;
- Object valueObj = attMap.get(key);
-
-
if (valueObj instanceof String) {
-
-
att = new BasicAttribute(key, valueObj);
-
} else if (valueObj instanceof List) {
-
-
att = new BasicAttribute(key);
- List valueList = (List) valueObj;
-
-
for (int i = 0; i < valueList.size(); i++) {
- att.add(valueList.get(i));
- }
-
} else {
-
-
att = new BasicAttribute(key,valueObj);
- }
-
- attrs.put(att);
- }
-
- context.createSubcontext(cn, attrs);
-
- }
-
-
-
-
-
-
-
-
-
public static void deleteContext(DirContext context, String cn) throws
- NamingException, BaseException {
-
-
-
if (context == null) {
- String[] args = {
-
"context"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter context NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
-
if (StringUtils.isEmpty(cn)) {
- String[] args = {
-
"cn"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter cn NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
- context.destroySubcontext(cn);
-
-
- }
-
-
-
-
-
-
-
-
-
-
public static void reNameContext(DirContext context, String cn,
-
String newCn) throws NamingException,
- BaseException {
-
-
-
if (context == null) {
- String[] args = {
-
"context"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter context NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
-
if (StringUtils.isEmpty(cn)) {
- String[] args = {
-
"cn"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter cn NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
-
if (context == null) {
- String[] args = {
-
"context"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter context NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
-
if (StringUtils.isEmpty(newCn)) {
- String[] args = {
-
"newCn"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter newCn NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
- context.rename(cn, newCn);
-
- }
-
-
-
-
-
-
-
-
-
-
-
public static void addAttributes(DirContext context, String cn, Map attMap) throws
- BaseException, NamingException {
-
-
-
if (context == null) {
- String[] args = {
-
"context"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter context NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
-
if (attMap == null) {
- String[] args = {
-
"attMap"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter attMap NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
if (StringUtils.isEmpty(cn)) {
- String[] args = {
-
"cn"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter cn NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
-
if (attMap.isEmpty()) {
-
return;
- }
-
-
- Set keySet = attMap.keySet();
- Iterator keyIterator = keySet.iterator();
-
Attributes attrs = new BasicAttributes();
-
-
while (keyIterator.hasNext()) {
-
-
- String key = (String) keyIterator.next();
-
Attribute att = null;
- Object valueObj = attMap.get(key);
-
-
if (valueObj instanceof String) {
-
-
att = new BasicAttribute(key, valueObj);
-
} else if (valueObj instanceof List) {
-
-
att = new BasicAttribute(key);
- List valueList = (List) valueObj;
-
-
for (int i = 0; i < valueList.size(); i++) {
- att.add(valueList.get(i));
- }
- }
-
- attrs.put(att);
- }
-
- context.modifyAttributes(cn, DirContext.ADD_ATTRIBUTE, attrs);
-
- }
-
-
-
-
-
-
-
-
-
-
public static void deleteAttributes(DirContext context, String cn,
-
List attList) throws BaseException,
- NamingException {
-
-
if (context == null) {
- String[] args = {
-
"context"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter context NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
-
if (attList == null) {
- String[] args = {
-
"attList"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter attList NULL ");
- log.error(msglog.toString());
-
throw new BaseException("error.common.parameter.empty", args);
- }
-
-
if (StringUtils.isEmpty(cn)) {
- String[] args = {
-
"cn"};
-
-
StringBuffer msglog = new StringBuffer(
-
"empty invoke parameter cn NULL ");
- log.error(msglog.toString());
-
<span
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
本篇内容将深入探讨如何封装JNDI操作,以便更方便地与LDAP服务器进行交互。 首先,我们要理解封装的目标:简化 LDAP 操作,使得用户只需熟悉 List 和 Map 数据结构,而无需直接处理复杂的 JNDI API。为此,我们创建...
【封装JNDI操作LDAP】 在Java开发中,直接使用JNDI API操作LDAP可能会涉及很多底层细节,包括连接设置、安全配置等,这增加了代码的复杂性和出错的可能性。因此,为了简化这一过程,通常会创建一个工具类来封装这些...
在IT行业中,LDAP(Lightweight Directory Access Protocol)是一种用于访问和管理分布式目录服务的标准协议,常用于企业身份验证...在实际项目中,为了提高代码的可维护性和安全性,通常会封装成专门的服务或工具类。
1. **连接LDAP服务器**:使用`InitialDirContext`类建立与LDAP服务器的连接。首先,创建一个环境属性对象,配置服务器地址、端口、用户名和密码,然后通过`new InitialDirContext(environment)`初始化上下文。 2. *...
为了简化这些操作,你可以创建一个名为`LdapUtil`的工具类,封装连接、查询、添加、修改和删除的方法。这样可以使代码更易于理解和维护。 总结,Java LDAP操作涉及连接LDAP服务器、执行查询、添加、修改和删除条目...
- "ldapUtil"可能是这个压缩包中包含的Java工具类,它封装了对LDAP的各种操作,便于开发人员调用。 - 这个工具类可能包含连接LDAP服务器的方法,执行查询、增加、删除和修改操作的函数,以及异常处理逻辑。 学习...
在Java中,我们通常使用JNDI(Java Naming and Directory Interface)来与LDAP服务器交互。JNDI是一个API,它为多种命名和目录服务提供了统一的接口,包括LDAP。在本项目中,可能包含了一个或多个Java类,这些类封装...
Java Naming and Directory Interface (JNDI) 是Java平台中用于访问命名和目录服务的API,它允许程序查找和操作各种命名和目录服务,如 Lightweight Directory Access Protocol (LDAP)、Java Database Connectivity ...
3. **强大的查询支持**:通过LdapTemplate类,开发者可以使用XPath或LDIF(LDAP Data Interchange Format)进行复杂查询,同时提供了安全性和性能优化。 4. **事务管理**:Spring LDAP 支持LDAP操作的事务管理,使得...
`providerutil`组件则是这些提供者的辅助工具,它包含了一些通用的工具类和方法,帮助实现JNDI服务提供者的基本功能,比如上下文管理、属性处理等。 二、`com.sun.jndi.providerutil.jar`的功能 1. **提供者注册**...
在实际项目中,这些通常会被封装到配置类或工具类中,以提高代码的可重用性和安全性。 在压缩包文件"LdapCRUDTest"中,可能包含了实现上述功能的测试代码。这些代码会展示如何在Java中使用JNDI进行具体的LDAP操作,...
它封装了JNDI(Java Naming and Directory Interface)API,使得开发者能够以更简洁的方式进行目录操作。 2. **ContextSource**:用于配置与 LDAP 服务器的连接。它可以设置URL、基础DN(Distinguished Name)、...
更重要的是,反射操作往往破坏了封装性,可能导致安全风险,因此在使用反射时需要特别小心,遵循最小权限原则。 最后,耦合性是衡量软件模块之间相互依赖程度的一个度量。低耦合意味着模块之间的关系简单,易于理解...
- 类与对象:类的概念、对象的创建过程、封装、继承、多态的基本原理。 - 构造器:构造器的作用、构造器重载、构造器链调用。 - 继承:继承的概念、super关键字的使用、继承中的构造器调用规则。 - 多态:多态性...
1. **Java基础**:Java是该项目的基础语言,学习者需要掌握Java面向对象编程的基本概念,包括类、对象、封装、继承、多态等。此外,对异常处理、输入输出流、集合框架(如ArrayList、HashMap)的理解也是必要的。 2...
### Java/J2EE核心概念与关键领域 ... - **并发工具类**:熟悉ConcurrentHashMap等并发容器的使用方法。 通过以上知识点的学习,读者可以全面掌握Java/J2EE的核心概念和技术细节,为即将到来的技术面试做好充分准备。
总的来说,`JDirectory`是Java开发者处理LDAP目录服务的强大工具,它通过简化JNDI的使用,使得开发人员能更专注于应用逻辑,提高了开发效率和代码质量。了解并掌握`JDirectory`,对于从事相关领域开发的人员来说,...
5. JNDI/LDAP目录集成:本书还会介绍如何利用Java命名和目录接口(JNDI)以及轻量级目录访问协议(LDAP)进行企业级服务的发现和集成。 6. 国际化:随着现代软件越来越注重全球市场,本节将说明如何利用Java的国际...
这部分内容涵盖了变量、数据类型、运算符、控制结构、类与对象、封装、继承、多态等基本概念。 #### Swing Swing是Java中用于构建图形用户界面(GUI)的一套组件库。了解Swing可以帮助开发者创建美观且功能丰富的...