Skip to content

Commit

Permalink
feat: add service user and acl
Browse files Browse the repository at this point in the history
  • Loading branch information
318228han committed Mar 30, 2024
1 parent 13eae3f commit 7f9c83f
Show file tree
Hide file tree
Showing 15 changed files with 822 additions and 121 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.eventmesh.dashboard.console.controller;

import org.apache.eventmesh.dashboard.console.entity.acl.AclEntity;
import org.apache.eventmesh.dashboard.console.service.acl.AclService;

import org.springframework.beans.factory.annotation.Autowired;
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.RestController;

@RestController
@RequestMapping("/acl")
public class AclController {

@Autowired
private AclService aclService;

@PostMapping("/insertAcl")
public void insertAcl(@RequestBody AclEntity aclEntity) {
this.aclService.insert(aclEntity);
}

@PostMapping("deleteAcl")
public void deleteAcl(@RequestBody AclEntity aclEntity) {
this.aclService.deleteAclById(aclEntity);
}

@PostMapping("/updateAcl")
public void updateAcl(@RequestBody AclEntity aclEntity) {
this.aclService.updateResourceTypeById(aclEntity);
}

@PostMapping("/selectAcl")
public void selectAcl(@RequestBody AclEntity aclEntity) {
this.aclService.selectById(aclEntity);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.eventmesh.dashboard.console.controller;

import org.apache.eventmesh.dashboard.console.entity.serviceuser.ServiceUserEntity;
import org.apache.eventmesh.dashboard.console.service.serviceuser.ServiceUserService;

import org.springframework.beans.factory.annotation.Autowired;
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.RestController;

@RestController
@RequestMapping("/serviceUser")
public class ServiceUserController {

@Autowired
private ServiceUserService serviceUserService;

@PostMapping("/insertServiceUser")
public void insertServiceUser(@RequestBody ServiceUserEntity serviceUserEntity) {
this.serviceUserService.insert(serviceUserEntity);
}

@PostMapping("/deleteServiceUserByCluster")
public void deleteServiceUserByCluster(@RequestBody ServiceUserEntity serviceUserEntity) {
this.serviceUserService.deleteServiceUserByCluster(serviceUserEntity);
}

@PostMapping("/updateNameById")
public void updateNameById(@RequestBody ServiceUserEntity serviceUserEntity) {
this.serviceUserService.updatePasswordById(serviceUserEntity);
}

@PostMapping("/selectAll")
public void selectAll() {

}

@PostMapping("/selectById")
public void selectById(@RequestBody ServiceUserEntity serviceUserEntity) {
this.serviceUserService.selectById(serviceUserEntity);
}

@PostMapping("/selectByName")
public void selectByName(@RequestBody ServiceUserEntity serviceUserEntity) {
this.serviceUserService.selectByName(serviceUserEntity);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.eventmesh.dashboard.console.entity.acl;

import org.apache.eventmesh.dashboard.console.entity.base.BaseEntity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true, exclude = "status")
public class AclEntity extends BaseEntity {

private static final long serialVersionUID = 6057071983428111947L;
private Long id;
private Long clusterId;
private String principal;
private Integer operation;
private Integer permissionType;
private String host;
private Integer resourceType;
private String resourceName;
private Integer patternType;
private Integer status;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.eventmesh.dashboard.console.entity.serviceuser;

import org.apache.eventmesh.dashboard.console.entity.base.BaseEntity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;


@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true, exclude = "status")
public class ServiceUserEntity extends BaseEntity {

private Integer serviceType;

private String password;

private Long clusterId;

private String name;

private String token;

private Integer status;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.eventmesh.dashboard.console.mapper.acl;

import org.apache.eventmesh.dashboard.console.entity.acl.AclEntity;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* Mybatis Mapper for the table of acl.
*/
@Mapper
public interface AclMapper {

@Insert({
"<script>",
" INSERT INTO acl (cluster_Id, principal, operation, permission_Type, host, resource_Type, resource_Name, pattern_Type) VALUES ",
" <foreach collection='list' item='c' index='index' separator=','>",
" (#{c.clusterId}, #{c.principal}, #{c.operation}, #{c.permissionType}, #{c.host}, "
+
" #{c.resourceType}, #{c.resourceName}, #{c.patternType})",
" </foreach>",
"</script>"})
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
void batchInsert(List<AclEntity> aclEntities);

@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
@Insert("INSERT INTO acl (cluster_id, principal, operation, permission_type, host, resource_type, resource_name, pattern_type)"
+ "VALUE (#{clusterId}, #{principal}, #{operation}, #{permissionType}, #{host}, #{resourceType}, #{resourceName}, #{patternType})")
void insert(AclEntity aclEntity);

@Update("UPDATE acl SET status=0 WHERE id=#{id}")
void deleteById(AclEntity aclEntity);

@Update("UPDATE acl SET resource_type=#{resourceType} WHERE id=#{id}")
void updateResourceTypeById(AclEntity aclEntity);

@Select("SELECT * FROM acl")
List<AclEntity> selectAll();

@Select("SELECT * FROM acl WHERE id=#{id}")
AclEntity selectById(AclEntity aclEntity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public interface ConfigMapper {
@Insert("INSERT INTO config (cluster_id, business_type, instance_type, instance_id, config_name, config_value, start_version, "
+ "status, is_default, end_version, diff_type, description, edit, is_modify, eventmesh_version) VALUE "
+ "(#{clusterId},#{businessType},#{instanceType},#{instanceId},#{configName},"
+ "#{configValue},#{startVersion},#{status},#{isDefault},#{endVersion},#{diffType},#{description},#{edit},#{isModify},#{eventmeshVersion})")
+ "#{configValue},#{startVersion},#{status},#{isDefault},#{endVersion},#{diffType},"
+ "#{description},#{edit},#{isModify},#{eventmeshVersion})")
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
Integer addConfig(ConfigEntity configEntity);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.eventmesh.dashboard.console.mapper.serviceuser;

import org.apache.eventmesh.dashboard.console.entity.serviceuser.ServiceUserEntity;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* Mybatis Mapper for the table of serviceuser.
*/
@Mapper
public interface ServiceUserMapper {

@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
@Insert("INSERT INTO service_user (id, service_type, password, cluster_id, name, token, status) "
+ "VALUES (#{id}, #{serviceType}, #{password}, #{clusterId}, #{name}, #{token},1)")
void insert(ServiceUserEntity serviceuserEntity);

@Update("UPDATE service_user SET status=0 WHERE cluster_id=#{clusterId}")
void deleteServiceUserByCluster(ServiceUserEntity serviceuserEntity);

@Update("UPDATE service_user SET password=#{password} WHERE id=#{id}")
void updatePasswordById(ServiceUserEntity serviceuserentity);

@Select("SELECT * FROM service_user WHERE status=1")
List<ServiceUserEntity> selectAll();

@Select("SELECT * FROM service_user WHERE id=#{id} AND status=1")
ServiceUserEntity selectById(ServiceUserEntity serviceuserEntity);

@Select("SELECT * FROM service_user WHERE name=#{name} AND status=1")
List<ServiceUserEntity> selectByName(ServiceUserEntity serviceuserEntity);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.eventmesh.dashboard.console.service.acl;

import org.apache.eventmesh.dashboard.console.entity.acl.AclEntity;

import java.util.List;

/**
* Service providing data of acl.
*/
public interface AclService {

void insert(AclEntity aclEntity);

void deleteAclById(AclEntity aclEntity);

void updateResourceTypeById(AclEntity aclEntity);

List<AclEntity> selectAll();

AclEntity selectById(AclEntity aclEntity);

}
Loading

0 comments on commit 7f9c83f

Please sign in to comment.