Java Code Examples for com.ruoyi.framework.util.ShiroUtils#getSysUser()
The following examples show how to use
com.ruoyi.framework.util.ShiroUtils#getSysUser() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataScopeAspect.java From supplierShop with MIT License | 6 votes |
protected void handleDataScope(final JoinPoint joinPoint) { // 获得注解 DataScope controllerDataScope = getAnnotationLog(joinPoint); if (controllerDataScope == null) { return; } // 获取当前的用户 SysUser currentUser = ShiroUtils.getSysUser(); if (currentUser != null) { // 如果是超级管理员,则不过滤数据 if (!currentUser.isAdmin()) { dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), controllerDataScope.userAlias()); } } }
Example 2
Source File: UserRealm.java From RuoYi with Apache License 2.0 | 6 votes |
/** * 授权 */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0) { SysUser user = ShiroUtils.getSysUser(); SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); // 管理员拥有所有权限 if (user.isAdmin()) { info.addRole("admin"); info.addStringPermission("*:*:*"); } else { // 角色列表 Set<String> roles = roleService.selectRoleKeys(user.getUserId()); // 功能列表 Set<String> menus = menuService.selectPermsByUserId(user.getUserId()); // 角色加入AuthorizationInfo认证对象 info.setRoles(roles); // 权限加入AuthorizationInfo认证对象 info.setStringPermissions(menus); } return info; }
Example 3
Source File: DataScopeAspect.java From ruoyiplus with MIT License | 6 votes |
protected void handleDataScope(final JoinPoint joinPoint) { // 获得注解 DataScope controllerDataScope = getAnnotationLog(joinPoint); if (controllerDataScope == null) { return; } // 获取当前的用户 SysUser currentUser = ShiroUtils.getSysUser(); if (currentUser != null) { // 如果是超级管理员,则不过滤数据 if (!currentUser.isAdmin()) { dataScopeFilter(joinPoint, currentUser, controllerDataScope.tableAlias()); } } }
Example 4
Source File: LogoutFilter.java From RuoYi with Apache License 2.0 | 6 votes |
@Override protected boolean preHandle(ServletRequest request, ServletResponse response){ try { Subject subject = getSubject(request, response); String redirectUrl = getRedirectUrl(request, response, subject); SysUser user = ShiroUtils.getSysUser(); if (ObjectUtil.isNotNull(user)) { String loginName = user.getLoginName(); // 记录用户退出日志 AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success"))); // 清理缓存 cache.remove(loginName); } // 退出登录 subject.logout(); issueRedirect(request, response, redirectUrl); } catch (Exception e) { log.error("Encountered session exception during logout. This can generally safely be ignored." , e); } return false; }
Example 5
Source File: UserRealm.java From ruoyiplus with MIT License | 5 votes |
/** * 授权 */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0) { SysUser user = ShiroUtils.getSysUser(); // 角色列表 Set<String> roles = new HashSet<String>(); // 功能列表 Set<String> menus = new HashSet<String>(); SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); // 管理员拥有所有权限 if (user.isAdmin()) { info.addRole("admin"); info.addStringPermission("*:*:*"); } else { roles = roleService.selectRoleKeys(user.getUserId()); menus = menuService.selectPermsByUserId(user.getUserId()); // 角色加入AuthorizationInfo认证对象 info.setRoles(roles); // 权限加入AuthorizationInfo认证对象 info.setStringPermissions(menus); } return info; }
Example 6
Source File: OnlineSessionFilter.java From ruoyiplus with MIT License | 5 votes |
/** * 表示是否允许访问;mappedValue就是[urls]配置中拦截器参数部分,如果允许访问返回true,否则false; */ @Override protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { Subject subject = getSubject(request, response); if (subject == null || subject.getSession() == null) { return true; } Session session = onlineSessionDAO.readSession(subject.getSession().getId()); if (session != null && session instanceof OnlineSession) { OnlineSession onlineSession = (OnlineSession) session; request.setAttribute(ShiroConstants.ONLINE_SESSION, onlineSession); // 把user对象设置进去 boolean isGuest = onlineSession.getUserId() == null || onlineSession.getUserId() == 0L; if (isGuest == true) { SysUser user = ShiroUtils.getSysUser(); if (user != null) { onlineSession.setUserId(user.getUserId()); onlineSession.setLoginName(user.getLoginName()); onlineSession.setDeptName(user.getDept().getDeptName()); onlineSession.markAttributeChanged(); } } if (onlineSession.getStatus() == OnlineStatus.off_line) { return false; } } return true; }
Example 7
Source File: OnlineSessionFilter.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 表示是否允许访问;mappedValue就是[urls]配置中拦截器参数部分,如果允许访问返回true,否则false; */ @Override protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue){ Subject subject = getSubject(request, response); if (subject == null || subject.getSession() == null) { return true; } Session session = onlineSessionDAO.readSession(subject.getSession().getId()); if (session instanceof OnlineSession) { OnlineSession onlineSession = (OnlineSession) session; request.setAttribute(ShiroConstants.ONLINE_SESSION, onlineSession); // 把user对象设置进去 boolean isGuest = onlineSession.getUserId() == null || onlineSession.getUserId() == 0L; if (isGuest) { SysUser user = ShiroUtils.getSysUser(); if (user != null) { onlineSession.setUserId(user.getUserId()); onlineSession.setLoginName(user.getLoginName()); onlineSession.setAvatar(user.getAvatar()); onlineSession.setDeptName(user.getDept().getDeptName()); onlineSession.markAttributeChanged(); } } return onlineSession.getStatus() != OnlineStatus.OFF_LINE; } return true; }
Example 8
Source File: SysProfileController.java From supplierShop with MIT License | 5 votes |
/** * 修改用户 */ @GetMapping("/edit") public String edit(ModelMap mmap) { SysUser user = ShiroUtils.getSysUser(); mmap.put("user", userService.selectUserById(user.getUserId())); return prefix + "/edit"; }
Example 9
Source File: SysProfileController.java From supplierShop with MIT License | 5 votes |
@GetMapping("/resetPwd") public String resetPwd(ModelMap mmap) { SysUser user = ShiroUtils.getSysUser(); mmap.put("user", userService.selectUserById(user.getUserId())); return prefix + "/resetPwd"; }
Example 10
Source File: SysProfileController.java From supplierShop with MIT License | 5 votes |
@GetMapping("/checkPassword") @ResponseBody public boolean checkPassword(String password) { SysUser user = ShiroUtils.getSysUser(); if (passwordService.matches(user, password)) { return true; } return false; }
Example 11
Source File: LoginAuthInterceptor.java From RuoYi with Apache License 2.0 | 5 votes |
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){ if (handler instanceof HandlerMethod) { final HandlerMethod handlerMethod = (HandlerMethod) handler; final Class<?> clazz = handlerMethod.getBeanType(); final Method method = handlerMethod.getMethod(); if (clazz.isAnnotationPresent(LoginAuth.class) || method.isAnnotationPresent(LoginAuth.class)) { SysUser loginUser = ShiroUtils.getSysUser(); return ObjectUtil.isNotNull(loginUser); } } return true; }
Example 12
Source File: SysIndexController.java From supplierShop with MIT License | 5 votes |
@GetMapping("/index") public String index(ModelMap mmap) { // 取身份信息 SysUser user = ShiroUtils.getSysUser(); // 根据用户id取出菜单 List<SysMenu> menus = menuService.selectMenusByUser(user); mmap.put("menus", menus); mmap.put("user", user); mmap.put("copyrightYear", Global.getCopyrightYear()); mmap.put("demoEnabled", Global.isDemoEnabled()); return "index"; }
Example 13
Source File: DataScopeAspect.java From RuoYi with Apache License 2.0 | 5 votes |
private void handleDataScope(final JoinPoint joinPoint) { // 获得注解 DataScope controllerDataScope = getAnnotationLog(joinPoint); if (controllerDataScope == null) { return; } // 获取当前的用户 SysUser currentUser = ShiroUtils.getSysUser(); if (ObjectUtil.isNotNull(currentUser) && !currentUser.isAdmin()) { // 如果是超级管理员,则不过滤数据 dataScopeFilter(joinPoint, currentUser, controllerDataScope.tableAlias()); } }
Example 14
Source File: OnlineSessionFilter.java From supplierShop with MIT License | 5 votes |
/** * 表示是否允许访问;mappedValue就是[urls]配置中拦截器参数部分,如果允许访问返回true,否则false; */ @Override protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { Subject subject = getSubject(request, response); if (subject == null || subject.getSession() == null) { return true; } Session session = onlineSessionDAO.readSession(subject.getSession().getId()); if (session != null && session instanceof OnlineSession) { OnlineSession onlineSession = (OnlineSession) session; request.setAttribute(ShiroConstants.ONLINE_SESSION, onlineSession); // 把user对象设置进去 boolean isGuest = onlineSession.getUserId() == null || onlineSession.getUserId() == 0L; if (isGuest == true) { SysUser user = ShiroUtils.getSysUser(); if (user != null) { onlineSession.setUserId(user.getUserId()); onlineSession.setLoginName(user.getLoginName()); onlineSession.setAvatar(user.getAvatar()); onlineSession.setDeptName(user.getDept().getDeptName()); onlineSession.markAttributeChanged(); } } if (onlineSession.getStatus() == OnlineStatus.off_line) { return false; } } return true; }
Example 15
Source File: LogoutFilter.java From supplierShop with MIT License | 5 votes |
@Override protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception { try { Subject subject = getSubject(request, response); String redirectUrl = getRedirectUrl(request, response, subject); try { SysUser user = ShiroUtils.getSysUser(); if (StringUtils.isNotNull(user)) { String loginName = user.getLoginName(); // 记录用户退出日志 AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success"))); // 清理缓存 cache.remove(loginName); } // 退出登录 subject.logout(); } catch (SessionException ise) { log.error("logout fail.", ise); } issueRedirect(request, response, redirectUrl); } catch (Exception e) { log.error("Encountered session exception during logout. This can generally safely be ignored.", e); } return false; }
Example 16
Source File: LoginUserArgumentResolver.java From RuoYi with Apache License 2.0 | 4 votes |
@Override public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory){ return ShiroUtils.getSysUser(); }
Example 17
Source File: BaseController.java From RuoYi with Apache License 2.0 | 4 votes |
public SysUser getSysUser() { return ShiroUtils.getSysUser(); }
Example 18
Source File: LogAspect.java From ruoyiplus with MIT License | 4 votes |
protected void handleLog(final JoinPoint joinPoint, final Exception e) { try { // 获得注解 Log controllerLog = getAnnotationLog(joinPoint); if (controllerLog == null) { return; } // 获取当前的用户 SysUser currentUser = ShiroUtils.getSysUser(); // *========数据库日志=========*// SysOperLog operLog = new SysOperLog(); operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); // 请求的地址 String ip = ShiroUtils.getIp(); operLog.setOperIp(ip); operLog.setOperUrl(ServletUtils.getRequest().getRequestURI()); if (currentUser != null) { operLog.setOperName(currentUser.getLoginName()); if (StringUtils.isNotNull(currentUser.getDept()) && StringUtils.isNotEmpty(currentUser.getDept().getDeptName())) { operLog.setDeptName(currentUser.getDept().getDeptName()); } } if (e != null) { operLog.setStatus(BusinessStatus.FAIL.ordinal()); operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); } // 设置方法名称 String className = joinPoint.getTarget().getClass().getName(); String methodName = joinPoint.getSignature().getName(); operLog.setMethod(className + "." + methodName + "()"); // 处理设置注解上的参数 getControllerMethodDescription(controllerLog, operLog); // 保存数据库 AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); } catch (Exception exp) { // 记录本地异常日志 log.error("==前置通知异常=="); log.error("异常信息:{}", exp.getMessage()); exp.printStackTrace(); } }
Example 19
Source File: BaseController.java From ruoyiplus with MIT License | 4 votes |
public SysUser getSysUser() { return ShiroUtils.getSysUser(); }
Example 20
Source File: LogAspect.java From supplierShop with MIT License | 4 votes |
protected void handleLog(final JoinPoint joinPoint, final Exception e) { try { // 获得注解 Log controllerLog = getAnnotationLog(joinPoint); if (controllerLog == null) { return; } // 获取当前的用户 SysUser currentUser = ShiroUtils.getSysUser(); // *========数据库日志=========*// SysOperLog operLog = new SysOperLog(); operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); // 请求的地址 String ip = ShiroUtils.getIp(); operLog.setOperIp(ip); operLog.setOperUrl(ServletUtils.getRequest().getRequestURI()); if (currentUser != null) { operLog.setOperName(currentUser.getLoginName()); if (StringUtils.isNotNull(currentUser.getDept()) && StringUtils.isNotEmpty(currentUser.getDept().getDeptName())) { operLog.setDeptName(currentUser.getDept().getDeptName()); } } if (e != null) { operLog.setStatus(BusinessStatus.FAIL.ordinal()); operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); } // 设置方法名称 String className = joinPoint.getTarget().getClass().getName(); String methodName = joinPoint.getSignature().getName(); operLog.setMethod(className + "." + methodName + "()"); // 处理设置注解上的参数 getControllerMethodDescription(controllerLog, operLog); // 保存数据库 AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); } catch (Exception exp) { // 记录本地异常日志 log.error("==前置通知异常=="); log.error("异常信息:{}", exp.getMessage()); exp.printStackTrace(); } }