Search in sources :

Example 6 with LoginUser

use of com.dimple.framework.security.LoginUser in project DimpleBlog by martin-chips.

the class LoginController method getInfo.

/**
 * 获取用户信息
 *
 * @return 用户信息
 */
@GetMapping("getInfo")
public AjaxResult getInfo() {
    LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
    SysUser user = loginUser.getUser();
    // 角色集合
    Set<String> roles = permissionService.getRolePermission(user);
    // 权限集合
    Set<String> permissions = permissionService.getMenuPermission(user);
    AjaxResult ajax = AjaxResult.success();
    ajax.put("user", user);
    ajax.put("roles", roles);
    ajax.put("permissions", permissions);
    return ajax;
}
Also used : AjaxResult(com.dimple.framework.web.domain.AjaxResult) SysUser(com.dimple.project.system.domain.SysUser) LoginUser(com.dimple.framework.security.LoginUser) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 7 with LoginUser

use of com.dimple.framework.security.LoginUser in project DimpleBlog by martin-chips.

the class ProfileController method profile.

/**
 * 个人信息
 */
@GetMapping
public AjaxResult profile() {
    LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
    SysUser user = loginUser.getUser();
    AjaxResult ajax = AjaxResult.success(user);
    ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername()));
    return ajax;
}
Also used : AjaxResult(com.dimple.framework.web.domain.AjaxResult) SysUser(com.dimple.project.system.domain.SysUser) LoginUser(com.dimple.framework.security.LoginUser) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 8 with LoginUser

use of com.dimple.framework.security.LoginUser in project DimpleBlog by martin-chips.

the class ProfileController method updatePwd.

/**
 * 重置密码
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping("/updatePwd")
public AjaxResult updatePwd(String oldPassword, String newPassword) {
    LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
    String userName = loginUser.getUsername();
    String password = loginUser.getPassword();
    if (!SecurityUtils.matchesPassword(oldPassword, password)) {
        return AjaxResult.error("修改密码失败,旧密码错误");
    }
    if (SecurityUtils.matchesPassword(newPassword, password)) {
        return AjaxResult.error("新密码不能与旧密码相同");
    }
    return toAjax(userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)));
}
Also used : LoginUser(com.dimple.framework.security.LoginUser) Log(com.dimple.framework.aspectj.lang.annotation.Log) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 9 with LoginUser

use of com.dimple.framework.security.LoginUser in project DimpleBlog by martin-chips.

the class LogoutSuccessHandlerImpl method onLogoutSuccess.

/**
 * 退出处理
 */
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
    LoginUser loginUser = tokenService.getLoginUser(request);
    if (StringUtils.isNotNull(loginUser)) {
        String userName = loginUser.getUsername();
        // 删除用户缓存记录
        tokenService.delLoginUser(loginUser.getToken());
        // 记录用户退出日志
        AsyncManager.me().execute(AsyncFactory.recordLoginLog(userName, Constants.SUCCESS, "退出成功"));
    }
    ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(HttpStatus.OK, "退出成功")));
}
Also used : LoginUser(com.dimple.framework.security.LoginUser)

Example 10 with LoginUser

use of com.dimple.framework.security.LoginUser in project DimpleBlog by martin-chips.

the class PermissionService method hasAnyPermi.

/**
 * 验证用户是否具有以下任意一个权限
 *
 * @param permissions 以 PERMISSION_NAMES_DELIMETER 为分隔符的权限列表
 * @return 用户是否具有以下任意一个权限
 */
public boolean hasAnyPermi(String permissions) {
    if (StringUtils.isEmpty(permissions)) {
        return false;
    }
    LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
    if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) {
        return false;
    }
    Set<String> authorities = loginUser.getPermissions();
    for (String permission : permissions.split(PERMISSION_DELIMETER)) {
        if (permission != null && hasPermissions(authorities, permission)) {
            return true;
        }
    }
    return false;
}
Also used : LoginUser(com.dimple.framework.security.LoginUser)

Aggregations

LoginUser (com.dimple.framework.security.LoginUser)11 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 SysUser (com.dimple.project.system.domain.SysUser)3 Log (com.dimple.framework.aspectj.lang.annotation.Log)2 AjaxResult (com.dimple.framework.web.domain.AjaxResult)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 CustomException (com.dimple.common.exception.CustomException)1 CaptchaException (com.dimple.common.exception.user.CaptchaException)1 CaptchaExpireException (com.dimple.common.exception.user.CaptchaExpireException)1 UserPasswordNotMatchException (com.dimple.common.exception.user.UserPasswordNotMatchException)1 TokenService (com.dimple.framework.security.service.TokenService)1 OperateLog (com.dimple.project.log.domain.OperateLog)1 UserOnline (com.dimple.project.monitor.domain.UserOnline)1 Menu (com.dimple.project.system.domain.Menu)1 ArrayList (java.util.ArrayList)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 Authentication (org.springframework.security.core.Authentication)1 WebAuthenticationDetailsSource (org.springframework.security.web.authentication.WebAuthenticationDetailsSource)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1