mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 08:13:44 +08:00 
			
		
		
		
	update 更新 service 注解
This commit is contained in:
		@@ -15,12 +15,15 @@ import java.util.Set;
 | 
				
			|||||||
 * @author ruoyi
 | 
					 * @author ruoyi
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@Service("ss")
 | 
					@Service("ss")
 | 
				
			||||||
public class PermissionService
 | 
					public class PermissionService {
 | 
				
			||||||
{
 | 
					    /**
 | 
				
			||||||
    /** 所有权限标识 */
 | 
					     * 所有权限标识
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    private static final String ALL_PERMISSION = "*:*:*";
 | 
					    private static final String ALL_PERMISSION = "*:*:*";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** 管理员角色权限标识 */
 | 
					    /**
 | 
				
			||||||
 | 
					     * 管理员角色权限标识
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
    private static final String SUPER_ADMIN = "admin";
 | 
					    private static final String SUPER_ADMIN = "admin";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static final String ROLE_DELIMETER = ",";
 | 
					    private static final String ROLE_DELIMETER = ",";
 | 
				
			||||||
@@ -33,15 +36,12 @@ public class PermissionService
 | 
				
			|||||||
     * @param permission 权限字符串
 | 
					     * @param permission 权限字符串
 | 
				
			||||||
     * @return 用户是否具备某权限
 | 
					     * @return 用户是否具备某权限
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean hasPermi(String permission)
 | 
					    public boolean hasPermi(String permission) {
 | 
				
			||||||
    {
 | 
					        if (StringUtils.isEmpty(permission)) {
 | 
				
			||||||
        if (StringUtils.isEmpty(permission))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        LoginUser loginUser = SecurityUtils.getLoginUser();
 | 
					        LoginUser loginUser = SecurityUtils.getLoginUser();
 | 
				
			||||||
        if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions()))
 | 
					        if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return hasPermissions(loginUser.getPermissions(), permission);
 | 
					        return hasPermissions(loginUser.getPermissions(), permission);
 | 
				
			||||||
@@ -53,8 +53,7 @@ public class PermissionService
 | 
				
			|||||||
     * @param permission 权限字符串
 | 
					     * @param permission 权限字符串
 | 
				
			||||||
     * @return 用户是否不具备某权限
 | 
					     * @return 用户是否不具备某权限
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean lacksPermi(String permission)
 | 
					    public boolean lacksPermi(String permission) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return hasPermi(permission) != true;
 | 
					        return hasPermi(permission) != true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -64,22 +63,17 @@ public class PermissionService
 | 
				
			|||||||
     * @param permissions 以 PERMISSION_NAMES_DELIMETER 为分隔符的权限列表
 | 
					     * @param permissions 以 PERMISSION_NAMES_DELIMETER 为分隔符的权限列表
 | 
				
			||||||
     * @return 用户是否具有以下任意一个权限
 | 
					     * @return 用户是否具有以下任意一个权限
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean hasAnyPermi(String permissions)
 | 
					    public boolean hasAnyPermi(String permissions) {
 | 
				
			||||||
    {
 | 
					        if (StringUtils.isEmpty(permissions)) {
 | 
				
			||||||
        if (StringUtils.isEmpty(permissions))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        LoginUser loginUser = SecurityUtils.getLoginUser();
 | 
					        LoginUser loginUser = SecurityUtils.getLoginUser();
 | 
				
			||||||
        if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions()))
 | 
					        if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Set<String> authorities = loginUser.getPermissions();
 | 
					        Set<String> authorities = loginUser.getPermissions();
 | 
				
			||||||
        for (String permission : permissions.split(PERMISSION_DELIMETER))
 | 
					        for (String permission : permissions.split(PERMISSION_DELIMETER)) {
 | 
				
			||||||
        {
 | 
					            if (permission != null && hasPermissions(authorities, permission)) {
 | 
				
			||||||
            if (permission != null && hasPermissions(authorities, permission))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -92,22 +86,17 @@ public class PermissionService
 | 
				
			|||||||
     * @param role 角色字符串
 | 
					     * @param role 角色字符串
 | 
				
			||||||
     * @return 用户是否具备某角色
 | 
					     * @return 用户是否具备某角色
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean hasRole(String role)
 | 
					    public boolean hasRole(String role) {
 | 
				
			||||||
    {
 | 
					        if (StringUtils.isEmpty(role)) {
 | 
				
			||||||
        if (StringUtils.isEmpty(role))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        LoginUser loginUser = SecurityUtils.getLoginUser();
 | 
					        LoginUser loginUser = SecurityUtils.getLoginUser();
 | 
				
			||||||
        if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles()))
 | 
					        if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        for (SysRole sysRole : loginUser.getUser().getRoles())
 | 
					        for (SysRole sysRole : loginUser.getUser().getRoles()) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            String roleKey = sysRole.getRoleKey();
 | 
					            String roleKey = sysRole.getRoleKey();
 | 
				
			||||||
            if (SUPER_ADMIN.equals(roleKey) || roleKey.equals(StringUtils.trim(role)))
 | 
					            if (SUPER_ADMIN.equals(roleKey) || roleKey.equals(StringUtils.trim(role))) {
 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -120,8 +109,7 @@ public class PermissionService
 | 
				
			|||||||
     * @param role 角色名称
 | 
					     * @param role 角色名称
 | 
				
			||||||
     * @return 用户是否不具备某角色
 | 
					     * @return 用户是否不具备某角色
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean lacksRole(String role)
 | 
					    public boolean lacksRole(String role) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return hasRole(role) != true;
 | 
					        return hasRole(role) != true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -131,21 +119,16 @@ public class PermissionService
 | 
				
			|||||||
     * @param roles 以 ROLE_NAMES_DELIMETER 为分隔符的角色列表
 | 
					     * @param roles 以 ROLE_NAMES_DELIMETER 为分隔符的角色列表
 | 
				
			||||||
     * @return 用户是否具有以下任意一个角色
 | 
					     * @return 用户是否具有以下任意一个角色
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean hasAnyRoles(String roles)
 | 
					    public boolean hasAnyRoles(String roles) {
 | 
				
			||||||
    {
 | 
					        if (StringUtils.isEmpty(roles)) {
 | 
				
			||||||
        if (StringUtils.isEmpty(roles))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        LoginUser loginUser = SecurityUtils.getLoginUser();
 | 
					        LoginUser loginUser = SecurityUtils.getLoginUser();
 | 
				
			||||||
        if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles()))
 | 
					        if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        for (String role : roles.split(ROLE_DELIMETER))
 | 
					        for (String role : roles.split(ROLE_DELIMETER)) {
 | 
				
			||||||
        {
 | 
					            if (hasRole(role)) {
 | 
				
			||||||
            if (hasRole(role))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -156,11 +139,10 @@ public class PermissionService
 | 
				
			|||||||
     * 判断是否包含权限
 | 
					     * 判断是否包含权限
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param permissions 权限列表
 | 
					     * @param permissions 权限列表
 | 
				
			||||||
     * @param permission 权限字符串
 | 
					     * @param permission  权限字符串
 | 
				
			||||||
     * @return 用户是否具备某权限
 | 
					     * @return 用户是否具备某权限
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private boolean hasPermissions(Set<String> permissions, String permission)
 | 
					    private boolean hasPermissions(Set<String> permissions, String permission) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return permissions.contains(ALL_PERMISSION) || permissions.contains(StringUtils.trim(permission));
 | 
					        return permissions.contains(ALL_PERMISSION) || permissions.contains(StringUtils.trim(permission));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,74 +18,65 @@ import org.springframework.security.authentication.AuthenticationManager;
 | 
				
			|||||||
import org.springframework.security.authentication.BadCredentialsException;
 | 
					import org.springframework.security.authentication.BadCredentialsException;
 | 
				
			||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 | 
					import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 | 
				
			||||||
import org.springframework.security.core.Authentication;
 | 
					import org.springframework.security.core.Authentication;
 | 
				
			||||||
import org.springframework.stereotype.Component;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.annotation.Resource;
 | 
					import javax.annotation.Resource;
 | 
				
			||||||
import javax.servlet.http.HttpServletRequest;
 | 
					import javax.servlet.http.HttpServletRequest;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 登录校验方法
 | 
					 * 登录校验方法
 | 
				
			||||||
 * 
 | 
					 *
 | 
				
			||||||
 * @author ruoyi
 | 
					 * @author ruoyi
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@Component
 | 
					@Service
 | 
				
			||||||
public class SysLoginService
 | 
					public class SysLoginService {
 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private TokenService tokenService;
 | 
					    private TokenService tokenService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Resource
 | 
					    @Resource
 | 
				
			||||||
    private AuthenticationManager authenticationManager;
 | 
					    private AuthenticationManager authenticationManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private ISysUserService userService;
 | 
					    private ISysUserService userService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Autowired
 | 
					    @Autowired
 | 
				
			||||||
	private ISysConfigService configService;
 | 
					    private ISysConfigService configService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Autowired
 | 
					    @Autowired
 | 
				
			||||||
	private LogininforService asyncService;
 | 
					    private LogininforService asyncService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 登录验证
 | 
					     * 登录验证
 | 
				
			||||||
     * 
 | 
					     *
 | 
				
			||||||
     * @param username 用户名
 | 
					     * @param username 用户名
 | 
				
			||||||
     * @param password 密码
 | 
					     * @param password 密码
 | 
				
			||||||
     * @param code 验证码
 | 
					     * @param code     验证码
 | 
				
			||||||
     * @param uuid 唯一标识
 | 
					     * @param uuid     唯一标识
 | 
				
			||||||
     * @return 结果
 | 
					     * @return 结果
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public String login(String username, String password, String code, String uuid)
 | 
					    public String login(String username, String password, String code, String uuid) {
 | 
				
			||||||
    {
 | 
					        HttpServletRequest request = ServletUtils.getRequest();
 | 
				
			||||||
		HttpServletRequest request = ServletUtils.getRequest();
 | 
					        boolean captchaOnOff = configService.selectCaptchaOnOff();
 | 
				
			||||||
		boolean captchaOnOff = configService.selectCaptchaOnOff();
 | 
					 | 
				
			||||||
        // 验证码开关
 | 
					        // 验证码开关
 | 
				
			||||||
        if (captchaOnOff)
 | 
					        if (captchaOnOff) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            validateCaptcha(username, code, uuid, request);
 | 
					            validateCaptcha(username, code, uuid, request);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // 用户验证
 | 
					        // 用户验证
 | 
				
			||||||
        Authentication authentication = null;
 | 
					        Authentication authentication = null;
 | 
				
			||||||
        try
 | 
					        try {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
 | 
					            // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
 | 
				
			||||||
            authentication = authenticationManager
 | 
					            authentication = authenticationManager
 | 
				
			||||||
                    .authenticate(new UsernamePasswordAuthenticationToken(username, password));
 | 
					                    .authenticate(new UsernamePasswordAuthenticationToken(username, password));
 | 
				
			||||||
        }
 | 
					        } catch (Exception e) {
 | 
				
			||||||
        catch (Exception e)
 | 
					            if (e instanceof BadCredentialsException) {
 | 
				
			||||||
        {
 | 
					                asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"), request);
 | 
				
			||||||
            if (e instanceof BadCredentialsException)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
				asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"), request);
 | 
					 | 
				
			||||||
                throw new UserPasswordNotMatchException();
 | 
					                throw new UserPasswordNotMatchException();
 | 
				
			||||||
            }
 | 
					            } else {
 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage(), request);
 | 
					                asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage(), request);
 | 
				
			||||||
                throw new ServiceException(e.getMessage());
 | 
					                throw new ServiceException(e.getMessage());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
		asyncService.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"), request);
 | 
					        asyncService.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"), request);
 | 
				
			||||||
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
 | 
					        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
 | 
				
			||||||
        recordLoginInfo(loginUser.getUserId());
 | 
					        recordLoginInfo(loginUser.getUserId());
 | 
				
			||||||
        // 生成token
 | 
					        // 生成token
 | 
				
			||||||
@@ -94,24 +85,24 @@ public class SysLoginService
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 校验验证码
 | 
					     * 校验验证码
 | 
				
			||||||
     * 
 | 
					     *
 | 
				
			||||||
     * @param username 用户名
 | 
					     * @param username 用户名
 | 
				
			||||||
     * @param code 验证码
 | 
					     * @param code     验证码
 | 
				
			||||||
     * @param uuid 唯一标识
 | 
					     * @param uuid     唯一标识
 | 
				
			||||||
     * @return 结果
 | 
					     * @return 结果
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void validateCaptcha(String username, String code, String uuid, HttpServletRequest request) {
 | 
					    public void validateCaptcha(String username, String code, String uuid, HttpServletRequest request) {
 | 
				
			||||||
		String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
 | 
					        String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
 | 
				
			||||||
		String captcha = RedisUtils.getCacheObject(verifyKey);
 | 
					        String captcha = RedisUtils.getCacheObject(verifyKey);
 | 
				
			||||||
        RedisUtils.deleteObject(verifyKey);
 | 
					        RedisUtils.deleteObject(verifyKey);
 | 
				
			||||||
		if (captcha == null) {
 | 
					        if (captcha == null) {
 | 
				
			||||||
			asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"), request);
 | 
					            asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"), request);
 | 
				
			||||||
			throw new CaptchaExpireException();
 | 
					            throw new CaptchaExpireException();
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
		if (!code.equalsIgnoreCase(captcha)) {
 | 
					        if (!code.equalsIgnoreCase(captcha)) {
 | 
				
			||||||
			asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"), request);
 | 
					            asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"), request);
 | 
				
			||||||
			throw new CaptchaException();
 | 
					            throw new CaptchaException();
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -119,8 +110,7 @@ public class SysLoginService
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param userId 用户ID
 | 
					     * @param userId 用户ID
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void recordLoginInfo(Long userId)
 | 
					    public void recordLoginInfo(Long userId) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        SysUser sysUser = new SysUser();
 | 
					        SysUser sysUser = new SysUser();
 | 
				
			||||||
        sysUser.setUserId(userId);
 | 
					        sysUser.setUserId(userId);
 | 
				
			||||||
        sysUser.setLoginIp(ServletUtils.getClientIP());
 | 
					        sysUser.setLoginIp(ServletUtils.getClientIP());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,19 +2,19 @@ package com.ruoyi.system.service;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import com.ruoyi.common.core.domain.entity.SysUser;
 | 
					import com.ruoyi.common.core.domain.entity.SysUser;
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
import org.springframework.stereotype.Component;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.HashSet;
 | 
					import java.util.HashSet;
 | 
				
			||||||
import java.util.Set;
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 用户权限处理
 | 
					 * 用户权限处理
 | 
				
			||||||
 * 
 | 
					 *
 | 
				
			||||||
 * @author ruoyi
 | 
					 * @author ruoyi
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@Component
 | 
					@Service
 | 
				
			||||||
public class SysPermissionService
 | 
					public class SysPermissionService {
 | 
				
			||||||
{
 | 
					
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private ISysRoleService roleService;
 | 
					    private ISysRoleService roleService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -23,20 +23,16 @@ public class SysPermissionService
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 获取角色数据权限
 | 
					     * 获取角色数据权限
 | 
				
			||||||
     * 
 | 
					     *
 | 
				
			||||||
     * @param user 用户信息
 | 
					     * @param user 用户信息
 | 
				
			||||||
     * @return 角色权限信息
 | 
					     * @return 角色权限信息
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public Set<String> getRolePermission(SysUser user)
 | 
					    public Set<String> getRolePermission(SysUser user) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        Set<String> roles = new HashSet<String>();
 | 
					        Set<String> roles = new HashSet<String>();
 | 
				
			||||||
        // 管理员拥有所有权限
 | 
					        // 管理员拥有所有权限
 | 
				
			||||||
        if (user.isAdmin())
 | 
					        if (user.isAdmin()) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            roles.add("admin");
 | 
					            roles.add("admin");
 | 
				
			||||||
        }
 | 
					        } else {
 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            roles.addAll(roleService.selectRolePermissionByUserId(user.getUserId()));
 | 
					            roles.addAll(roleService.selectRolePermissionByUserId(user.getUserId()));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return roles;
 | 
					        return roles;
 | 
				
			||||||
@@ -44,20 +40,16 @@ public class SysPermissionService
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 获取菜单数据权限
 | 
					     * 获取菜单数据权限
 | 
				
			||||||
     * 
 | 
					     *
 | 
				
			||||||
     * @param user 用户信息
 | 
					     * @param user 用户信息
 | 
				
			||||||
     * @return 菜单权限信息
 | 
					     * @return 菜单权限信息
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public Set<String> getMenuPermission(SysUser user)
 | 
					    public Set<String> getMenuPermission(SysUser user) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        Set<String> perms = new HashSet<String>();
 | 
					        Set<String> perms = new HashSet<String>();
 | 
				
			||||||
        // 管理员拥有所有权限
 | 
					        // 管理员拥有所有权限
 | 
				
			||||||
        if (user.isAdmin())
 | 
					        if (user.isAdmin()) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            perms.add("*:*:*");
 | 
					            perms.add("*:*:*");
 | 
				
			||||||
        }
 | 
					        } else {
 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId()));
 | 
					            perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId()));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return perms;
 | 
					        return perms;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,75 +9,59 @@ import com.ruoyi.common.exception.user.CaptchaException;
 | 
				
			|||||||
import com.ruoyi.common.exception.user.CaptchaExpireException;
 | 
					import com.ruoyi.common.exception.user.CaptchaExpireException;
 | 
				
			||||||
import com.ruoyi.common.utils.*;
 | 
					import com.ruoyi.common.utils.*;
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
import org.springframework.stereotype.Component;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 注册校验方法
 | 
					 * 注册校验方法
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author ruoyi
 | 
					 * @author ruoyi
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@Component
 | 
					@Service
 | 
				
			||||||
public class SysRegisterService
 | 
					public class SysRegisterService {
 | 
				
			||||||
{
 | 
					
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private ISysUserService userService;
 | 
					    private ISysUserService userService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private ISysConfigService configService;
 | 
					    private ISysConfigService configService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Autowired
 | 
					    @Autowired
 | 
				
			||||||
	private LogininforService asyncService;
 | 
					    private LogininforService asyncService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 注册
 | 
					     * 注册
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public String register(RegisterBody registerBody)
 | 
					    public String register(RegisterBody registerBody) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        String msg = "", username = registerBody.getUsername(), password = registerBody.getPassword();
 | 
					        String msg = "", username = registerBody.getUsername(), password = registerBody.getPassword();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        boolean captchaOnOff = configService.selectCaptchaOnOff();
 | 
					        boolean captchaOnOff = configService.selectCaptchaOnOff();
 | 
				
			||||||
        // 验证码开关
 | 
					        // 验证码开关
 | 
				
			||||||
        if (captchaOnOff)
 | 
					        if (captchaOnOff) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            validateCaptcha(username, registerBody.getCode(), registerBody.getUuid());
 | 
					            validateCaptcha(username, registerBody.getCode(), registerBody.getUuid());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (StringUtils.isEmpty(username))
 | 
					        if (StringUtils.isEmpty(username)) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            msg = "用户名不能为空";
 | 
					            msg = "用户名不能为空";
 | 
				
			||||||
        }
 | 
					        } else if (StringUtils.isEmpty(password)) {
 | 
				
			||||||
        else if (StringUtils.isEmpty(password))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            msg = "用户密码不能为空";
 | 
					            msg = "用户密码不能为空";
 | 
				
			||||||
        }
 | 
					        } else if (username.length() < UserConstants.USERNAME_MIN_LENGTH
 | 
				
			||||||
        else if (username.length() < UserConstants.USERNAME_MIN_LENGTH
 | 
					                || username.length() > UserConstants.USERNAME_MAX_LENGTH) {
 | 
				
			||||||
                || username.length() > UserConstants.USERNAME_MAX_LENGTH)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            msg = "账户长度必须在2到20个字符之间";
 | 
					            msg = "账户长度必须在2到20个字符之间";
 | 
				
			||||||
        }
 | 
					        } else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
 | 
				
			||||||
        else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
 | 
					                || password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
 | 
				
			||||||
                || password.length() > UserConstants.PASSWORD_MAX_LENGTH)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            msg = "密码长度必须在5到20个字符之间";
 | 
					            msg = "密码长度必须在5到20个字符之间";
 | 
				
			||||||
        }
 | 
					        } else if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username))) {
 | 
				
			||||||
        else if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username)))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            msg = "保存用户'" + username + "'失败,注册账号已存在";
 | 
					            msg = "保存用户'" + username + "'失败,注册账号已存在";
 | 
				
			||||||
        }
 | 
					        } else {
 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            SysUser sysUser = new SysUser();
 | 
					            SysUser sysUser = new SysUser();
 | 
				
			||||||
            sysUser.setUserName(username);
 | 
					            sysUser.setUserName(username);
 | 
				
			||||||
            sysUser.setNickName(username);
 | 
					            sysUser.setNickName(username);
 | 
				
			||||||
            sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword()));
 | 
					            sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword()));
 | 
				
			||||||
            boolean regFlag = userService.registerUser(sysUser);
 | 
					            boolean regFlag = userService.registerUser(sysUser);
 | 
				
			||||||
            if (!regFlag)
 | 
					            if (!regFlag) {
 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                msg = "注册失败,请联系系统管理人员";
 | 
					                msg = "注册失败,请联系系统管理人员";
 | 
				
			||||||
            }
 | 
					            } else {
 | 
				
			||||||
            else
 | 
					                asyncService.recordLogininfor(username, Constants.REGISTER,
 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
				asyncService.recordLogininfor(username, Constants.REGISTER,
 | 
					 | 
				
			||||||
                        MessageUtils.message("user.register.success"), ServletUtils.getRequest());
 | 
					                        MessageUtils.message("user.register.success"), ServletUtils.getRequest());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -88,21 +72,18 @@ public class SysRegisterService
 | 
				
			|||||||
     * 校验验证码
 | 
					     * 校验验证码
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param username 用户名
 | 
					     * @param username 用户名
 | 
				
			||||||
     * @param code 验证码
 | 
					     * @param code     验证码
 | 
				
			||||||
     * @param uuid 唯一标识
 | 
					     * @param uuid     唯一标识
 | 
				
			||||||
     * @return 结果
 | 
					     * @return 结果
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void validateCaptcha(String username, String code, String uuid)
 | 
					    public void validateCaptcha(String username, String code, String uuid) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
 | 
					        String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
 | 
				
			||||||
        String captcha = RedisUtils.getCacheObject(verifyKey);
 | 
					        String captcha = RedisUtils.getCacheObject(verifyKey);
 | 
				
			||||||
        RedisUtils.deleteObject(verifyKey);
 | 
					        RedisUtils.deleteObject(verifyKey);
 | 
				
			||||||
        if (captcha == null)
 | 
					        if (captcha == null) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            throw new CaptchaExpireException();
 | 
					            throw new CaptchaExpireException();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (!code.equalsIgnoreCase(captcha))
 | 
					        if (!code.equalsIgnoreCase(captcha)) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            throw new CaptchaException();
 | 
					            throw new CaptchaException();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,7 @@ import io.jsonwebtoken.Claims;
 | 
				
			|||||||
import io.jsonwebtoken.Jwts;
 | 
					import io.jsonwebtoken.Jwts;
 | 
				
			||||||
import io.jsonwebtoken.SignatureAlgorithm;
 | 
					import io.jsonwebtoken.SignatureAlgorithm;
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
import org.springframework.stereotype.Component;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.servlet.http.HttpServletRequest;
 | 
					import javax.servlet.http.HttpServletRequest;
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
@@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author Lion Li
 | 
					 * @author Lion Li
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@Component
 | 
					@Service
 | 
				
			||||||
public class TokenServiceImpl implements TokenService {
 | 
					public class TokenServiceImpl implements TokenService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected static final long MILLIS_SECOND = 1000;
 | 
					    protected static final long MILLIS_SECOND = 1000;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,8 +21,7 @@ import org.springframework.stereotype.Service;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
@Slf4j
 | 
					@Slf4j
 | 
				
			||||||
@Service
 | 
					@Service
 | 
				
			||||||
public class UserDetailsServiceImpl implements UserDetailsService
 | 
					public class UserDetailsServiceImpl implements UserDetailsService {
 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private ISysUserService userService;
 | 
					    private ISysUserService userService;
 | 
				
			||||||
@@ -31,21 +30,15 @@ public class UserDetailsServiceImpl implements UserDetailsService
 | 
				
			|||||||
    private SysPermissionService permissionService;
 | 
					    private SysPermissionService permissionService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
 | 
					    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        SysUser user = userService.selectUserByUserName(username);
 | 
					        SysUser user = userService.selectUserByUserName(username);
 | 
				
			||||||
        if (StringUtils.isNull(user))
 | 
					        if (StringUtils.isNull(user)) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            log.info("登录用户:{} 不存在.", username);
 | 
					            log.info("登录用户:{} 不存在.", username);
 | 
				
			||||||
            throw new ServiceException("登录用户:" + username + " 不存在");
 | 
					            throw new ServiceException("登录用户:" + username + " 不存在");
 | 
				
			||||||
        }
 | 
					        } else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
 | 
				
			||||||
        else if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            log.info("登录用户:{} 已被删除.", username);
 | 
					            log.info("登录用户:{} 已被删除.", username);
 | 
				
			||||||
            throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
 | 
					            throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
 | 
				
			||||||
        }
 | 
					        } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
 | 
				
			||||||
        else if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            log.info("登录用户:{} 已被停用.", username);
 | 
					            log.info("登录用户:{} 已被停用.", username);
 | 
				
			||||||
            throw new ServiceException("对不起,您的账号:" + username + " 已停用");
 | 
					            throw new ServiceException("对不起,您的账号:" + username + " 已停用");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -53,8 +46,7 @@ public class UserDetailsServiceImpl implements UserDetailsService
 | 
				
			|||||||
        return createLoginUser(user);
 | 
					        return createLoginUser(user);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public UserDetails createLoginUser(SysUser user)
 | 
					    public UserDetails createLoginUser(SysUser user) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user));
 | 
					        return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user