use of com.ruoyi.common.exception.ServiceException in project wumei-smart by kerwincui.
the class SysLoginService method socialLogin.
/**
* 第三方验证后,调用登录方法
* @param username 用户名
* @param password 密码
* @return token
*/
public String socialLogin(String username, String password) {
// 用户验证
Authentication authentication = null;
try {
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
} catch (Exception e) {
if (e instanceof BadCredentialsException) {
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
throw new UserPasswordNotMatchException();
} else {
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
throw new ServiceException(e.getMessage());
}
}
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
recordLoginInfo(loginUser.getUserId());
// 生成token
return tokenService.createToken(loginUser);
}
use of com.ruoyi.common.exception.ServiceException in project wumei-smart by kerwincui.
the class SysUserServiceImpl method checkUserDataScope.
/**
* 校验用户是否有数据权限
*
* @param userId 用户id
*/
@Override
public void checkUserDataScope(Long userId) {
if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
SysUser user = new SysUser();
user.setUserId(userId);
List<SysUser> users = SpringUtils.getAopProxy(this).selectUserList(user);
if (StringUtils.isEmpty(users)) {
throw new ServiceException("没有权限访问用户数据!");
}
}
}
use of com.ruoyi.common.exception.ServiceException in project wumei-smart by kerwincui.
the class ProductAuthorizeServiceImpl method boundProductAuthorize.
/**
* 根据产品id和设备序列号绑定授权码
*
* @param productAuthorize
* @return
*/
@Override
@Transactional
public int boundProductAuthorize(ProductAuthorize productAuthorize) {
ProductAuthorize authorize = null;
if (StringUtils.isEmpty(productAuthorize.getAuthorizeCode())) {
// TODO-kami: 2022/4/11 13:34 后期无需查询,硬件调用直接传入参数,可以删除
authorize = productAuthorizeMapper.selectOneUnboundAuthorizeByProductId(productAuthorize);
productAuthorize.setAuthorizeCode(authorize.getAuthorizeCode());
} else {
authorize = productAuthorizeMapper.selectOneUnboundAuthorizeByAuthorizeCode(productAuthorize);
}
if (authorize == null) {
throw new ServiceException("授权码数据异常", HttpStatus.BAD_REQUEST);
}
productAuthorize.setAuthorizeId(authorize.getAuthorizeId());
productAuthorize.setUpdateTime(DateUtils.getNowDate());
return productAuthorizeMapper.updateProductAuthorize(productAuthorize);
}
use of com.ruoyi.common.exception.ServiceException in project wumei-smart by kerwincui.
the class SysRoleServiceImpl method deleteRoleByIds.
/**
* 批量删除角色信息
*
* @param roleIds 需要删除的角色ID
* @return 结果
*/
@Override
@Transactional
public int deleteRoleByIds(Long[] roleIds) {
for (Long roleId : roleIds) {
checkRoleAllowed(new SysRole(roleId));
SysRole role = selectRoleById(roleId);
if (countUserRoleByRoleId(roleId) > 0) {
throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName()));
}
}
// 删除角色与菜单关联
roleMenuMapper.deleteRoleMenu(roleIds);
// 删除角色与部门关联
roleDeptMapper.deleteRoleDept(roleIds);
return roleMapper.deleteRoleByIds(roleIds);
}
use of com.ruoyi.common.exception.ServiceException in project wumei-smart by kerwincui.
the class SysRoleServiceImpl method checkRoleDataScope.
/**
* 校验角色是否有数据权限
*
* @param roleId 角色id
*/
@Override
public void checkRoleDataScope(Long roleId) {
if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
SysRole role = new SysRole();
role.setRoleId(roleId);
List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
if (StringUtils.isEmpty(roles)) {
throw new ServiceException("没有权限访问角色数据!");
}
}
}
Aggregations