SringLdap,基于对CSV文件的解析来批量增加,更新AD用户——超详细

本文详细介绍了如何通过SpringLdap解析CSV文件,实现对AD域用户的批量增加和更新操作。首先解析文件,判断用户是新增还是更新,接着分别处理新增和更新用户的过程。在创建ADUser对象后进行测试。批量操作的关键点在于异常处理和OU的变化,当用户部门变更时,需要单独处理OU更新。
摘要由CSDN通过智能技术生成

根据csv文件批量更新AD域的用户

1、解析CSV文件并确定是新增还是更新用户

package com.lls.it.ldapapi.service;

import com.lls.it.ldapapi.entity.AdUser;
import com.lls.it.ldapapi.exception.UserExistException;
import com.lls.it.ldapapi.exception.UserNotFoundException;
import com.opencsv.CSVReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.FileReader;

@Service
public class CSVReaderService {
   

    private static final String USER_ACCOUNT_CONTROL = "66048";

    @Autowired
    private UserService userService;

    /**
     * dealType: 1, create用户; 2, update用户
     * 根据导入的CSV文件批量新增用户
     */
    public boolean ParseCSVFile(String file, Integer dealType) {
        try {
            CSVReader reader = null;
            reader = new CSVReader(new FileReader(file));
            String[] line = null;
            reader.readNext();
            // 批量创建用户
            if (dealType == 1) {
                while ((line = reader.readNext()) != null) {
                    if (userService.findByAccountName(line[0]) == null) {
                        batchCreateADUser(line);
                    } else {
                        throw new UserExistException(String.format("user %s has existed&
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值