mirror of https://gitee.com/topiam/eiam
Merge remote-tracking branch 'origin/master'
commit
0a1df68e5e
|
@ -1,94 +0,0 @@
|
|||
/*
|
||||
* eiam-audit - 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.audit.entity;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
import org.springframework.data.elasticsearch.annotations.Setting;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 审计elasticsearch实体
|
||||
*
|
||||
* @author TopIAM
|
||||
* Created by support@topiam.cn on 2022/10/13 23:22
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@Document(indexName = "#{@auditDynamicIndexName.getIndexName()}")
|
||||
@Setting(replicas = 0)
|
||||
public class AuditElasticSearchEntity implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 6589338521638519634L;
|
||||
|
||||
@Id
|
||||
@Field(type = FieldType.Keyword, name = "id")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* Request Id
|
||||
*/
|
||||
@Field(type = FieldType.Keyword, name = "request_id")
|
||||
private String requestId;
|
||||
|
||||
/**
|
||||
* Session Id
|
||||
*/
|
||||
@Field(type = FieldType.Keyword, name = "session_id")
|
||||
private String sessionId;
|
||||
|
||||
/**
|
||||
* 操作者
|
||||
*/
|
||||
@Field(type = FieldType.Object, name = "actor")
|
||||
private Actor actor;
|
||||
|
||||
/**
|
||||
* 事件
|
||||
*/
|
||||
@Field(type = FieldType.Object, name = "event")
|
||||
private Event event;
|
||||
|
||||
/**
|
||||
* 操作目标
|
||||
*/
|
||||
@Field(type = FieldType.Object, name = "target")
|
||||
private List<Target> targets;
|
||||
|
||||
/**
|
||||
* UserAgent
|
||||
*/
|
||||
@Field(type = FieldType.Object, name = "user_agent")
|
||||
private UserAgent userAgent;
|
||||
|
||||
/**
|
||||
* 地理位置
|
||||
*/
|
||||
@Field(type = FieldType.Object, name = "geo_location")
|
||||
private GeoLocation geoLocation;
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* eiam-audit - 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.audit.repository;
|
||||
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import cn.topiam.employee.audit.entity.AuditElasticSearchEntity;
|
||||
|
||||
/**
|
||||
* 行为审计repository
|
||||
*
|
||||
* @author TopIAM
|
||||
* Created by support@topiam.cn on 2021/9/11 22:32
|
||||
*/
|
||||
@Repository
|
||||
public interface AuditElasticSearchRepository extends
|
||||
ElasticsearchRepository<AuditElasticSearchEntity, String> {
|
||||
|
||||
}
|
|
@ -38,9 +38,7 @@ import com.google.common.collect.Lists;
|
|||
|
||||
import cn.topiam.employee.audit.controller.pojo.AuditListQuery;
|
||||
import cn.topiam.employee.audit.controller.pojo.AuditListResult;
|
||||
import cn.topiam.employee.audit.entity.Actor;
|
||||
import cn.topiam.employee.audit.entity.AuditElasticSearchEntity;
|
||||
import cn.topiam.employee.audit.entity.Event;
|
||||
import cn.topiam.employee.audit.entity.AuditEntity;
|
||||
import cn.topiam.employee.audit.entity.Target;
|
||||
import cn.topiam.employee.audit.enums.TargetType;
|
||||
import cn.topiam.employee.common.entity.account.OrganizationEntity;
|
||||
|
@ -93,27 +91,25 @@ public interface AuditDataConverter {
|
|||
* @param page {@link PageModel}
|
||||
* @return {@link Page}
|
||||
*/
|
||||
default Page<AuditListResult> searchHitsConvertToAuditListResult(SearchHits<AuditElasticSearchEntity> search,
|
||||
default Page<AuditListResult> searchHitsConvertToAuditListResult(SearchHits<AuditEntity> search,
|
||||
PageModel page) {
|
||||
List<AuditListResult> list = new ArrayList<>();
|
||||
//总记录数
|
||||
search.forEach(hit -> {
|
||||
AuditElasticSearchEntity content = hit.getContent();
|
||||
Event event = content.getEvent();
|
||||
AuditEntity content = hit.getContent();
|
||||
AuditListResult result = new AuditListResult();
|
||||
result.setId(content.getId());
|
||||
result.setEventStatus(event.getStatus());
|
||||
result.setEventType(event.getType().getDesc());
|
||||
result.setEventTime(event.getTime());
|
||||
result.setId(content.getId().toString());
|
||||
result.setEventStatus(content.getEventStatus());
|
||||
result.setEventType(content.getEventType().getDesc());
|
||||
result.setEventTime(content.getEventTime());
|
||||
//用户代理
|
||||
result.setUserAgent(content.getUserAgent());
|
||||
result.setGeoLocation(content.getGeoLocation());
|
||||
Actor actor = content.getActor();
|
||||
//用户ID
|
||||
result.setUserId(actor.getId());
|
||||
result.setUsername(getUsername(actor.getType(), actor.getId()));
|
||||
result.setUserId(content.getActorId());
|
||||
result.setUsername(getUsername(content.getActorType(), content.getActorId()));
|
||||
//用户类型
|
||||
result.setUserType(actor.getType().getType());
|
||||
result.setUserType(content.getActorType().getType());
|
||||
//操作对象
|
||||
if (Objects.nonNull(content.getTargets())) {
|
||||
for (Target target : content.getTargets()) {
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.springframework.util.CollectionUtils;
|
|||
import cn.topiam.employee.audit.controller.pojo.AuditListQuery;
|
||||
import cn.topiam.employee.audit.controller.pojo.AuditListResult;
|
||||
import cn.topiam.employee.audit.controller.pojo.DictResult;
|
||||
import cn.topiam.employee.audit.entity.AuditElasticSearchEntity;
|
||||
import cn.topiam.employee.audit.entity.AuditEntity;
|
||||
import cn.topiam.employee.audit.event.type.EventType;
|
||||
import cn.topiam.employee.audit.service.AuditService;
|
||||
import cn.topiam.employee.audit.service.converter.AuditDataConverter;
|
||||
|
@ -71,8 +71,8 @@ public class AuditServiceImpl implements AuditService {
|
|||
//查询入参转查询条件
|
||||
NativeQuery nsq = auditDataConverter.auditListRequestConvertToNativeQuery(query, page);
|
||||
//查询列表
|
||||
SearchHits<AuditElasticSearchEntity> search = elasticsearchTemplate.search(nsq,
|
||||
AuditElasticSearchEntity.class, IndexCoordinates
|
||||
SearchHits<AuditEntity> search = elasticsearchTemplate.search(nsq, AuditEntity.class,
|
||||
IndexCoordinates
|
||||
.of(getAuditIndexPrefix(supportProperties.getAudit().getIndexPrefix()) + "*"));
|
||||
//结果转返回结果
|
||||
return auditDataConverter.searchHitsConvertToAuditListResult(search, page);
|
||||
|
|
Loading…
Reference in New Issue