add user detail module

This commit is contained in:
许晓东
2021-09-07 17:28:11 +08:00
parent 139037ef26
commit 9e01d244f9
8 changed files with 147 additions and 85 deletions

View File

@@ -0,0 +1,21 @@
package com.xuxd.kafka.console.beans.vo;
import lombok.Data;
/**
* kafka-console-ui.
*
* @author xuxd
* @date 2021-09-07 14:10:10
**/
@Data
public class KafkaUserDetailVO {
private String username;
private String password;
private String credentialInfos;
private String consistencyDescription;
}

View File

@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
@@ -43,4 +44,9 @@ public class AclUserController {
public Object deleteUserAndAuth(@RequestBody AclUser user) {
return aclService.deleteUserAndAuth(user.getUsername());
}
@GetMapping("/detail")
public Object getUserDetail(@RequestParam String username) {
return aclService.getUserDetail(username);
}
}

View File

@@ -5,6 +5,7 @@ import com.xuxd.kafka.console.beans.CounterList;
import com.xuxd.kafka.console.beans.CounterMap;
import com.xuxd.kafka.console.beans.ResponseData;
import com.xuxd.kafka.console.beans.dos.KafkaUserDO;
import com.xuxd.kafka.console.beans.vo.KafkaUserDetailVO;
import com.xuxd.kafka.console.config.KafkaConfig;
import com.xuxd.kafka.console.dao.KafkaUserMapper;
import com.xuxd.kafka.console.service.AclService;
@@ -77,7 +78,7 @@ public class AclServiceImpl implements AclService, SmartInitializingSingleton {
map.put("username", name);
kafkaUserMapper.deleteByMap(map);
kafkaUserMapper.insert(userDO);
}catch (Exception e) {
} catch (Exception e) {
log.error("kafkaUserMapper.insert error.", e);
return ResponseData.create().failed(e.getMessage());
}
@@ -107,7 +108,7 @@ public class AclServiceImpl implements AclService, SmartInitializingSingleton {
}
@Override public ResponseData getAclDetailList(AclEntry entry) {
List<AclBinding> aclBindingList = entry ==null || entry.isNull() ? aclConsole.getAclList(null) : aclConsole.getAclList(entry);
List<AclBinding> aclBindingList = entry == null || entry.isNull() ? aclConsole.getAclList(null) : aclConsole.getAclList(entry);
return ResponseData.create().data(new CounterList<>(aclBindingList.stream().map(x -> AclEntry.valueOf(x)).collect(Collectors.toList()))).success();
}
@@ -182,15 +183,26 @@ public class AclServiceImpl implements AclService, SmartInitializingSingleton {
}
@Override public ResponseData getUserDetail(String username) {
KafkaUserDetailVO vo = new KafkaUserDetailVO();
vo.setUsername(username);
Map<String, UserScramCredentialsDescription> detailList = configConsole.getUserDetailList(Collections.singletonList(username));
if (!detailList.isEmpty() && detailList.containsKey(username)) {
UserScramCredentialsDescription description = detailList.get(username);
String credentialInfo = StringUtils.join(description.credentialInfos(), ";");
vo.setCredentialInfos(credentialInfo);
}
Map<String, Object> param = new HashMap<>();
param.put("username", username);
List<KafkaUserDO> dos = kafkaUserMapper.selectByMap(param);
if (dos.isEmpty()) {
return ResponseData.create().data(new CounterList<>(dos)).success("Retrieved the user info is null.");
vo.setConsistencyDescription("Password is null.");
} else {
vo.setPassword(dos.stream().findFirst().get().getPassword());
}
// check for consistency.
return null;
return ResponseData.create().data(vo).success();
}
@Override public void afterSingletonsInstantiated() {