feat:用户实体审查完善
This commit is contained in:
parent
873880036b
commit
703049fbec
@ -1,21 +1,19 @@
|
|||||||
package com.flyfish.framework.service;
|
package com.flyfish.framework.service;
|
||||||
|
|
||||||
import com.flyfish.framework.domain.base.Qo;
|
import com.flyfish.framework.auditor.BeanAuditor;
|
||||||
import com.flyfish.framework.domain.po.User;
|
import com.flyfish.framework.domain.po.User;
|
||||||
import com.flyfish.framework.enums.UserType;
|
import com.flyfish.framework.enums.UserType;
|
||||||
import com.flyfish.framework.repository.UserRepository;
|
import com.flyfish.framework.repository.UserRepository;
|
||||||
import com.flyfish.framework.service.impl.BaseServiceImpl;
|
import com.flyfish.framework.service.impl.BaseServiceImpl;
|
||||||
import com.flyfish.framework.utils.Assert;
|
import com.flyfish.framework.utils.Assert;
|
||||||
import com.flyfish.framework.utils.StrengthUtils;
|
import com.flyfish.framework.utils.StrengthUtils;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -35,35 +33,35 @@ public class UserService extends BaseServiceImpl<User> implements UserFindServic
|
|||||||
return ((UserRepository) repository).findByUsername(username);
|
return ((UserRepository) repository).findByUsername(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Component
|
||||||
public User create(User entity) {
|
@RequiredArgsConstructor
|
||||||
if (null == entity.getId() && StringUtils.isNotBlank(entity.getPassword())) {
|
public static class Auditor implements BeanAuditor<User> {
|
||||||
Assert.isTrue(StrengthUtils.isValid(entity.getPassword()), "密码强度不够,至少应该包含数字、大小写字母、符号组合");
|
|
||||||
entity.setPassword(passwordEncoder.encode(entity.getPassword()));
|
|
||||||
}
|
|
||||||
if (null == entity.getType()) {
|
|
||||||
entity.setType(UserType.ADMIN);
|
|
||||||
}
|
|
||||||
if (null == entity.getEnable()) {
|
|
||||||
entity.setEnable(true);
|
|
||||||
}
|
|
||||||
if (null == entity.getApp()) {
|
|
||||||
entity.setApp(false);
|
|
||||||
}
|
|
||||||
if (null == entity.getCode()) {
|
|
||||||
entity.setCode(entity.getUsername());
|
|
||||||
}
|
|
||||||
return super.create(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
private final PasswordEncoder passwordEncoder;
|
||||||
public User createSelective(User entity) {
|
|
||||||
return create(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public List<User> getList(Qo<User> query) {
|
* 对实体进行审查,并补全相关字段
|
||||||
return super.getList(query);
|
*
|
||||||
|
* @param entity 原数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void audit(User entity) {
|
||||||
|
if (null == entity.getId() && StringUtils.isNotBlank(entity.getPassword())) {
|
||||||
|
Assert.isTrue(StrengthUtils.isValid(entity.getPassword()), "密码强度不够,至少应该包含数字、大小写字母、符号组合");
|
||||||
|
entity.setPassword(passwordEncoder.encode(entity.getPassword()));
|
||||||
|
}
|
||||||
|
if (null == entity.getType()) {
|
||||||
|
entity.setType(UserType.ADMIN);
|
||||||
|
}
|
||||||
|
if (null == entity.getEnable()) {
|
||||||
|
entity.setEnable(true);
|
||||||
|
}
|
||||||
|
if (null == entity.getApp()) {
|
||||||
|
entity.setApp(false);
|
||||||
|
}
|
||||||
|
if (null == entity.getCode()) {
|
||||||
|
entity.setCode(entity.getUsername());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user