提交 97f8ce2f 编写于 作者: sq3536's avatar sq3536

userservice排除

上级 5ce7e773
package cn.ibizlab.util.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.CachedBeanCopier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import cn.ibizlab.util.mapper.IBZUSERMapper;
import cn.ibizlab.util.domain.IBZUSER;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.security.core.authority.AuthorityUtils;
/**
* 实体[IBZUSER] 服务对象接口实现
*/
@Service("IBZUSERService")
@ConditionalOnExpression("(!${ibiz.enablePermissionValid:false})&&'${ibiz.auth.service:IBZUAAUserService}'.equals('IBZUSERService')")
public class IBZUSERServiceImpl extends ServiceImpl<IBZUSERMapper, IBZUSER> implements IBZUSERService,AuthenticationUserService{
@Value("${ibiz.auth.pwencrymode:0}")
private int pwencrymode;
@Override
public AuthenticationUser loadUserByUsername(String username) {
if(StringUtils.isEmpty(username))
throw new UsernameNotFoundException("用户名为空");
QueryWrapper<IBZUSER> conds=new QueryWrapper<IBZUSER>();
String[] data=username.split("[|]");
String loginname="";
String domains="";
if(data.length>0)
loginname=data[0].trim();
if(data.length>1)
domains=data[1].trim();
if(!StringUtils.isEmpty(loginname))
conds.eq("loginname",loginname);
if(!StringUtils.isEmpty(domains))
conds.eq("domains",domains);
IBZUSER user = this.getOne(conds);
if (user == null) {
throw new UsernameNotFoundException("用户" + username + "未找到");
}
else {
user.setUsername(username);
return createUserDetails(user);
}
}
@Override
public AuthenticationUser loadUserByLogin(String username, String password){
AuthenticationUser authuserdetail = loadUserByUsername(username);
if(pwencrymode==1)
password = DigestUtils.md5DigestAsHex(password.getBytes());
else if(pwencrymode==2)
password = DigestUtils.md5DigestAsHex(String.format("%1$s||%2$s", username, password).getBytes());
if(!authuserdetail.getPassword().equals( password )){
throw new BadRequestAlertException("用户名密码错误","IBZUSER",username);
}
return authuserdetail;
}
public void resetByUsername(String username) {
}
public AuthenticationUser createUserDetails(IBZUSER user) {
AuthenticationUser userdatail = new AuthenticationUser();
CachedBeanCopier.copy(user,userdatail);
if(userdatail.getSuperuser()==1){
userdatail.setAuthorities(AuthorityUtils.createAuthorityList("ROLE_SUPERADMIN"));
}
return userdatail;
}
public class IBZUSERServiceImpl {
}
\ No newline at end of file
package cn.ibizlab.util.service;
import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.client.IBZUAAFeignClient;
import cn.ibizlab.util.client.IBZOUFeignClient;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.security.core.authority.AuthorityUtils;
/**
* 实体[IBZUSER] 服务对象接口实现
*/
@Primary
@Service("SimpleUserService")
@ConditionalOnExpression("(!${ibiz.enablePermissionValid:false})&&'${ibiz.auth.service:IBZUAAUserService}'.equals('SimpleUserService')")
public class SimpleUserService implements AuthenticationUserService{
@Override
public AuthenticationUser loadUserByUsername(String username) {
AuthenticationUser user = new AuthenticationUser();
String[] data=username.split("[|]");
String loginname=username;
String domains="";
String password="";
if(data.length==2) {
loginname=data[0].trim();
domains=data[1].trim();
}
user.setUserid(username);
user.setUsercode(loginname);
user.setUsername(username);
user.setLoginname(loginname);
user.setPersonname(loginname);
user.setDomain(domains);
user.setPassword(password);
user.setOrgid(domains);
user.setOrgcode(domains);
user.setOrgname(domains);
user.setSuperuser(1);
user.setAuthorities(AuthorityUtils.createAuthorityList("ROLE_SUPERADMIN"));
return user;
}
@Override
public AuthenticationUser loadUserByLogin(String username, String password) {
AuthenticationUser authuserdetail = loadUserByUsername(username);
return authuserdetail;
}
@Override
public void resetByUsername(String username) {
}
public class SimpleUserService {
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册