use of com.moon.admin.service.TokenManager in project moon by gentoo111.
the class LogoutFilter method preHandle.
@Override
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
String loginToken = RestfulFilter.getToken(request);
User user = UserUtil.getCurrentUser();
if (StringUtils.isBlank(loginToken)) {
// 非Restful方式
boolean flag = super.preHandle(request, response);
log.debug("{}退出成功", user.getUsername());
SpringUtil.getBean(SysLogService.class).save(user.getId(), "退出", true, null);
return flag;
} else {
TokenManager tokenManager = SpringUtil.getBean(TokenManager.class);
boolean flag = tokenManager.deleteToken(loginToken);
if (flag) {
RestfulFilter.writeResponse(WebUtils.toHttp(response), HttpStatus.OK.value(), SUCCESS_INFO);
log.debug("{}退出成功", user.getUsername());
} else {
RestfulFilter.writeResponse(WebUtils.toHttp(response), HttpStatus.BAD_REQUEST.value(), ERR_INFO);
}
SpringUtil.getBean(SysLogService.class).save(user.getId(), "token方式退出", flag, null);
return false;
}
}
use of com.moon.admin.service.TokenManager in project moon by gentoo111.
the class RestfulFilter method isAccessAllowed.
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
String loginToken = getToken(request);
if (StringUtils.isBlank(loginToken)) {
// 非Restful方式
return super.isAccessAllowed(request, response, mappedValue);
}
TokenManager tokenManager = SpringUtil.getBean(TokenManager.class);
UsernamePasswordToken token = tokenManager.getToken(loginToken);
if (token != null) {
try {
Subject subject = getSubject(request, response);
if (subject.getPrincipal() == null) {
subject.login(token);
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
Aggregations