Search in sources :

Example 1 with LogLoginDo

use of com.albedo.java.modules.sys.domain.LogLoginDo in project albedo by somowhere.

the class AjaxAuthenticationFailureHandler method onAuthenticationFailure.

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) {
    String username = request.getParameter("username");
    LoginUtil.isValidateCodeLogin(username, true, false);
    String message = exception instanceof BadCredentialsException && "Bad credentials".equals(exception.getMessage()) ? "密码填写错误!" : exception.getMessage();
    LogLoginDo logLoginDo = SysLogUtils.getSysLogLogin();
    logLoginDo.setParams(HttpUtil.toParams(request.getParameterMap()));
    logLoginDo.setUsername(username);
    try {
        UserDetail userDetails = (UserDetail) userDetailsService.loadUserByUsername(username);
        if (userDetails != null) {
            logLoginDo.setCreatedBy(userDetails.getId());
        }
    } catch (Exception e) {
        log.debug("can not find createId by username[{}]", username);
    }
    logLoginDo.setTitle("用户登录失败");
    logLoginDo.setDescription(message);
    AsyncUtil.recordLogLogin(logLoginDo);
    response.setStatus(HttpServletResponse.SC_OK);
    WebUtil.renderJson(response, Result.buildFail(message));
}
Also used : UserDetail(com.albedo.java.common.security.service.UserDetail) LogLoginDo(com.albedo.java.modules.sys.domain.LogLoginDo) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) AuthenticationException(org.springframework.security.core.AuthenticationException)

Example 2 with LogLoginDo

use of com.albedo.java.modules.sys.domain.LogLoginDo in project albedo by somowhere.

the class AjaxAuthenticationSuccessHandler method onAuthenticationSuccess.

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
    response.setStatus(HttpServletResponse.SC_OK);
    String useruame = request.getParameter("username");
    LoginUtil.isValidateCodeLogin(useruame, false, true);
    UserOnlineDo userOnlineDo = LoginUtil.getUserOnline(authentication);
    SpringContextHolder.publishEvent(new SysUserOnlineEvent(userOnlineDo));
    LogLoginDo logLoginDo = SysLogUtils.getSysLogLogin();
    logLoginDo.setParams(HttpUtil.toParams(request.getParameterMap()));
    logLoginDo.setUsername(useruame);
    logLoginDo.setTitle("用户登录");
    AsyncUtil.recordLogLogin(logLoginDo);
    WebUtil.renderJson(response, Result.buildOk("登录成功"));
}
Also used : SysUserOnlineEvent(com.albedo.java.common.security.event.SysUserOnlineEvent) LogLoginDo(com.albedo.java.modules.sys.domain.LogLoginDo) UserOnlineDo(com.albedo.java.modules.sys.domain.UserOnlineDo)

Example 3 with LogLoginDo

use of com.albedo.java.modules.sys.domain.LogLoginDo in project albedo by somowhere.

the class SysLogLoginListener method saveSysLog.

@Async
@Order
@EventListener(SysLogLoginEvent.class)
public void saveSysLog(SysLogLoginEvent event) {
    LogLoginDo logLoginDo = (LogLoginDo) event.getSource();
    logLoginService.save(logLoginDo);
}
Also used : LogLoginDo(com.albedo.java.modules.sys.domain.LogLoginDo) Order(org.springframework.core.annotation.Order) Async(org.springframework.scheduling.annotation.Async) EventListener(org.springframework.context.event.EventListener)

Example 4 with LogLoginDo

use of com.albedo.java.modules.sys.domain.LogLoginDo in project albedo by somowhere.

the class LogLoginResource method download.

@LogOperate(value = "登录日志导出")
@Operation(summary = "登录日志导出")
@GetMapping(value = "/download")
@PreAuthorize("@pms.hasPermission('sys_logOperate_export')")
public void download(LogLoginQueryCriteria logOperateQueryCriteria, HttpServletResponse response) {
    QueryWrapper wrapper = QueryWrapperUtil.getWrapper(logOperateQueryCriteria);
    ExcelUtil<LogLoginDo> util = new ExcelUtil(LogLoginDo.class);
    util.exportExcel(service.list(wrapper), "登录日志", response);
}
Also used : ExcelUtil(com.albedo.java.common.util.ExcelUtil) LogLoginDo(com.albedo.java.modules.sys.domain.LogLoginDo) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LogOperate(com.albedo.java.common.log.annotation.LogOperate) Operation(io.swagger.v3.oas.annotations.Operation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

LogLoginDo (com.albedo.java.modules.sys.domain.LogLoginDo)4 LogOperate (com.albedo.java.common.log.annotation.LogOperate)1 SysUserOnlineEvent (com.albedo.java.common.security.event.SysUserOnlineEvent)1 UserDetail (com.albedo.java.common.security.service.UserDetail)1 ExcelUtil (com.albedo.java.common.util.ExcelUtil)1 UserOnlineDo (com.albedo.java.modules.sys.domain.UserOnlineDo)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 Operation (io.swagger.v3.oas.annotations.Operation)1 EventListener (org.springframework.context.event.EventListener)1 Order (org.springframework.core.annotation.Order)1 Async (org.springframework.scheduling.annotation.Async)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1