Merge remote-tracking branch 'origin/master'

This commit is contained in:
flower 2019-01-28 23:16:28 +08:00
commit 1e350c0060
7 changed files with 78 additions and 75 deletions

View File

@ -165,7 +165,6 @@ public class ExamQuestionServiceImpl extends AbstractBaseServiceImpl<ExamQuestio
@Override
public List<ExamQuestionVO> selectQuestionListByPracticeId(Map<String, Object> map) {
// startPage();
return examQuestionMapper.selectQuestionListByPracticeId(map);
}

View File

@ -1,10 +1,12 @@
package com.ruoyi.framework.jwt;
import cn.hutool.core.util.StrUtil;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.ruoyi.framework.web.exception.user.UserNotExistsException;
import com.ruoyi.framework.web.util.ServletUtils;
import java.util.Date;
@ -49,10 +51,14 @@ public class JwtUtil {
try {
String token = ServletUtils.getRequest().getHeader("Authorization");
DecodedJWT jwt = JWT.decode(token);
String loginName = jwt.getClaim( "loginName" ).asString();
// jwt.getExpiresAt();
return jwt.getClaim("loginName").asString();
if (StrUtil.isBlank( loginName )) {
throw new UserNotExistsException();
}
return loginName;
} catch (JWTDecodeException e) {
return null;
throw new UserNotExistsException();
}
}

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.shiro.session.ExpiredSessionException;
import org.apache.shiro.session.InvalidSessionException;
@ -21,54 +22,44 @@ import com.ruoyi.system.service.ISysUserOnlineService;
/**
* 主要是在此如果会话的属性修改了 就标识下其修改了 然后方便 OnlineSessionDao同步
*
*
* @author ruoyi
*/
public class OnlineWebSessionManager extends DefaultWebSessionManager
{
private static final Logger log = LoggerFactory.getLogger(OnlineWebSessionManager.class);
public class OnlineWebSessionManager extends DefaultWebSessionManager {
private static final Logger log = LoggerFactory.getLogger( OnlineWebSessionManager.class );
@Override
public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException
{
super.setAttribute(sessionKey, attributeKey, value);
if (value != null && needMarkAttributeChanged(attributeKey))
{
OnlineSession s = (OnlineSession) doGetSession(sessionKey);
public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException {
super.setAttribute( sessionKey, attributeKey, value );
if (value != null && needMarkAttributeChanged( attributeKey )) {
OnlineSession s = (OnlineSession) doGetSession( sessionKey );
s.markAttributeChanged();
}
}
private boolean needMarkAttributeChanged(Object attributeKey)
{
if (attributeKey == null)
{
private boolean needMarkAttributeChanged(Object attributeKey) {
if (attributeKey == null) {
return false;
}
String attributeKeyStr = attributeKey.toString();
// 优化 flash属性没必要持久化
if (attributeKeyStr.startsWith("org.springframework"))
{
if (attributeKeyStr.startsWith( "org.springframework" )) {
return false;
}
if (attributeKeyStr.startsWith("javax.servlet"))
{
if (attributeKeyStr.startsWith( "javax.servlet" )) {
return false;
}
if (attributeKeyStr.equals(ShiroConstants.CURRENT_USERNAME))
{
if (attributeKeyStr.equals( ShiroConstants.CURRENT_USERNAME )) {
return false;
}
return true;
}
@Override
public Object removeAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException
{
Object removed = super.removeAttribute(sessionKey, attributeKey);
if (removed != null)
{
OnlineSession s = (OnlineSession) doGetSession(sessionKey);
public Object removeAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException {
Object removed = super.removeAttribute( sessionKey, attributeKey );
if (removed != null) {
OnlineSession s = (OnlineSession) doGetSession( sessionKey );
s.markAttributeChanged();
}
@ -79,77 +70,60 @@ public class OnlineWebSessionManager extends DefaultWebSessionManager
* 验证session是否有效 用于删除过期session
*/
@Override
public void validateSessions()
{
if (log.isInfoEnabled())
{
log.info("invalidation sessions...");
public void validateSessions() {
if (log.isInfoEnabled()) {
log.info( "invalidation sessions..." );
}
int invalidCount = 0;
int timeout = (int) this.getGlobalSessionTimeout();
Date expiredDate = DateUtils.addMilliseconds(new Date(), 0 - timeout);
ISysUserOnlineService userOnlineService = SpringUtils.getBean(ISysUserOnlineService.class);
List<SysUserOnline> userOnlineList = userOnlineService.selectOnlineByExpired(expiredDate);
Date expiredDate = DateUtils.addMilliseconds( new Date(), 0 - timeout );
ISysUserOnlineService userOnlineService = SpringUtils.getBean( ISysUserOnlineService.class );
List<SysUserOnline> userOnlineList = userOnlineService.selectOnlineByExpired( expiredDate );
// 批量过期删除
List<String> needOfflineIdList = new ArrayList<String>();
for (SysUserOnline userOnline : userOnlineList)
{
try
{
SessionKey key = new DefaultSessionKey(userOnline.getSessionId());
Session session = retrieveSession(key);
if (session != null)
{
for (SysUserOnline userOnline : userOnlineList) {
try {
SessionKey key = new DefaultSessionKey( userOnline.getSessionId() );
Session session = retrieveSession( key );
if (session != null) {
throw new InvalidSessionException();
}
}
catch (InvalidSessionException e)
{
if (log.isDebugEnabled())
{
} catch (InvalidSessionException e) {
if (log.isDebugEnabled()) {
boolean expired = (e instanceof ExpiredSessionException);
String msg = "Invalidated session with id [" + userOnline.getSessionId() + "]"
+ (expired ? " (expired)" : " (stopped)");
log.debug(msg);
log.debug( msg );
}
invalidCount++;
needOfflineIdList.add(userOnline.getSessionId());
needOfflineIdList.add( userOnline.getSessionId() );
}
}
if (needOfflineIdList.size() > 0)
{
try
{
userOnlineService.batchDeleteOnline(needOfflineIdList);
}
catch (Exception e)
{
log.error("batch delete db session error.", e);
if (needOfflineIdList.size() > 0) {
try {
userOnlineService.batchDeleteOnline( needOfflineIdList );
} catch (Exception e) {
log.error( "batch delete db session error.", e );
}
}
if (log.isInfoEnabled())
{
if (log.isInfoEnabled()) {
String msg = "Finished invalidation session.";
if (invalidCount > 0)
{
if (invalidCount > 0) {
msg += " [" + invalidCount + "] sessions were stopped.";
}
else
{
} else {
msg += " No sessions were stopped.";
}
log.info(msg);
log.info( msg );
}
}
@Override
protected Collection<Session> getActiveSessions()
{
throw new UnsupportedOperationException("getActiveSessions method not supported");
protected Collection<Session> getActiveSessions() {
throw new UnsupportedOperationException( "getActiveSessions method not supported" );
}
}

View File

@ -1,5 +1,6 @@
package com.ruoyi.framework.web.exception;
import com.ruoyi.framework.web.exception.user.UserNotExistsException;
import org.apache.shiro.authz.AuthorizationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -39,7 +40,15 @@ public class DefaultExceptionHandler
log.error(e.getMessage(), e);
return AjaxResult.error("不支持' " + e.getMethod() + "'请求");
}
/**
* 拦截未知的运行时异常
*/
@ExceptionHandler(UserNotExistsException.class)
public AjaxResult userNotFound(UserNotExistsException e)
{
log.error("运行时异常:", e);
return AjaxResult.error(302,"运行时异常:" + e.getMessage());
}
/**
* 拦截未知的运行时异常
*/

View File

@ -1,9 +1,12 @@
package com.ruoyi.system.service.impl;
import java.nio.file.attribute.UserPrincipalNotFoundException;
import java.util.ArrayList;
import java.util.List;
import com.ruoyi.framework.web.base.AbstractBaseServiceImpl;
import com.ruoyi.framework.web.exception.user.UserException;
import com.ruoyi.framework.web.exception.user.UserNotExistsException;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
@ -57,6 +60,7 @@ public class SysUserServiceImpl extends AbstractBaseServiceImpl<SysUserMapper, S
*/
@Override
public SysUser selectUserByLoginName(String userName) {
return userMapper.selectUserByLoginName( userName );
}

View File

@ -10,6 +10,15 @@ public class VipUserOrdersVO extends VipUserOrders {
private String vipUserName;
private String trainCourseName;
private String trainCourseCover;
public String getTrainCourseCover() {
return trainCourseCover;
}
public void setTrainCourseCover(String trainCourseCover) {
this.trainCourseCover = trainCourseCover;
}
public String getVipUserName() {
return vipUserName;

View File

@ -17,6 +17,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="delFlag" column="del_flag" />
<result property="vipUserName" column="vipUserName" />
<result property="trainCourseName" column="trainCourseName" />
<result property="trainCourseCover" column="trainCourseCover" />
</resultMap>
<sql id="selectVipUserOrdersVo">
@ -26,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectVipUserOrdersList" parameterType="VipUserOrdersVO" resultMap="VipUserOrdersResult">
select
<include refid="selectVipUserOrdersVo"/>,
u.user_name vipUserName,c.name trainCourseName
u.user_name vipUserName,c.name trainCourseName,c.cover trainCourseCover
from vip_user_orders o
join sys_user u on u.user_id=o.vip_user_id
join train_course c on c.id=o.train_course_id