xxd763795151 commented on a change in pull request #71: URL: https://github.com/apache/rocketmq-dashboard/pull/71#discussion_r810635557
########## File path: src/main/java/org/apache/rocketmq/dashboard/controller/AclController.java ########## @@ -0,0 +1,146 @@ +/* + * 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.rocketmq.dashboard.controller; + +import com.google.common.base.Preconditions; +import java.util.List; +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.rocketmq.common.AclConfig; +import org.apache.rocketmq.common.PlainAccessConfig; +import org.apache.rocketmq.dashboard.config.RMQConfigure; +import org.apache.rocketmq.dashboard.model.User; +import org.apache.rocketmq.dashboard.model.UserInfo; +import org.apache.rocketmq.dashboard.model.request.AclRequest; +import org.apache.rocketmq.dashboard.permisssion.Permission; +import org.apache.rocketmq.dashboard.service.AclService; +import org.apache.rocketmq.dashboard.support.JsonResult; +import org.apache.rocketmq.dashboard.util.WebUtil; +import org.springframework.web.bind.annotation.DeleteMapping; +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; + +@RestController +@RequestMapping("/acl") +@Permission +public class AclController { + + @Resource + private AclService aclService; + + @Resource + private RMQConfigure configure; + + @GetMapping("/enable.query") + public Object isEnableAcl() { + return new JsonResult<>(configure.isACLEnabled()); + } + + @GetMapping("/config.query") + public AclConfig getAclConfig(HttpServletRequest request) { + if (!configure.isLoginRequired()) { + return aclService.getAclConfig(false); + } + UserInfo userInfo = (UserInfo) WebUtil.getValueFromSession(request, WebUtil.USER_INFO); + // if user info is null but reach here, must exclude secret key for safety. + return aclService.getAclConfig(userInfo == null || userInfo.getUser().getType() != User.ADMIN); + } + + @PostMapping("/add.do") + public Object addAclConfig(@RequestBody PlainAccessConfig config) { + Preconditions.checkArgument(StringUtils.isNotEmpty(config.getAccessKey()), "accessKey is null"); + Preconditions.checkArgument(StringUtils.isNotEmpty(config.getSecretKey()), "secretKey is null"); + aclService.addAclConfig(config); + return new JsonResult(0, ""); Review comment: I will adjust it later. When I optimize code first time, I try return true, but it occur json error. So I use this style as return value. But using this style, it doesn't seem to be a problem right now, I will optimize these code again. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
