Skip to content

Commit

Permalink
[INLONG-11608][Manager] Add permission verification for ordinary user…
Browse files Browse the repository at this point in the history
…s to create streams and sinks
  • Loading branch information
fuweng11 committed Dec 17, 2024
1 parent 302f808 commit aa1f33a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ public Integer save(SinkRequest request, String operator) {
// Check if it can be added
String groupId = request.getInlongGroupId();
groupCheckService.checkGroupStatus(groupId, operator);

InlongGroupEntity groupEntity = groupMapper.selectByGroupId(groupId);
if (groupEntity == null) {
throw new BusinessException(String.format("InlongGroup does not exist with InlongGroupId=%s", groupId));
}
userService.checkUser(groupEntity.getInCharges(), operator,
"Current user does not have permission to create sink info");
// Make sure that there is no same sink name under the current groupId and streamId
String streamId = request.getInlongStreamId();
String sinkName = request.getSinkName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public Integer save(SourceRequest request, String operator) {
// Check if it can be added
String groupId = request.getInlongGroupId();
String streamId = request.getInlongStreamId();
InlongGroupEntity groupEntity = groupMapper.selectByGroupId(groupId);
if (groupEntity == null) {
throw new BusinessException(String.format("InlongGroup does not exist with InlongGroupId=%s", groupId));
}
userService.checkUser(groupEntity.getInCharges(), operator,
"Current user does not have permission to create source info");
InlongStreamEntity streamEntity = groupCheckService.checkStreamStatus(groupId, streamId, operator);
String sourceName = request.getSourceName();
List<StreamSourceEntity> existList = sourceMapper.selectByRelatedId(groupId, streamId, sourceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@

package org.apache.inlong.manager.service.stream;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserManager;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.create.table.ColDataType;
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
import net.sf.jsqlparser.statement.create.table.CreateTable;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.inlong.manager.common.consts.InlongConstants;
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
import org.apache.inlong.manager.common.enums.GroupStatus;
Expand Down Expand Up @@ -68,20 +81,6 @@
import org.apache.inlong.manager.service.sink.StreamSinkService;
import org.apache.inlong.manager.service.source.StreamSourceService;
import org.apache.inlong.manager.service.user.UserService;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserManager;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.create.table.ColDataType;
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
import net.sf.jsqlparser.statement.create.table.CreateTable;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -166,7 +165,12 @@ public Integer save(InlongStreamRequest request, String operator) {

// Check if it can be added
checkGroupStatusIsTemp(groupId);

InlongGroupEntity groupEntity = groupMapper.selectByGroupId(groupId);
if (groupEntity == null) {
throw new BusinessException(String.format("InlongGroup does not exist with InlongGroupId=%s", groupId));
}
userService.checkUser(groupEntity.getInCharges(), operator,
"Current user does not have permission to create stream info");
// The streamId under the same groupId cannot be repeated
Integer count = streamMapper.selectExistByIdentifier(groupId, streamId);
if (count >= 1) {
Expand Down

0 comments on commit aa1f33a

Please sign in to comment.