feat: update

This commit is contained in:
zlg
2024-05-26 17:17:49 +08:00
parent c3a29cedca
commit 1154a53e9f
34 changed files with 956 additions and 223 deletions

View File

@@ -1,11 +1,14 @@
package com.schisandra.auth.application.config;
import cn.dev33.satoken.interceptor.SaInterceptor;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import java.util.List;
@@ -21,6 +24,7 @@ import java.util.List;
*/
@Configuration
public class GlobalConfig extends WebMvcConfigurationSupport {
@Override
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
super.configureMessageConverters(converters);

View File

@@ -5,9 +5,11 @@ import com.google.common.base.Preconditions;
import com.schisandra.auth.application.convert.SchisandraAuthUserDTOConverter;
import com.schisandra.auth.application.dto.SchisandraAuthUserDTO;
import com.schisandra.auth.common.entity.Result;
import com.schisandra.auth.common.redis.RedisUtil;
import com.schisandra.auth.domain.bo.SchisandraAuthUserBO;
import com.schisandra.auth.domain.service.SchisandraAuthUserDomainService;
import lombok.extern.slf4j.Slf4j;
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;
@@ -15,16 +17,20 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* controller
*
* @author landaiqing
* @since 2024-05-23 20:00:28
* @Classname SchisandraAuthUserController
* @BelongsProject: schisandra-cloud-storage
* @BelongsPackage: com.schisandra.auth.application.controller
* @Author: schisandra
* @CreateTime: 2024-03-21 22:48
* @Description: AuthUserController层
* @Version: 1.0
*/
@RestController
@RequestMapping("/auth/")
@Slf4j
public class SchisandraAuthUserController {
@Resource
RedisUtil redisUtil;
@Resource
private SchisandraAuthUserDomainService schisandraAuthUserDomainService;
@@ -33,44 +39,48 @@ public class SchisandraAuthUserController {
*/
@RequestMapping("add")
public Result<Boolean> add(@RequestBody SchisandraAuthUserDTO schisandraAuthUserDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SchisandraAuthUserController.add.dto:{}", JSON.toJSONString(schisandraAuthUserDTO));
}
Preconditions.checkNotNull(schisandraAuthUserDTO.getId(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getUserName(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getNickName(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getEmail(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getPhone(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getPassword(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getGender(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getAvatar(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getStatus(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getIntroduce(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getExtJson(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getCreatedBy(), "创建人不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getCreatedTime(), "创建时间不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getUpdateBy(), "更新人不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getUpdateTime(), "更新时间不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getIsDeleted(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getBlog(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getLocation(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getCompany(), "不能为空");
SchisandraAuthUserBO SchisandraAuthUserBO = SchisandraAuthUserDTOConverter.INSTANCE.convertDTOToBO(schisandraAuthUserDTO);
return Result.ok(schisandraAuthUserDomainService.add(SchisandraAuthUserBO));
} catch (Exception e) {
log.error("SchisandraAuthUserController.register.error:{}", e.getMessage(), e);
return Result.fail("新增失败");
}
return Result.ok();
}
@PostMapping("register")
public Result register(@RequestBody SchisandraAuthUserDTO schisandraAuthUserDTO) {
if (log.isInfoEnabled()) {
log.info("UserController.register.dto:{}", JSON.toJSONString(schisandraAuthUserDTO));
}
if (redisUtil.exist("auth.phone." + schisandraAuthUserDTO.getPhone())) {
if (redisUtil.get("auth.phone." + schisandraAuthUserDTO.getPhone()) != schisandraAuthUserDTO.getActiveCode()) {
return Result.fail("验证码错误,请重新验证");
}
} else {
return Result.fail("验证码错误,请重新验证");
}
try {
SchisandraAuthUserBO authUserBO = SchisandraAuthUserDTOConverter.INSTANCE.convertDTOToBO(schisandraAuthUserDTO);
if (schisandraAuthUserDomainService.register(authUserBO)) {
return Result.fail("注册用户成功");
} else {
return Result.fail("注册用户失败");
}
} catch (Exception e) {
return Result.fail("注册用户失败");
}
}
@PostMapping("login")
public Result login(@RequestBody SchisandraAuthUserDTO schisandraAuthUserDTO) {
String EmailType = "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.[a-zA-Z0-9]{2,6}$";
Boolean s = EmailType.matches(schisandraAuthUserDTO.getEmail());
// return Result.ok(schisandraAuthUserDomainService.login(SchisandraAuthUserDTOConverter.INSTANCE.convertDTOToBO(schisandraAuthUserDTO)));
// return null;
return Result.ok(s);
}
/**
* 修改
*/
@RequestMapping("update")
public Result<Boolean> update(@RequestBody SchisandraAuthUserDTO schisandraAuthUserDTO) {
public Result update(@RequestBody SchisandraAuthUserDTO schisandraAuthUserDTO) {
try {
if (log.isInfoEnabled()) {
@@ -134,7 +144,8 @@ public class SchisandraAuthUserController {
Preconditions.checkNotNull(schisandraAuthUserDTO.getLocation(), "不能为空");
Preconditions.checkNotNull(schisandraAuthUserDTO.getCompany(), "不能为空");
SchisandraAuthUserBO schisandraAuthUserBO = SchisandraAuthUserDTOConverter.INSTANCE.convertDTOToBO(schisandraAuthUserDTO);
return Result.ok(schisandraAuthUserDomainService.delete(schisandraAuthUserBO));
//
return Result.ok();
} catch (Exception e) {
log.error("SchisandraAuthUserController.delete.error:{}", e.getMessage(), e);
return Result.fail("删除信息失败");

View File

@@ -0,0 +1,23 @@
package com.schisandra.auth.application.convert;
import com.schisandra.auth.application.dto.SchisandraAuthUserRoleDTO;
import com.schisandra.auth.domain.bo.SchisandraAuthUserRoleBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* dto转换器
*
* @author zlg
* @since 2024-05-25 18:05:40
*/
@Mapper
public interface SchisandraAuthUserRoleDTOConverter {
SchisandraAuthUserRoleDTOConverter INSTANCE = Mappers.getMapper(SchisandraAuthUserRoleDTOConverter.class);
SchisandraAuthUserRoleBO convertDTOToBO(SchisandraAuthUserRoleDTO schisandraAuthUserRoleDTO);
SchisandraAuthUserRoleDTO convertBOToDTO(SchisandraAuthUserRoleBO schisandraAuthUserRoleBO);
}

View File

@@ -109,5 +109,7 @@ public class SchisandraAuthUserDTO implements Serializable {
*/
private String company;
private String activeCode;
}

View File

@@ -0,0 +1,58 @@
package com.schisandra.auth.application.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* dto
*
* @author zlg
* @since 2024-05-25 18:05:40
*/
@Data
public class SchisandraAuthUserRoleDTO implements Serializable {
/**
*
*/
private Long id;
/**
*
*/
private Long userId;
/**
*
*/
private Long roleId;
/**
* 创建人
*/
private String createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人
*/
private String updateBy;
/**
* 更新时间
*/
private Date updateTime;
/**
*
*/
private Integer isDeleted;
}

View File

@@ -0,0 +1,58 @@
package com.schisandra.auth.domain.bo;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* bo
*
* @author zlg
* @since 2024-05-25 18:05:40
*/
@Data
public class SchisandraAuthUserRoleBO implements Serializable {
/**
*
*/
private Long id;
/**
*
*/
private Long userId;
/**
*
*/
private Long roleId;
/**
* 创建人
*/
private String createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人
*/
private String updateBy;
/**
* 更新时间
*/
private Date updateTime;
/**
*
*/
private Integer isDeleted;
}

View File

@@ -19,4 +19,6 @@ public interface SchisandraAuthUserBOConverter {
SchisandraAuthUser convertBOToEntity(SchisandraAuthUserBO schisandraAuthUserBO);
SchisandraAuthUserBO convertEntityToBO(SchisandraAuthUser schisandraAuthUser);
}

View File

@@ -0,0 +1,25 @@
package com.schisandra.auth.domain.convert;
import com.schisandra.auth.domain.bo.SchisandraAuthUserRoleBO;
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUserRole;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* bo转换器
*
* @author zlg
* @since 2024-05-25 18:05:40
*/
@Mapper
public interface SchisandraAuthUserRoleBOConverter {
SchisandraAuthUserRoleBOConverter INSTANCE = Mappers.getMapper(SchisandraAuthUserRoleBOConverter.class);
SchisandraAuthUserRole convertBOToEntity(SchisandraAuthUserRoleBO schisandraAuthUserRoleBO);
SchisandraAuthUserRoleBO convertEntityToBO(SchisandraAuthUserRole schisandraAuthUserRole);
}

View File

@@ -1,28 +1,57 @@
package com.schisandra.auth.domain.service;
import com.schisandra.auth.domain.bo.SchisandraAuthUserBO;
/**
* 领域service
* 用户领域service
*
* @author landaiqing
* @since 2024-05-23 20:00:28
* @author schisandra
* @date 2024/3/21
*/
public interface SchisandraAuthUserDomainService {
/**
* 添加 信息
*/
Boolean add(SchisandraAuthUserBO schisandraAuthUserBO);
/**
* 更新 信息
* @description 用户注册
* @param schisandraAuthUserBO
* @return java.lang.Boolean
* @author zlg
* @date 2024/3/21 23:14
*/
Boolean update(SchisandraAuthUserBO schisandraAuthUserBO);
Boolean register(SchisandraAuthUserBO schisandraAuthUserBO);
SchisandraAuthUserBO login(SchisandraAuthUserBO schisandraAuthUserBO);
/**
* 删除 信息
* @description 更新用户信息
* @param schisandraAuthUserBO
* @return java.lang.Object
* @author schisandra
* @date 2024/3/21 23:14
*/
Boolean delete(SchisandraAuthUserBO schisandraAuthUserBO);
Object update(SchisandraAuthUserBO schisandraAuthUserBO);
/**
* @description 查询用户信息
* @param schisandraAuthUserBO
* @author msz
* @return com.schisandra.auth.infra.basic.entity.SchisandraAuthUser
*/
SchisandraAuthUserBO queryById(SchisandraAuthUserBO schisandraAuthUserBO);
/**
* @description 添加用户信息
* @param schisandraAuthUserBO
* @author msz
* @return java.lang.object
*/
Object insert(SchisandraAuthUserBO schisandraAuthUserBO);
/**
* @description 删除用户(物理)
* @param id
* @author msz
* @return java.lang.object
*/
Object deleteById(Long id);
}

View File

@@ -0,0 +1,30 @@
package com.schisandra.auth.domain.service;
import com.schisandra.auth.domain.bo.SchisandraAuthUserRoleBO;
/**
* 领域service
*
* @author zlg
* @since 2024-05-25 18:05:40
*/
public interface SchisandraAuthUserRoleDomainService {
/**
* 添加 信息
*/
Boolean add(SchisandraAuthUserRoleBO schisandraAuthUserRoleBO);
/**
* 更新 信息
*/
Boolean update(SchisandraAuthUserRoleBO schisandraAuthUserRoleBO);
/**
* 删除 信息
*/
Boolean delete(SchisandraAuthUserRoleBO schisandraAuthUserRoleBO);
}

View File

@@ -1,49 +1,110 @@
package com.schisandra.auth.domain.service.impl;
import com.schisandra.auth.common.enums.IsDeletedFlagEnum;
import com.schisandra.auth.domain.bo.SchisandraAuthUserBO;
import com.schisandra.auth.domain.bo.SchisandraAuthUserRoleBO;
import com.schisandra.auth.domain.convert.SchisandraAuthUserBOConverter;
import com.schisandra.auth.domain.convert.SchisandraAuthUserRoleBOConverter;
import com.schisandra.auth.domain.service.SchisandraAuthUserDomainService;
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUser;
import com.schisandra.auth.infra.basic.service.SchisandraAuthUserRoleService;
import com.schisandra.auth.infra.basic.service.SchisandraAuthUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* 领域service实现了
*
* @author landaiqing
* @since 2024-05-23 20:00:28
*/
@Service
@Slf4j
public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDomainService {
@Resource
private SchisandraAuthUserService schisandraAuthUserService;
@Resource
private SchisandraAuthUserRoleService schisandraAuthUserRoleService;
/**
* @description: 注册用户
* @param: [schisandraAuthUserBO]
* @return: com.schisandra.auth.domain.bo.SchisandraAuthUserBO
* @author zlg
* @date: 2024/5/14 20:59
*/
@Override
public Boolean register(SchisandraAuthUserBO schisandraAuthUserBO) {
SchisandraAuthUser schisandraAuthUser = schisandraAuthUserService.queryByPhone(schisandraAuthUserBO.getPhone());
if (schisandraAuthUser != null) {
return false;
} else {
SchisandraAuthUser schisandraAuthUser1 = SchisandraAuthUserBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserBO);
if (schisandraAuthUserService.insert(schisandraAuthUser1)){
SchisandraAuthUserRoleBO schisandraAuthUserRoleBO = new SchisandraAuthUserRoleBO();
schisandraAuthUserRoleBO.setUserId(schisandraAuthUserService.queryByPhone(schisandraAuthUserBO.getPhone()).getId());
schisandraAuthUserRoleBO.setRoleId(1L);
return schisandraAuthUserRoleService.insert(SchisandraAuthUserRoleBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserRoleBO))>1;
}else {
return false;
}
}
}
@Override
public Boolean add(SchisandraAuthUserBO schisandraAuthUserBO) {
public SchisandraAuthUserBO login(SchisandraAuthUserBO schisandraAuthUserBO) {
return null;
}
/**
* @param schisandraAuthUserBO
* @return java.lang.Object
* @description 更新用户信息
* @author schisandra
* @date 2024/3/21 23:14
*/
@Override
public Object update(SchisandraAuthUserBO schisandraAuthUserBO) {
SchisandraAuthUser schisandraAuthUser = SchisandraAuthUserBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserBO);
schisandraAuthUser.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
return schisandraAuthUserService.insert(schisandraAuthUser) > 0;
Integer count = schisandraAuthUserService.update(schisandraAuthUser);
return count > 0;
}
/**
* @param schisandraAuthUserBO
* @return
* @description 查询用户信息
* @author msz
* @date 2024/4/3 22:10
*/
@Override
public Boolean update(SchisandraAuthUserBO schisandraAuthUserBO) {
public SchisandraAuthUserBO queryById(SchisandraAuthUserBO schisandraAuthUserBO) {
SchisandraAuthUser schisandraAuthUser = schisandraAuthUserService.queryById(schisandraAuthUserBO.getId());
SchisandraAuthUserBO schisandraAuthUserBO1 = SchisandraAuthUserBOConverter.INSTANCE.convertEntityToBO(schisandraAuthUser);
return schisandraAuthUserBO1;
}
/**
* @param schisandraAuthUserBO
* @return java.lang.Object
* @description 添加用户信息
* @author msz
* @date 2024/4/3 22:17
*/
@Override
public Object insert(SchisandraAuthUserBO schisandraAuthUserBO) {
SchisandraAuthUser schisandraAuthUser = SchisandraAuthUserBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserBO);
return schisandraAuthUserService.update(schisandraAuthUser) > 0;
return schisandraAuthUserService.insert(schisandraAuthUser);
}
/**
* @param id
* @return java.lang.Object
* @description 添加用户信息
* @author msz
* @date 2024/4/3 22:30
*/
@Override
public Boolean delete(SchisandraAuthUserBO schisandraAuthUserBO) {
SchisandraAuthUser schisandraAuthUser = new SchisandraAuthUser();
schisandraAuthUser.setId(schisandraAuthUserBO.getId());
schisandraAuthUser.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
return schisandraAuthUserService.update(schisandraAuthUser) > 0;
public Object deleteById(Long id) {
boolean flag = schisandraAuthUserService.deleteById(id);
return flag;
}
}

View File

@@ -0,0 +1,48 @@
package com.schisandra.auth.domain.service.impl;
import com.schisandra.auth.common.enums.IsDeletedFlagEnum;
import com.schisandra.auth.domain.bo.SchisandraAuthUserRoleBO;
import com.schisandra.auth.domain.convert.SchisandraAuthUserRoleBOConverter;
import com.schisandra.auth.domain.service.SchisandraAuthUserRoleDomainService;
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUserRole;
import com.schisandra.auth.infra.basic.service.SchisandraAuthUserRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* 领域service实现了
*
* @author zlg
* @since 2024-05-25 18:05:40
*/
@Service
@Slf4j
public class SchisandraAuthUserRoleDomainServiceImpl implements SchisandraAuthUserRoleDomainService {
@Resource
private SchisandraAuthUserRoleService schisandraAuthUserRoleService;
@Override
public Boolean add(SchisandraAuthUserRoleBO schisandraAuthUserRoleBO) {
SchisandraAuthUserRole schisandraAuthUserRole = SchisandraAuthUserRoleBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserRoleBO);
schisandraAuthUserRole.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
return schisandraAuthUserRoleService.insert(schisandraAuthUserRole) > 0;
}
@Override
public Boolean update(SchisandraAuthUserRoleBO schisandraAuthUserRoleBO) {
SchisandraAuthUserRole schisandraAuthUserRole = SchisandraAuthUserRoleBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserRoleBO);
return schisandraAuthUserRoleService.update(schisandraAuthUserRole) > 0;
}
@Override
public Boolean delete(SchisandraAuthUserRoleBO schisandraAuthUserRoleBO) {
SchisandraAuthUserRole schisandraAuthUserRole = new SchisandraAuthUserRole();
schisandraAuthUserRole.setId(schisandraAuthUserRoleBO.getId());
schisandraAuthUserRole.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
return schisandraAuthUserRoleService.update(schisandraAuthUserRole) > 0;
}
}

View File

@@ -0,0 +1,17 @@
package com.schisandra.auth.infra.basic.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUserRole;
import org.springframework.stereotype.Repository;
/**
* 表数据库访问层
*
* @author zlg
* @since 2024-05-25 18:05:40
*/
@Repository
public interface SchisandraAuthUserRoleDao extends BaseMapper<SchisandraAuthUserRole> {
}

View File

@@ -0,0 +1,71 @@
package com.schisandra.auth.infra.basic.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 实体类
*
* @author zlg
* @since 2024-05-25 18:05:40
*/
@Data
@TableName("schisandra_auth_user_role")
public class SchisandraAuthUserRole implements Serializable {
/**
*
*/
@TableId(value = "`id`", type = IdType.AUTO)
private Long id;
/**
*
*/
@TableField("`user_id`")
private Long userId;
/**
*
*/
@TableField("`role_id`")
private Long roleId;
/**
* 创建人
*/
@TableField("`created_by`")
private String createdBy;
/**
* 创建时间
*/
@TableField("`created_time`")
private Date createdTime;
/**
* 更新人
*/
@TableField("`update_by`")
private String updateBy;
/**
* 更新时间
*/
@TableField("`update_time`")
private Date updateTime;
/**
*
*/
@TableField("`is_deleted`")
private Integer isDeleted;
}

View File

@@ -0,0 +1,50 @@
package com.schisandra.auth.infra.basic.service;
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUserRole;
/**
* 表服务接口
*
* @author zlg
* @since 2024-05-25 18:05:40
*/
public interface SchisandraAuthUserRoleService {
/**
* 通过ID查询单条数据
*
* @param id 主键
* @return 实例对象
*/
SchisandraAuthUserRole queryById(Long id);
/**
* 新增数据
*
* @param schisandraAuthUserRole 实例对象
* @return 实例对象
*/
int insert(SchisandraAuthUserRole schisandraAuthUserRole);
/**
* 修改数据
*
* @param schisandraAuthUserRole 实例对象
* @return 实例对象
*/
int update(SchisandraAuthUserRole schisandraAuthUserRole);
/**
* 通过主键删除数据
*
* @param id 主键
* @return 是否成功
*/
boolean deleteById(Long id);
/**
* 根据条件查询角色
*/
SchisandraAuthUserRole queryByCondition(SchisandraAuthUserRole schisandraAuthUserRole);
}

View File

@@ -3,13 +3,15 @@ package com.schisandra.auth.infra.basic.service;
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUser;
/**
* 表服务接口
* (SchisandraAuthUser)表服务接口
*
* @author landaiqing
* @since 2024-05-23 20:00:28
* @author schisandra
* @since 2024-03-21 20:15:44
*/
public interface SchisandraAuthUserService {
SchisandraAuthUser queryByPhone(String phone);
/**
* 通过ID查询单条数据
*
@@ -24,7 +26,7 @@ public interface SchisandraAuthUserService {
* @param schisandraAuthUser 实例对象
* @return 实例对象
*/
int insert(SchisandraAuthUser schisandraAuthUser);
Boolean insert(SchisandraAuthUser schisandraAuthUser);
/**
* 修改数据

View File

@@ -0,0 +1,93 @@
package com.schisandra.auth.infra.basic.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.schisandra.auth.infra.basic.dao.SchisandraAuthUserRoleDao;
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUserRole;
import com.schisandra.auth.infra.basic.service.SchisandraAuthUserRoleService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Objects;
/**
* 表服务实现类
*
* @author zlg
* @since 2024-05-25 18:05:40
*/
@Service("SchisandraAuthUserRoleService")
public class SchisandraAuthUserRoleServiceImpl implements SchisandraAuthUserRoleService {
@Resource
private SchisandraAuthUserRoleDao schisandraAuthUserRoleDao;
/**
* 通过ID查询单条数据
*
* @param id 主键
* @return 实例对象
*/
@Override
public SchisandraAuthUserRole queryById(Long id) {
return this.schisandraAuthUserRoleDao.selectById(id);
}
/**
* 新增数据
*
* @param schisandraAuthUserRole 实例对象
* @return 实例对象
*/
@Override
public int insert(SchisandraAuthUserRole schisandraAuthUserRole) {
return this.schisandraAuthUserRoleDao.insert(schisandraAuthUserRole);
}
/**
* 修改数据
*
* @param schisandraAuthUserRole 实例对象
* @return 实例对象
*/
@Override
public int update(SchisandraAuthUserRole schisandraAuthUserRole) {
return this.schisandraAuthUserRoleDao.updateById(schisandraAuthUserRole);
}
/**
* 通过主键删除数据
*
* @param id 主键
* @return 是否成功
*/
@Override
public boolean deleteById(Long id) {
return this.schisandraAuthUserRoleDao.deleteById(id) > 0;
}
/**
* 条件查询
*
* @param schisandraAuthUserRole 条件
* @return 实例对象
*/
@Override
public SchisandraAuthUserRole queryByCondition(SchisandraAuthUserRole schisandraAuthUserRole) {
LambdaQueryWrapper<SchisandraAuthUserRole> queryWrapper = Wrappers.<SchisandraAuthUserRole>lambdaQuery()
.eq(Objects.nonNull(schisandraAuthUserRole.getId()), SchisandraAuthUserRole::getId, schisandraAuthUserRole.getId())
.eq(Objects.nonNull(schisandraAuthUserRole.getUserId()), SchisandraAuthUserRole::getUserId, schisandraAuthUserRole.getUserId())
.eq(Objects.nonNull(schisandraAuthUserRole.getRoleId()), SchisandraAuthUserRole::getRoleId, schisandraAuthUserRole.getRoleId())
.eq(Objects.nonNull(schisandraAuthUserRole.getCreatedBy()), SchisandraAuthUserRole::getCreatedBy, schisandraAuthUserRole.getCreatedBy())
.eq(Objects.nonNull(schisandraAuthUserRole.getCreatedTime()), SchisandraAuthUserRole::getCreatedTime, schisandraAuthUserRole.getCreatedTime())
.eq(Objects.nonNull(schisandraAuthUserRole.getUpdateBy()), SchisandraAuthUserRole::getUpdateBy, schisandraAuthUserRole.getUpdateBy())
.eq(Objects.nonNull(schisandraAuthUserRole.getUpdateTime()), SchisandraAuthUserRole::getUpdateTime, schisandraAuthUserRole.getUpdateTime())
.eq(Objects.nonNull(schisandraAuthUserRole.getIsDeleted()), SchisandraAuthUserRole::getIsDeleted, schisandraAuthUserRole.getIsDeleted())
;
return schisandraAuthUserRoleDao.selectOne(queryWrapper);
}
}

View File

@@ -1,6 +1,5 @@
package com.schisandra.auth.infra.basic.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.schisandra.auth.infra.basic.dao.SchisandraAuthUserDao;
@@ -12,10 +11,10 @@ import javax.annotation.Resource;
import java.util.Objects;
/**
* 表服务实现类
* (SchisandraAuthUser)表服务实现类
*
* @author landaiqing
* @since 2024-05-23 20:00:28
* @author schisandra
* @since 2024-03-21 20:15:44
*/
@Service("SchisandraAuthUserService")
public class SchisandraAuthUserServiceImpl implements SchisandraAuthUserService {
@@ -23,6 +22,11 @@ public class SchisandraAuthUserServiceImpl implements SchisandraAuthUserService
@Resource
private SchisandraAuthUserDao schisandraAuthUserDao;
@Override
public SchisandraAuthUser queryByPhone(String phone) {
return null;
}
/**
* 通过ID查询单条数据
*
@@ -41,8 +45,9 @@ public class SchisandraAuthUserServiceImpl implements SchisandraAuthUserService
* @return 实例对象
*/
@Override
public int insert(SchisandraAuthUser schisandraAuthUser) {
return this.schisandraAuthUserDao.insert(schisandraAuthUser);
public Boolean insert(SchisandraAuthUser schisandraAuthUser) {
return this.schisandraAuthUserDao.insert(schisandraAuthUser)>0;
}
/**

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.schisandra.auth.infra.basic.dao.SchisandraAuthUserRoleDao">
<resultMap id="BaseResultMap" type="com.schisandra.auth.infra.basic.entity.SchisandraAuthUserRole">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="user_id" jdbcType="BIGINT" property="userId"/>
<result column="role_id" jdbcType="BIGINT" property="roleId"/>
<result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
</resultMap>
</mapper>

View File

@@ -39,6 +39,7 @@ public class LoginFilter implements GlobalFilter {
if (StringUtils.isEmpty(loginId)) {
throw new Exception("未获取到用户信息");
}
mutate.header("loginId", loginId);
return chain.filter(exchange.mutate().request(mutate.build()).build());

View File

@@ -0,0 +1,67 @@
package com.schisandra.oss.application.aspect;
import com.schisandra.oss.application.dto.SchisandraOssMinioDTO;
import com.schisandra.oss.common.redis.RedisUtil;
import com.schisandra.oss.common.utils.AESUtils;
import com.schisandra.oss.common.utils.RSAUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
@Slf4j
@Aspect
@Component
public class DecryptAspect {
@Autowired
RedisUtil redisUtil;
private final String authSecretKeyPrefix = "auth.SecretKey";
/**
* @description: 解密切面
* @param: []
* @return: void
* @author zlg
* @date: 2024/5/23 19:53
*/
@Pointcut("@annotation(com.schisandra.oss.application.aspect.NeedDecrypt)")
public void pointCut() {
}
@Around("pointCut()")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
//解密
Object result = decrypt(joinPoint);
return result;
}
public Object decrypt(ProceedingJoinPoint joinPoint) {
Object result = null;
Object []objects=null;
try {
objects = joinPoint.getArgs();
Object obj = joinPoint.proceed();
SchisandraOssMinioDTO schisandraOssMinioDTO=(SchisandraOssMinioDTO) obj;
String prefix = redisUtil.buildKey(authSecretKeyPrefix, String.valueOf(objects[0]));
if (obj!= null) {
HashMap<String,String> map=redisUtil.getJson(prefix);
String key=RSAUtils.decryptByPrivate(map.get("AESKey"),map.get("privateKey"));
// AESUtils.decrypt(objects.toString(),key);
// schisandraOssMinioDTO.setUserId(Long.valueOf(AESUtils.decrypt(String.valueOf(schisandraOssMinioDTO.getUserId()),key)));
schisandraOssMinioDTO.setEndpoint(AESUtils.decrypt(schisandraOssMinioDTO.getEndpoint(),key));
schisandraOssMinioDTO.setSecretKey(AESUtils.decrypt(schisandraOssMinioDTO.getSecretKey(),key));
schisandraOssMinioDTO.setAccessKey(AESUtils.decrypt(schisandraOssMinioDTO.getAccessKey(),key));
result=schisandraOssMinioDTO;
}
} catch (Throwable e) {
e.printStackTrace();
}
return result;
}
}

View File

@@ -0,0 +1,62 @@
package com.schisandra.oss.application.aspect;
import com.schisandra.oss.application.dto.SchisandraOssMinioDTO;
import com.schisandra.oss.common.redis.RedisUtil;
import com.schisandra.oss.common.utils.AESUtils;
import com.schisandra.oss.common.utils.RSAUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@Aspect
@Component
public class EncryptAspect {
@Autowired
private RedisUtil redisUtil;
private final String authSecretKeyPrefix = "auth.SecretKey";
@Pointcut("@annotation(com.schisandra.oss.application.aspect.NeedEncrypt)")
public void pointCut() {
}
@Around("pointCut()")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
//加密
encrypt(joinPoint);
return joinPoint.proceed();
}
public void encrypt(ProceedingJoinPoint joinPoint) {
Object[] objects = null;
try {
objects = joinPoint.getArgs();
SchisandraOssMinioDTO schisandraOssMinioDTO= (SchisandraOssMinioDTO) objects[0];
String prefix = redisUtil.buildKey(authSecretKeyPrefix, String.valueOf(schisandraOssMinioDTO.getUserId()));
String key = AESUtils.getKey();
Map<String, String> map = new HashMap<>();
map = RSAUtils.getPriKeyAndPubKey();
String publicKey = map.get("publicKey");
if (objects.length != 0) {
schisandraOssMinioDTO.setEndpoint(AESUtils.encrypt(schisandraOssMinioDTO.getEndpoint(), key));
schisandraOssMinioDTO.setSecretKey(AESUtils.encrypt(schisandraOssMinioDTO.getSecretKey(), key));
schisandraOssMinioDTO.setAccessKey(AESUtils.encrypt(schisandraOssMinioDTO.getAccessKey(), key));
objects[0] = schisandraOssMinioDTO;
String AESkey = RSAUtils.encryptByPublic(key, publicKey);
map.put("AESKey", AESkey);
redisUtil.setJson(prefix, map);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,11 @@
package com.schisandra.oss.application.aspect;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.FIELD,ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface EncryptField {
}

View File

@@ -0,0 +1,11 @@
package com.schisandra.oss.application.aspect;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface NeedDecrypt {
}

View File

@@ -0,0 +1,11 @@
package com.schisandra.oss.application.aspect;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface NeedEncrypt {
}

View File

@@ -3,6 +3,8 @@ package com.schisandra.oss.application.controller;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Preconditions;
import com.schisandra.oss.application.aspect.NeedDecrypt;
import com.schisandra.oss.application.aspect.NeedEncrypt;
import com.schisandra.oss.application.convert.SchisandraOssMinioDTOConverter;
import com.schisandra.oss.application.dto.SchisandraOssMinioDTO;
import com.schisandra.oss.application.oss.core.minio.MinioOssClient;
@@ -27,6 +29,8 @@ import java.util.List;
@RequestMapping("/oss/minio/")
@Slf4j
public class SchisandraOssMinioController {
@Resource
MinioOssClient minioOssClient;
@Resource
private SchisandraOssMinioDomainService schisandraOssMinioDomainService;
@@ -47,6 +51,7 @@ public class SchisandraOssMinioController {
*/
@PostMapping("init")
public void initMinio(@RequestParam String userId) {
if (log.isInfoEnabled()) {
log.info("SchisandraOssMinioController.init.userId:{}", userId);
}
@@ -60,24 +65,29 @@ public class SchisandraOssMinioController {
}
minioOssConfiguration.minioOssClient(userId);
log.info("用户: " + userId + "-> minio 初始化完成!");
redisUtil.set(key, "true");
} catch (Exception e) {
log.error("用户: " + userId + "-> minio 初始化失败!", e.getMessage(), e);
}
}
@NeedDecrypt
@PostMapping("get")
public SchisandraOssMinioDTO getMinioOss(@RequestParam String userId) {
return SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTO(schisandraOssMinioDomainService.getMinioConfig(Long.valueOf(userId)));
}
/**
* 新增
*/
@PostMapping("add")
@NeedEncrypt
@RequestMapping("add")
public Result<Boolean> addMinioOss(@RequestBody SchisandraOssMinioDTO schisandraOssMinioDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SchisandraOssMinioController.add.dto:{}", JSON.toJSONString(schisandraOssMinioDTO));
}
parameterCheck(schisandraOssMinioDTO);
// parameterCheck(schisandraOssMinioDTO);
SchisandraOssMinioBO SchisandraOssMinioBO = SchisandraOssMinioDTOConverter.INSTANCE.convertDTOToBO(schisandraOssMinioDTO);
return Result.ok(schisandraOssMinioDomainService.add(SchisandraOssMinioBO));
} catch (Exception e) {
@@ -92,6 +102,7 @@ public class SchisandraOssMinioController {
*/
@PostMapping("update")
public Result<Boolean> updateMinioOss(@RequestBody SchisandraOssMinioDTO schisandraOssMinioDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SchisandraOssMinioController.update.dto:{}", JSON.toJSONString(schisandraOssMinioDTO));

View File

@@ -1,5 +1,6 @@
package com.schisandra.oss.application.dto;
import com.schisandra.oss.application.aspect.EncryptField;
import lombok.Data;
import java.io.Serializable;
@@ -22,21 +23,25 @@ public class SchisandraOssMinioDTO implements Serializable {
/**
*
*/
@EncryptField
private Long userId;
/**
*
*/
@EncryptField
private String endpoint;
/**
*
*/
@EncryptField
private String accessKey;
/**
*
*/
@EncryptField
private String secretKey;
/**

View File

@@ -1,6 +1,7 @@
package com.schisandra.oss.application.oss.core.minio;
import cn.hutool.extra.spring.SpringUtil;
import com.schisandra.oss.application.aspect.NeedDecrypt;
import com.schisandra.oss.application.convert.SchisandraOssMinioDTOConverter;
import com.schisandra.oss.application.dto.SchisandraOssMinioDTO;
import com.schisandra.oss.application.oss.core.StandardOssClient;
@@ -13,7 +14,6 @@ import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import org.apache.commons.lang3.ObjectUtils;
import org.jetbrains.annotations.Nullable;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@@ -31,12 +31,14 @@ public class MinioOssConfiguration {
@Resource
private RedisUtil redisUtil;
@Resource
MinioOssConfiguration minioOssConfiguration;
@Resource
private SchisandraOssMinioDomainService schisandraOssMinioDomainService;
public StandardOssClient minioOssClient(String userId) {
SchisandraOssMinioDTO minio = getSchisandraOssMinioDTO(userId);
SchisandraOssMinioDTO minio = minioOssConfiguration.getSchisandraOssMinioDTO(userId);
if (minio == null) return null;
MinioOssConfig minioOssConfig = new MinioOssConfig();
minioOssConfig.setBasePath(minio.getBasePath());
@@ -63,8 +65,10 @@ public class MinioOssConfiguration {
}
@Nullable
private SchisandraOssMinioDTO getSchisandraOssMinioDTO(String userId) {
@NeedDecrypt
public SchisandraOssMinioDTO getSchisandraOssMinioDTO(String userId) {
CompletableFuture<SchisandraOssMinioDTO> futurePrice = CompletableFuture.supplyAsync(() -> {
SchisandraOssMinioBO minioBO = schisandraOssMinioDomainService.getMinioConfig(Long.valueOf(userId));
SchisandraOssMinioDTO minioDTO = SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTO(minioBO);

View File

@@ -1,10 +1,12 @@
package com.schisandra.oss.common.redis;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -53,6 +55,14 @@ public class RedisUtil {
redisTemplate.opsForValue().set(key, value);
}
public void setJson(String key, Object value) {
redisTemplate.opsForValue().set(key, value);
}
public HashMap<String, String> getJson(String key) {
return (HashMap<String, String>) redisTemplate.opsForValue().get(key);
}
/**
* set(带过期)
*/

View File

@@ -1,19 +1,13 @@
package com.schisandra.oss.common.utils;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.AsymmetricAlgorithm;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import java.io.ByteArrayOutputStream;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.HashMap;
/**
* @ClassName RSAUtils
@@ -24,149 +18,68 @@ import java.util.Map;
public class RSAUtils {
/**
* 加密算法RSA
* 公钥加密(解密就要用到对应的私钥)
*
* @param msg 明文信息
* @param pubKey 公钥,用来加密明文
* @return
*/
private static final String KEY_ALGORITHM = "RSA";
/**
* 算法名称/加密模式/数据填充方式
* 默认RSA/ECB/PKCS1Padding
*/
private static final String ALGORITHMS = "RSA/ECB/PKCS1Padding";
/**
* RSA最大加密明文大小
*/
private static final int MAX_ENCRYPT_BLOCK = 245;
/**
* RSA最大解密密文大小
*/
private static final int MAX_DECRYPT_BLOCK = 256;
/**
* RSA 位数 如果采用2048 上面最大加密和最大解密则须填写: 245 256
*/
private static final int INITIALIZE_LENGTH = 2048;
/**
* 后端RSA的密钥对(公钥和私钥)Map由静态代码块赋值
*/
private static final Map<String, String> map = new LinkedHashMap<>(2);
/**
* 生成密钥对(公钥和私钥)
*/
public static Map<String,String> genKeyPair() throws Exception {
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM);
keyPairGen.initialize(INITIALIZE_LENGTH);
KeyPair keyPair = keyPairGen.generateKeyPair();
// 获取公钥
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
// 获取私钥
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
// 得到公钥字符串
String publicKeyString = Base64.encodeBase64String(publicKey.getEncoded());
// 得到私钥字符串
String privateKeyString = Base64.encodeBase64String((privateKey.getEncoded()));
map.put("publicKey",publicKeyString);
map.put("privateKey",privateKeyString);
return map;
}
public static String getPrivateKey(){
return map.get("privateKey");
}
public static String getPublicKey(){
return map.get("publicKey");
}
/**
* RSA私钥解密
* @param data BASE64编码过的密文
* @param privateKey 私钥(BASE64编码)
* @return utf-8编码的明文
*/
public static byte[] decryptByPrivateKey(byte[] data, String privateKey) throws Exception {
//base64格式的key字符串转Key对象
Key privateK = KeyFactory.getInstance(KEY_ALGORITHM).generatePrivate(new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey)));
Cipher cipher = Cipher.getInstance(ALGORITHMS);
cipher.init(Cipher.DECRYPT_MODE, privateK);
//分段进行解密操作
return encryptAndDecryptOfSubsection(data, cipher, MAX_DECRYPT_BLOCK);
public static String encryptByPublic(String msg, String pubKey) {
RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB_PKCS1.getValue(), null, pubKey);
return rsa.encryptBase64(msg, KeyType.PublicKey);
}
/**
* RSA公钥加
* @param data BASE64编码过的密文
* @param publicKey 公钥(BASE64编码)
* @return utf-8编码的明
* 私钥解
*
* @param encryptMsg 公钥加密的密文
* @param priKey 私钥,用来解密密
* @return
*/
public static byte[] encryptByPublicKey(byte[] data, String publicKey) throws Exception {
//base64格式的key字符串转Key对象
Key publicK = KeyFactory.getInstance(KEY_ALGORITHM).generatePublic(new X509EncodedKeySpec(Base64.decodeBase64(publicKey)));
Cipher cipher = Cipher.getInstance(ALGORITHMS);
cipher.init(Cipher.ENCRYPT_MODE, publicK);
//分段进行加密操作
return encryptAndDecryptOfSubsection(data, cipher, MAX_ENCRYPT_BLOCK);
public static String decryptByPrivate(String encryptMsg, String priKey) {
RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB_PKCS1.getValue(), priKey, null);
return rsa.decryptStr(encryptMsg, KeyType.PrivateKey);
}
/**
* RSA公钥解密
* @param data BASE64编码过的密文
* @param publicKey RSA公钥
* @return utf-8编码的明文
* 私钥加密(解密就要用到对应的公钥)
*
* @param msg 明文信息
* @param priKey 私钥,用来加密明文
* @return
*/
public static byte[] pubKeyDec(byte[] data, String publicKey) throws Exception {
//base64格式的key字符串转Key对象
Key privateK = KeyFactory.getInstance(KEY_ALGORITHM).generatePublic(new X509EncodedKeySpec(Base64.decodeBase64(publicKey)));
Cipher cipher = Cipher.getInstance(ALGORITHMS);
cipher.init(Cipher.DECRYPT_MODE, privateK);
//分段进行解密操作
return encryptAndDecryptOfSubsection(data, cipher, MAX_DECRYPT_BLOCK);
public static String encryptByPrivate(String msg, String priKey) {
RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB_PKCS1.getValue(), priKey, null);
return rsa.encryptBase64(msg, KeyType.PrivateKey);
}
/**
* RSA私钥加
* @param data 待加密的明文
* @param privateKey RSA私钥
* @return 经BASE64编码后的密文
* 公钥解
*
* @param encryptMsg 密文
* @param pubKey 公钥,用来解密
* @return
*/
public static byte[] privKeyEnc(byte[] data, String privateKey) throws Exception {
//base64格式的key字符串转Key对象
Key publicK = KeyFactory.getInstance(KEY_ALGORITHM).generatePrivate(new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey)));
Cipher cipher = Cipher.getInstance(ALGORITHMS);
cipher.init(Cipher.ENCRYPT_MODE, publicK);
//分段进行加密操作
return encryptAndDecryptOfSubsection(data, cipher, MAX_ENCRYPT_BLOCK);
public static String decryptByPublic(String encryptMsg, String pubKey) {
RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB_PKCS1.getValue(), null, pubKey);
return rsa.decryptStr(encryptMsg, KeyType.PublicKey);
}
/**
* 分段进行加密、解密操作
* 获取公私钥集合
*
* @return
*/
private static byte[] encryptAndDecryptOfSubsection(byte[] data, Cipher cipher, int encryptBlock) throws Exception {
int inputLen = data.length;
ByteArrayOutputStream out = new ByteArrayOutputStream();
int offSet = 0;
byte[] cache;
int i = 0;
// 对数据分段加密
while (inputLen - offSet > 0) {
if (inputLen - offSet > encryptBlock) {
cache = cipher.doFinal(data, offSet, encryptBlock);
} else {
cache = cipher.doFinal(data, offSet, inputLen - offSet);
}
out.write(cache, 0, cache.length);
i++;
offSet = i * encryptBlock;
}
out.close();
return out.toByteArray();
public static HashMap<String,String> getPriKeyAndPubKey() {
KeyPair pair = SecureUtil.generateKeyPair("RSA");
String privateKey = Base64.encodeBase64String(pair.getPrivate().getEncoded());
String publicKey = Base64.encodeBase64String(pair.getPublic().getEncoded());
HashMap<String,String> keys = new HashMap<>();
keys.put("privateKey",privateKey);
keys.put("publicKey",publicKey);
return keys;
}
}

View File

@@ -49,5 +49,13 @@
<artifactId>schisandra-cloud-storage-oss-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.6</version>
</dependency>
</dependencies>
</project>

View File

@@ -13,6 +13,7 @@ import java.util.List;
*/
public interface SchisandraOssMinioService {
/**
* 通过ID查询单条数据
*

View File

@@ -3,10 +3,11 @@ package com.schisandra.oss.infra.basic.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.schisandra.oss.infra.basic.dao.SchisandraOssMinioDao;
import com.schisandra.oss.infra.basic.entity.SchisandraOssMinio;
import com.schisandra.oss.infra.basic.service.SchisandraOssMinioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -20,7 +21,10 @@ import java.util.Objects;
* @since 2024-05-14 19:47:04
*/
@Service("SchisandraOssMinioService")
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class SchisandraOssMinioServiceImpl implements SchisandraOssMinioService {
@Autowired
SchisandraOssMinioServiceImpl schisandraOssMinioService;
@Resource
private SchisandraOssMinioDao schisandraOssMinioDao;
@@ -55,7 +59,14 @@ public class SchisandraOssMinioServiceImpl implements SchisandraOssMinioService
*/
@Override
public int update(SchisandraOssMinio schisandraOssMinio) {
// ApplicationContext applicationContext=null;
// Service service=applicationContext.getBean(Service.class);
// final SchisandraOssMinioService bean=context.getBean(SchisandraOssMinioService.class);
// return bean.update(schisandraOssMinio);
return this.schisandraOssMinioDao.updateById(schisandraOssMinio);
// eById(schisandraOssMinio);
// return schisandraOssMinioDao.update(schisandraOssMinio);
}
/**

View File

@@ -4,6 +4,7 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
/**
* 存储微服务启动类
@@ -14,6 +15,7 @@ import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan("com.schisandra")
@MapperScan("com.schisandra.**.dao")
public class OssApplication {
public static void main(String[] args) {
SpringApplication.run(OssApplication.class);