add query acl list by group API
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.xuxd.kafka.console.beans;
|
||||
|
||||
import java.util.Objects;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.kafka.common.acl.AccessControlEntry;
|
||||
@@ -49,6 +50,11 @@ public class AclEntry {
|
||||
return entry;
|
||||
}
|
||||
|
||||
public boolean isNull() {
|
||||
return Objects.isNull(resourceType) && Objects.isNull(name) && Objects.isNull(patternType) && Objects.isNull(principal)
|
||||
&& Objects.isNull(host) && Objects.isNull(operation) && Objects.isNull(permissionType);
|
||||
}
|
||||
|
||||
public AclBinding toAclBinding() {
|
||||
ResourceType resourceType = StringUtils.isBlank(this.resourceType) ? ResourceType.UNKNOWN : ResourceType.valueOf(this.resourceType);
|
||||
String resourceName = StringUtils.isBlank(this.name) ? ResourcePattern.WILDCARD_RESOURCE : this.name;
|
||||
@@ -62,12 +68,12 @@ public class AclEntry {
|
||||
}
|
||||
|
||||
public AclBindingFilter toAclBindingFilter() {
|
||||
ResourceType resourceType = StringUtils.isBlank(this.resourceType) ? ResourceType.UNKNOWN : ResourceType.valueOf(this.resourceType);
|
||||
ResourceType resourceType = StringUtils.isBlank(this.resourceType) ? ResourceType.UNKNOWN : ResourceType.valueOf(this.resourceType.toUpperCase());
|
||||
String resourceName = StringUtils.isBlank(this.name) ? ResourcePattern.WILDCARD_RESOURCE : this.name;
|
||||
PatternType patternType = StringUtils.isBlank(this.patternType) ? PatternType.LITERAL : PatternType.valueOf(this.patternType);
|
||||
String principal = StringUtils.isNotBlank(this.principal) ? new KafkaPrincipal(KafkaPrincipal.USER_TYPE, this.principal).toString() : KafkaPrincipal.ANONYMOUS.toString();
|
||||
String host = StringUtils.isBlank(this.host) ? ResourcePattern.WILDCARD_RESOURCE : this.host;
|
||||
AclOperation operation = StringUtils.isBlank(this.operation) ? AclOperation.UNKNOWN : AclOperation.valueOf(this.operation);
|
||||
AclOperation operation = StringUtils.isBlank(this.operation) ? AclOperation.UNKNOWN : AclOperation.valueOf(this.operation.toUpperCase());
|
||||
AclPermissionType permissionType = StringUtils.isBlank(this.permissionType) ? AclPermissionType.ALLOW : AclPermissionType.valueOf(this.permissionType);
|
||||
|
||||
AclBindingFilter filter = new AclBindingFilter(new ResourcePatternFilter(resourceType, resourceName, patternType),
|
||||
|
||||
25
src/main/java/com/xuxd/kafka/console/beans/CounterMap.java
Normal file
25
src/main/java/com/xuxd/kafka/console/beans/CounterMap.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.xuxd.kafka.console.beans;
|
||||
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-08-31 21:05:14
|
||||
**/
|
||||
public class CounterMap<K, E> {
|
||||
|
||||
@Getter
|
||||
private Map<K, E> map;
|
||||
|
||||
@Getter
|
||||
private int total;
|
||||
|
||||
public CounterMap(Map<K, E> map) {
|
||||
this.map = map;
|
||||
this.total = this.map != null ? this.map.size() : 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.xuxd.kafka.console.beans.dto;
|
||||
|
||||
import com.xuxd.kafka.console.beans.AclEntry;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-08-31 17:18:40
|
||||
**/
|
||||
@Data
|
||||
public class QueryAclDTO {
|
||||
|
||||
private String resourceType;
|
||||
|
||||
private String username = null;
|
||||
|
||||
private String resourceName = null;
|
||||
|
||||
public AclEntry toEntry() {
|
||||
AclEntry entry = new AclEntry();
|
||||
entry.setPrincipal(username);
|
||||
entry.setResourceType(resourceType);
|
||||
entry.setName(resourceName);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.xuxd.kafka.console.beans.AclEntry;
|
||||
import com.xuxd.kafka.console.beans.dto.ConsumerAuthDTO;
|
||||
import com.xuxd.kafka.console.beans.dto.DeleteAclDTO;
|
||||
import com.xuxd.kafka.console.beans.dto.ProducerAuthDTO;
|
||||
import com.xuxd.kafka.console.beans.dto.QueryAclDTO;
|
||||
import com.xuxd.kafka.console.service.AclService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
@@ -31,6 +32,11 @@ public class AclAuthController {
|
||||
return aclService.getAclList();
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Object getAclList(@RequestBody QueryAclDTO param) {
|
||||
return aclService.getAclList(param.toEntry());
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public Object addAcl(@RequestBody AclEntry entry) {
|
||||
return aclService.addAcl(entry);
|
||||
|
||||
@@ -20,6 +20,8 @@ public interface AclService {
|
||||
|
||||
ResponseData getAclList();
|
||||
|
||||
ResponseData getAclList(AclEntry entry);
|
||||
|
||||
ResponseData deleteAcl(AclEntry entry);
|
||||
|
||||
ResponseData addAcl(AclEntry entry);
|
||||
|
||||
@@ -2,10 +2,12 @@ package com.xuxd.kafka.console.service.impl;
|
||||
|
||||
import com.xuxd.kafka.console.beans.AclEntry;
|
||||
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.service.AclService;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import kafka.console.KafkaAclConsole;
|
||||
@@ -49,11 +51,19 @@ public class AclServiceImpl implements AclService {
|
||||
}
|
||||
|
||||
@Override public ResponseData getAclList() {
|
||||
List<AclBinding> aclBindingList = aclConsole.getAclList();
|
||||
List<AclBinding> aclBindingList = aclConsole.getAclList(null);
|
||||
|
||||
return ResponseData.create().data(new CounterList<>(aclBindingList.stream().map(x -> AclEntry.valueOf(x)).collect(Collectors.toList()))).success();
|
||||
}
|
||||
|
||||
@Override public ResponseData getAclList(AclEntry entry) {
|
||||
List<AclBinding> aclBindingList = entry.isNull() ? aclConsole.getAclList(null) : aclConsole.getAclList(entry);
|
||||
List<AclEntry> entryList = aclBindingList.stream().map(x -> AclEntry.valueOf(x)).collect(Collectors.toList());
|
||||
Map<String, List<AclEntry>> entryMap = entryList.stream().collect(Collectors.groupingBy(AclEntry::getPrincipal));
|
||||
|
||||
return ResponseData.create().data(new CounterMap<>(entryMap)).success();
|
||||
}
|
||||
|
||||
@Override public ResponseData deleteAcl(AclEntry entry) {
|
||||
return aclConsole.deleteAcl(entry, false, false, false) ? ResponseData.create().success() : ResponseData.create().failed();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user