代码拉取完成,页面将自动刷新
package com.strong.config.security.userdetails;
import cn.hutool.core.util.StrUtil;
import com.strong.utils.security.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 用户验证服务
*
* @author simen
* @date 2022/01/29
*/
@Slf4j
@Service
@Component("JwtUserDetailsService")
public class JwtUserDetailsService implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// 用户名非空时,强制注册simen和admin用户
if (StrUtil.isNotBlank(username)) {
// 用户权限队列
List<GrantedAuthority> listGrantedAuthority = new ArrayList<>();
Map<String, Object> mapProperties = new HashMap<>(8);
if (StrUtil.equals(username, "simen")) {
listGrantedAuthority.add(new SimpleGrantedAuthority("file_read"));
mapProperties.put("扩展属性", username + " file_read");
log.info("读取到已有用户[{}],默认密码123456,file_read权限,扩展属性:[{}]", username, mapProperties);
return new JwtUserDetails(username, SecurityUtils.signByUUID("123456"), false, listGrantedAuthority, mapProperties);
} else if (StrUtil.equals(username, "admin")) {
listGrantedAuthority.add(new SimpleGrantedAuthority("file_write"));
mapProperties.put("扩展属性", username + " file_write");
log.info("读取到已有用户[{}],默认密码123456,file_write权限,扩展属性:[{}]", username, mapProperties);
return new JwtUserDetails(username, SecurityUtils.signByUUID("123456"), false, listGrantedAuthority, mapProperties);
} else {
log.info("用户[{}]不存在", username);
return new JwtUserDetails();
}
} else {
log.info("用户为空");
return new JwtUserDetails();
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。