mirror of https://gitee.com/topiam/eiam
应用分组新增分组类型
parent
68fa64b80a
commit
5ea64964ce
|
@ -17,8 +17,9 @@
|
|||
*/
|
||||
package cn.topiam.employee.application;
|
||||
|
||||
import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity;
|
||||
import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.util.AlternativeJdkIdGenerator;
|
||||
import org.springframework.util.IdGenerator;
|
||||
|
@ -27,17 +28,16 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
|
||||
import cn.topiam.employee.common.entity.app.AppAccountEntity;
|
||||
import cn.topiam.employee.common.entity.app.AppEntity;
|
||||
import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity;
|
||||
import cn.topiam.employee.common.enums.app.AuthorizationType;
|
||||
import cn.topiam.employee.common.enums.app.InitLoginType;
|
||||
import cn.topiam.employee.common.exception.app.AppAccountNotExistException;
|
||||
import cn.topiam.employee.common.repository.app.AppAccountRepository;
|
||||
import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository;
|
||||
import cn.topiam.employee.common.repository.app.AppRepository;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AbstractApplicationService
|
||||
*
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.time.LocalDateTime;
|
|||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
|
||||
import cn.topiam.employee.common.repository.app.*;
|
||||
import org.bouncycastle.asn1.x500.X500Name;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -33,6 +32,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
|
||||
import cn.topiam.employee.common.entity.app.AppCertEntity;
|
||||
import cn.topiam.employee.common.enums.app.AppCertUsingType;
|
||||
import cn.topiam.employee.common.repository.app.*;
|
||||
import cn.topiam.employee.support.exception.TopIamException;
|
||||
import cn.topiam.employee.support.util.CertUtils;
|
||||
import cn.topiam.employee.support.util.RsaUtils;
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -36,6 +35,7 @@ import cn.topiam.employee.common.entity.app.po.AppFormConfigPO;
|
|||
import cn.topiam.employee.common.enums.app.*;
|
||||
import cn.topiam.employee.common.repository.app.AppAccountRepository;
|
||||
import cn.topiam.employee.common.repository.app.AppFormConfigRepository;
|
||||
import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository;
|
||||
import cn.topiam.employee.common.repository.app.AppRepository;
|
||||
import cn.topiam.employee.support.exception.TopIamException;
|
||||
import cn.topiam.employee.support.validation.ValidationUtils;
|
||||
|
|
|
@ -20,6 +20,7 @@ package cn.topiam.employee.common.entity.app;
|
|||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
||||
import cn.topiam.employee.common.enums.app.AppGroupType;
|
||||
import cn.topiam.employee.support.repository.domain.LogicDeleteEntity;
|
||||
|
||||
import lombok.Getter;
|
||||
|
@ -53,11 +54,17 @@ public class AppGroupEntity extends LogicDeleteEntity<Long> {
|
|||
* 分组名称
|
||||
*/
|
||||
@Column(name = "name_")
|
||||
private String name;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 分组编码
|
||||
*/
|
||||
@Column(name = "code_")
|
||||
private String code;
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 分组类型
|
||||
*/
|
||||
@Column(name = "type_")
|
||||
private AppGroupType type;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* eiam-common - Employee Identity and Access Management
|
||||
* Copyright © 2022-Present Jinan Yuanchuang Network Technology Co., Ltd. (support@topiam.cn)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package cn.topiam.employee.common.enums.app;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
import cn.topiam.employee.support.enums.BaseEnum;
|
||||
import cn.topiam.employee.support.web.converter.EnumConvert;
|
||||
|
||||
/**
|
||||
* 应用分组类型
|
||||
*
|
||||
* @author TopIAM
|
||||
* Created by support@topiam.cn on 2023/9/9 16:22
|
||||
*/
|
||||
public enum AppGroupType implements BaseEnum {
|
||||
/**
|
||||
* 默认分组
|
||||
*/
|
||||
DEFAULT("default", "默认分组"),
|
||||
/**
|
||||
* 自定义分组
|
||||
*/
|
||||
CUSTOM("custom", "自定义分组");
|
||||
|
||||
@JsonValue
|
||||
private final String code;
|
||||
private final String desc;
|
||||
|
||||
AppGroupType(String code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类型
|
||||
*
|
||||
* @param code {@link String}
|
||||
* @return {@link AppGroupType}
|
||||
*/
|
||||
@EnumConvert
|
||||
public static AppGroupType getType(String code) {
|
||||
AppGroupType[] values = values();
|
||||
for (AppGroupType status : values) {
|
||||
if (String.valueOf(status.getCode()).equals(code)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* eiam-common - Employee Identity and Access Management
|
||||
* Copyright © 2022-Present Jinan Yuanchuang Network Technology Co., Ltd. (support@topiam.cn)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package cn.topiam.employee.common.enums.app.converter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import cn.topiam.employee.common.enums.app.AppGroupType;
|
||||
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.Converter;
|
||||
|
||||
/**
|
||||
* @author TopIAM
|
||||
* Created by support@topiam.cn on 2023/9/9 16:23
|
||||
*/
|
||||
@Converter(autoApply = true)
|
||||
public class AppGroupTypeConverter implements AttributeConverter<AppGroupType, String> {
|
||||
|
||||
/**
|
||||
* Converts the value stored in the entity attribute into the
|
||||
* data representation to be stored in the database.
|
||||
*
|
||||
* @param attribute the entity attribute value to be converted
|
||||
* @return the converted data to be stored in the database
|
||||
* column
|
||||
*/
|
||||
@Override
|
||||
public String convertToDatabaseColumn(AppGroupType attribute) {
|
||||
if (!Objects.isNull(attribute)) {
|
||||
return attribute.getCode();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the data stored in the database column into the
|
||||
* value to be stored in the entity attribute.
|
||||
* Note that it is the responsibility of the converter writer to
|
||||
* specify the correct <code>dbData</code> type for the corresponding
|
||||
* column for use by the JDBC driver: i.e., persistence providers are
|
||||
* not expected to do such type conversion.
|
||||
*
|
||||
* @param dbData the data from the database column to be
|
||||
* converted
|
||||
* @return the converted value to be stored in the entity
|
||||
* attribute
|
||||
*/
|
||||
@Override
|
||||
public AppGroupType convertToEntityAttribute(String dbData) {
|
||||
return AppGroupType.getType(dbData);
|
||||
}
|
||||
}
|
|
@ -24,12 +24,10 @@ import org.jetbrains.annotations.NotNull;
|
|||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import cn.topiam.employee.common.entity.app.AppGroupEntity;
|
||||
import cn.topiam.employee.support.repository.LogicDeleteRepository;
|
||||
|
@ -56,20 +54,6 @@ public interface AppGroupRepository extends LogicDeleteRepository<AppGroupEntity
|
|||
@CacheEvict(allEntries = true)
|
||||
<S extends AppGroupEntity> S save(@NotNull S entity);
|
||||
|
||||
/**
|
||||
* 更新应用分组状态
|
||||
*
|
||||
* @param id {@link Long}
|
||||
* @param enabled {@link Boolean}
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
@Modifying
|
||||
@CacheEvict(allEntries = true)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Query(value = "UPDATE app_group SET is_enabled = :enabled WHERE id_ = :id", nativeQuery = true)
|
||||
Integer updateAppGroupStatus(@Param(value = "id") Long id,
|
||||
@Param(value = "enabled") Boolean enabled);
|
||||
|
||||
/**
|
||||
* delete
|
||||
*
|
||||
|
|
|
@ -58,6 +58,7 @@ public class AppGroupRepositoryCustomizedImpl implements AppGroupRepositoryCusto
|
|||
`group`.id_,
|
||||
`group`.name_,
|
||||
`group`.code_,
|
||||
`group`.type_,
|
||||
`group`.create_time,
|
||||
`group`.remark_,
|
||||
IFNULL( ass.app_count, 0 ) AS app_count
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.time.LocalDateTime;
|
|||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import cn.topiam.employee.common.entity.app.po.AppGroupPO;
|
||||
import cn.topiam.employee.common.enums.app.AppGroupType;
|
||||
|
||||
/**
|
||||
* @author TopIAM
|
||||
|
@ -47,8 +48,9 @@ public class AppGroupPoMapper implements RowMapper<AppGroupPO> {
|
|||
public AppGroupPO mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
AppGroupPO appGroup = new AppGroupPO();
|
||||
appGroup.setId(rs.getLong("id_"));
|
||||
appGroup.setCode(rs.getString("code_"));
|
||||
appGroup.setName(rs.getString("name_"));
|
||||
appGroup.setCode(rs.getString("code_"));
|
||||
appGroup.setType(AppGroupType.getType(rs.getString("type_")));
|
||||
appGroup.setRemark(rs.getString("remark_"));
|
||||
appGroup.setAppCount(rs.getInt("app_count"));
|
||||
appGroup.setCreateTime(rs.getObject("create_time", LocalDateTime.class));
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
<column name="code_" remarks="分组编码" type="VARCHAR(64)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="type_" type="VARCHAR(20)" remarks="类型(默认、自定义)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="create_by" remarks="创建者" type="VARCHAR(64)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
|
|
|
@ -143,41 +143,7 @@ public class AppGroupController {
|
|||
}
|
||||
|
||||
/**
|
||||
* 启用应用分组
|
||||
*
|
||||
* @param id {@link String}
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
@Lock
|
||||
@Preview
|
||||
@Operation(summary = "启用应用分组")
|
||||
@Audit(type = EventType.ENABLE_APP_GROUP)
|
||||
@PutMapping(value = "/enable/{id}")
|
||||
@PreAuthorize(value = "authenticated and @sae.hasAuthority(T(cn.topiam.employee.support.security.userdetails.UserType).ADMIN)")
|
||||
public ApiRestResult<Boolean> enableAppGroup(@PathVariable(value = "id") String id) {
|
||||
boolean result = appGroupService.enableAppGroup(id);
|
||||
return ApiRestResult.<Boolean> builder().result(result).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用应用分组
|
||||
*
|
||||
* @param id {@link String}
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
@Lock
|
||||
@Preview
|
||||
@Operation(summary = "禁用应用分组")
|
||||
@Audit(type = EventType.DISABLE_APP_GROUP)
|
||||
@PutMapping(value = "/disable/{id}")
|
||||
@PreAuthorize(value = "authenticated and @sae.hasAuthority(T(cn.topiam.employee.support.security.userdetails.UserType).ADMIN)")
|
||||
public ApiRestResult<Boolean> disableAppGroup(@PathVariable(value = "id") String id) {
|
||||
boolean result = appGroupService.disableAppGroup(id);
|
||||
return ApiRestResult.<Boolean> builder().result(result).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除分组用户
|
||||
* 移除应用组关联
|
||||
*
|
||||
* @param id {@link String}
|
||||
* @return {@link Boolean}
|
||||
|
|
|
@ -20,6 +20,8 @@ package cn.topiam.employee.console.pojo.result.app;
|
|||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import cn.topiam.employee.common.enums.app.AppGroupType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
|
@ -53,6 +55,12 @@ public class AppGroupListResult implements Serializable {
|
|||
@Parameter(description = "分组编码")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 分组类型
|
||||
*/
|
||||
@Parameter(description = "分组类型")
|
||||
private AppGroupType type;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.io.Serializable;
|
|||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
|
|
|
@ -80,31 +80,6 @@ public interface AppGroupService {
|
|||
*/
|
||||
AppGroupGetResult getAppGroup(Long id);
|
||||
|
||||
/**
|
||||
* 启用应用分组
|
||||
*
|
||||
* @param id {@link String}
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
Boolean enableAppGroup(String id);
|
||||
|
||||
/**
|
||||
* 禁用应用分组
|
||||
*
|
||||
* @param id {@link String}
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
Boolean disableAppGroup(String id);
|
||||
|
||||
/**
|
||||
* 添加应用
|
||||
*
|
||||
* @param appIds {@link String}
|
||||
* @param groupId {@link String}
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
Boolean addAssociation(String groupId, String[] appIds);
|
||||
|
||||
/**
|
||||
* 批量移除应用
|
||||
*
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package cn.topiam.employee.console.service.app.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
@ -26,17 +25,15 @@ import org.springframework.data.domain.PageRequest;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cn.topiam.employee.audit.context.AuditContext;
|
||||
import cn.topiam.employee.audit.entity.Target;
|
||||
import cn.topiam.employee.audit.enums.TargetType;
|
||||
import cn.topiam.employee.common.entity.app.AppEntity;
|
||||
import cn.topiam.employee.common.entity.app.AppGroupAssociationEntity;
|
||||
import cn.topiam.employee.common.entity.app.AppGroupEntity;
|
||||
import cn.topiam.employee.common.entity.app.po.AppGroupPO;
|
||||
import cn.topiam.employee.common.entity.app.query.AppGroupAssociationListQuery;
|
||||
import cn.topiam.employee.common.entity.app.query.AppGroupQuery;
|
||||
import cn.topiam.employee.common.enums.app.AppGroupType;
|
||||
import cn.topiam.employee.common.repository.app.AppGroupAssociationRepository;
|
||||
import cn.topiam.employee.common.repository.app.AppGroupRepository;
|
||||
import cn.topiam.employee.console.converter.app.AppConverter;
|
||||
|
@ -93,6 +90,7 @@ public class AppGroupServiceImpl implements AppGroupService {
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean createAppGroup(AppGroupCreateParam param) {
|
||||
AppGroupEntity entity = appGroupConverter.appGroupCreateParamConvertToEntity(param);
|
||||
entity.setType(AppGroupType.CUSTOM);
|
||||
appGroupRepository.save(entity);
|
||||
AuditContext.setTarget(
|
||||
Target.builder().id(String.valueOf(entity.getId())).type(TargetType.APP_GROUP).build());
|
||||
|
@ -149,34 +147,6 @@ public class AppGroupServiceImpl implements AppGroupService {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用应用分组
|
||||
*
|
||||
* @param id {@link String}
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
@Override
|
||||
public Boolean enableAppGroup(String id) {
|
||||
appGroupRequireNonNull(Long.valueOf(id));
|
||||
Integer count = appGroupRepository.updateAppGroupStatus(Long.valueOf(id), Boolean.TRUE);
|
||||
AuditContext.setTarget(Target.builder().id(id).type(TargetType.APP_GROUP).build());
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用应用分组
|
||||
*
|
||||
* @param id {@link String}
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
@Override
|
||||
public Boolean disableAppGroup(String id) {
|
||||
appGroupRequireNonNull(Long.valueOf(id));
|
||||
Integer count = appGroupRepository.updateAppGroupStatus(Long.valueOf(id), Boolean.FALSE);
|
||||
AuditContext.setTarget(Target.builder().id(id).type(TargetType.APP_GROUP).build());
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询并检查分组是否为空,非空返回
|
||||
*
|
||||
|
@ -193,38 +163,6 @@ public class AppGroupServiceImpl implements AppGroupService {
|
|||
return optional.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加应用
|
||||
*
|
||||
* @param appIds {@link String}
|
||||
* @param groupId {@link String}
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
@Override
|
||||
public Boolean addAssociation(String groupId, String[] appIds) {
|
||||
Optional<AppGroupEntity> optional = appGroupRepository.findById(Long.valueOf(groupId));
|
||||
//用户组不存在
|
||||
if (optional.isEmpty()) {
|
||||
AuditContext.setContent("操作失败,应用组不存在");
|
||||
log.warn(AuditContext.getContent());
|
||||
throw new TopIamException(AuditContext.getContent());
|
||||
}
|
||||
List<AppGroupAssociationEntity> list = new ArrayList<>();
|
||||
Lists.newArrayList(appIds).forEach(id -> {
|
||||
AppGroupAssociationEntity member = new AppGroupAssociationEntity();
|
||||
member.setGroupId(Long.valueOf(groupId));
|
||||
member.setAppId(Long.valueOf(id));
|
||||
list.add(member);
|
||||
});
|
||||
//添加
|
||||
appGroupAssociationRepository.saveAll(list);
|
||||
List<Target> targets = new ArrayList<>(Arrays.stream(appIds)
|
||||
.map(i -> Target.builder().id(i).type(TargetType.APPLICATION).build()).toList());
|
||||
targets.add(Target.builder().id(groupId).type(TargetType.APP_GROUP).build());
|
||||
AuditContext.setTarget(targets);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量移除应用
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue