`
- 浏览:
25512 次
- 性别:
- 来自:
广州
-
- 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服务器所要使用的类的详细介绍。 封装JNDI操作LDAP服务器的工具类.doc
主要介绍了封装JNDI操作LDAP服务器的工具类,使用者只需要会使用List,Map 数据结构,大家参考使用吧
Windows_7_下搭建LDAP服务器并使用JNDI Windows_7_下搭建LDAP服务器并使用JNDI Windows_7_下搭建LDAP服务器并使用JNDI
基于Java JNDI 操纵LDAP的基础实现,包括LDAP连接相关生命周期,认证的两种策略demo,条目的操作,schema的基础操作包括(attributeDefinition\objectDefinition\)但未包含相关syntaxDefinition的操纵. 没有资源分的朋友...
import com.sun.jndi.ldap.ctl.VirtualListViewControl;
JNDI 操作 LDAP的几个例子源码 包括连接、添加、删除、修改、搜寻
NULL 博文链接:https://zzqrj.iteye.com/blog/1279219
maven稀缺jar资源
除了已知的JNDI攻击方法(通过引用中的远程类加载)之外,此工具还利用的功能带来了新的攻击媒介。 支持的有效载荷 经典的JNDI攻击,通过远程类加载导致RCE,可达到jdk8u191 通过org.apache.naming.factory.Bea
LDAPWindows 7 下搭建LDAP服务器并使用JNDI
提供了使用fsContext服务器的unbind bind list lookup rename的相关例子,及ldap 连接的一个例子 jndi,就是命名服务(n:naming)和目录服务(d:directory). 命名服务:把对象映射到方便记忆的名字的机制.可以通过域名系统...
详细讲解了JNDI概念和目录服务的配置,以LDAP服务器为平台,全面讲解JNDI操作LDAP.详细这本书是很多人都需要的,在大型项目中是经常使用的.
一款用作JNDI注入利用的工具,大量参考/引用了Rogue JNDI项目的代码,支持直接插入植入内存shell ,并集成了常见的bypass 高版本JDK的方式,适用于与自动化工具配合使用。 使用说明 使用java -jar JNDIExploit.jar -...
JNDI服务利用工具 RMI/LDAP,支持部分场景回显、内存shell,高版本JDK场景下利用等,fastjson rce命令执行,log4j rce命令执行 漏洞检测辅助工具
AD ldap java集成
jndi对数据库操作 数据源对数据库操作 最简单的java
rmi-jndi-ldap-jrmp-jmx-jms rmi,jndi,ldap,jrmp,jmx,jms一些演示测试
027-JNDI之初探 LDAP.pdf