From acdcf5b25c387652453f6f4ae55321a47408903b Mon Sep 17 00:00:00 2001 From: dinggang <2498628697@qq.com> Date: Tue, 15 Nov 2022 16:50:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E5=A4=9A=E5=9C=B0=E5=90=8C=E6=97=B6=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E5=8A=9F=E8=83=BD=202.=E5=8E=BB=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E6=B3=A8=E5=85=A5=203.=E4=BA=91=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=92=8C=E4=BA=91=E8=A7=86=E9=A2=91=E8=B0=83=E7=94=A8=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=204.=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E7=AE=A1=E7=90=86=E6=96=B0=E5=A2=9E=E6=8C=89=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E6=A8=A1=E7=B3=8A=E6=9F=A5=E8=AF=A2=205.=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=AD=97=E5=85=B8=E8=A1=A8=E6=96=B0=E5=A2=9E=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ResourceController.java | 27 ------------------- .../service/impl/ResourceServiceImpl.java | 17 ++++++++++-- .../modules/security/oauth2/Oauth2Realm.java | 19 +++++++++++-- .../sys/controller/SysMenuController.java | 4 +-- .../io/renren/modules/sys/dao/SysMenuDao.java | 2 +- .../modules/sys/service/SysMenuService.java | 2 +- .../sys/service/impl/SysMenuServiceImpl.java | 6 ++--- .../src/main/resources/db/R__del_token.sql | 7 +++++ .../main/resources/db/V7.3__add_sys_data.sql | 11 ++++++++ .../mapper/sys/AbilityApplicationService.xml | 26 ------------------ .../main/resources/mapper/sys/SysMenuDao.xml | 16 +++++++---- .../resources/mapper/sys/SysUserTokenDao.xml | 2 +- 12 files changed, 69 insertions(+), 70 deletions(-) create mode 100644 renren-admin/src/main/resources/db/R__del_token.sql create mode 100644 renren-admin/src/main/resources/db/V7.3__add_sys_data.sql delete mode 100644 renren-admin/src/main/resources/mapper/sys/AbilityApplicationService.xml diff --git a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java index 836306fe..fc628c0f 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java @@ -82,33 +82,6 @@ public class ResourceController { @Value("${qdyjj.ipAndPort}") private String ipAndPort; - @Value("${zsk.appid}") - private String appId; - - @Value("${zsk.appkey}") - private String appKey; - - @Value("${zsk.url.sign}") - private String sign; - - @Value("${zsk.url.gateway}") - private String gateway; - - @Value("${zsk.methodId}") - private String methodId; - - @Value("${zsk.param.charset}") - private String charset; - - @Value("${zsk.param.origin}") - private String origin; - - @Value("${zsk.param.version}") - private String version; - - @Value("${zsk.catalogIds}") - private String[] catalogIds; - @Value("${resource.path}") private String uploadPath; diff --git a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java index c472dd83..3efa2614 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java @@ -83,6 +83,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; @@ -2742,7 +2743,13 @@ public class ResourceServiceImpl extends CrudServiceImpl requestEntity = new HttpEntity(param, new HttpHeaders()); - return restTemplate.postForEntity("http://15.72.183.88:8760/yzy/main/cloudresource/getResourceBusinessList", requestEntity, String.class).getBody(); + String body; + try { + body = restTemplate.postForEntity("http://15.72.183.88:8760/yzy/main/cloudresource/getResourceBusinessList", requestEntity, String.class).getBody(); + } catch (RestClientException e) { + throw new RuntimeException("云资源数据查询失败!"); + } + return body; } @Override @@ -2752,7 +2759,13 @@ public class ResourceServiceImpl extends CrudServiceImpl requestEntity = new HttpEntity(param, new HttpHeaders()); - return restTemplate.postForEntity("http://15.72.183.88:8760/yzy/main/cloudresource/getVideoBusinessList", requestEntity, String.class).getBody(); + String body; + try { + body = restTemplate.postForEntity("http://15.72.183.88:8760/yzy/main/cloudresource/getVideoBusinessList", requestEntity, String.class).getBody(); + } catch (RestClientException e) { + throw new RuntimeException("云视频查询失败!"); + } + return body; } } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/security/oauth2/Oauth2Realm.java b/renren-admin/src/main/java/io/renren/modules/security/oauth2/Oauth2Realm.java index 4e1a7d41..88f2405e 100644 --- a/renren-admin/src/main/java/io/renren/modules/security/oauth2/Oauth2Realm.java +++ b/renren-admin/src/main/java/io/renren/modules/security/oauth2/Oauth2Realm.java @@ -13,6 +13,7 @@ import org.apache.shiro.authz.SimpleAuthorizationInfo; import org.apache.shiro.realm.AuthorizingRealm; import org.apache.shiro.subject.PrincipalCollection; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.util.List; @@ -26,6 +27,9 @@ public class Oauth2Realm extends AuthorizingRealm { @Autowired private ShiroService shiroService; + @Value("${system.allowSimultaneousLogin}") + private int allowSimultaneousLogin; + @Override public boolean supports(AuthenticationToken token) { return token instanceof Oauth2Token; @@ -55,8 +59,15 @@ public class Oauth2Realm extends AuthorizingRealm { //根据accessToken,查询用户信息 SysUserTokenEntity tokenEntity = shiroService.getByToken(accessToken); + + //判断是否允许同时登录,0:不允许,1:允许 + //允许同时在线时不校验过期时间 + if (allowSimultaneousLogin != 1 && tokenEntity.getExpireDate().getTime() < System.currentTimeMillis()) { + throw new IncorrectCredentialsException(MessageUtils.getMessage(ErrorCode.TOKEN_INVALID)); + } + //token失效 - if (tokenEntity == null || tokenEntity.getExpireDate().getTime() < System.currentTimeMillis()) { + if (tokenEntity == null) { throw new IncorrectCredentialsException(MessageUtils.getMessage(ErrorCode.TOKEN_INVALID)); } @@ -66,11 +77,15 @@ public class Oauth2Realm extends AuthorizingRealm { //转换成UserDetail对象 UserDetail userDetail = ConvertUtils.sourceToTarget(userEntity, UserDetail.class); - //账号锁定 + //账号停用 if (userDetail.getStatus() == 0) { throw new LockedAccountException(MessageUtils.getMessage(ErrorCode.ACCOUNT_LOCK)); } + if (userDetail.getStatus() == 2) { + throw new LockedAccountException(MessageUtils.getMessage(500 ,"账号已锁定!")); + } + //获取用户对应的部门数据权限 List deptIdList = shiroService.getDataScopeList(userDetail.getId()); userDetail.setDeptIdList(deptIdList); diff --git a/renren-admin/src/main/java/io/renren/modules/sys/controller/SysMenuController.java b/renren-admin/src/main/java/io/renren/modules/sys/controller/SysMenuController.java index cb808686..b56a5de4 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/controller/SysMenuController.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/controller/SysMenuController.java @@ -55,8 +55,8 @@ public class SysMenuController { @ApiOperation("列表") @ApiImplicitParam(name = "type", value = "菜单类型 0:菜单 1:按钮 null:全部", paramType = "query", dataType = "int") // @RequiresPermissions("sys:menu:list") - public Result> list(Integer type) { - List list = sysMenuService.getAllMenuList(type); + public Result> list(Integer type, String name) { + List list = sysMenuService.getAllMenuList(type, name); return new Result>().ok(list); } diff --git a/renren-admin/src/main/java/io/renren/modules/sys/dao/SysMenuDao.java b/renren-admin/src/main/java/io/renren/modules/sys/dao/SysMenuDao.java index e9470d12..4a1467a2 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/dao/SysMenuDao.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/dao/SysMenuDao.java @@ -21,7 +21,7 @@ public interface SysMenuDao extends BaseDao { * @param type 菜单类型 * @param language 语言 */ - List getMenuList(@Param("type") Integer type, @Param("language") String language); + List getMenuList(@Param("type") Integer type, @Param("language") String language, @Param("name") String name); /** * 查询用户菜单列表 diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/SysMenuService.java b/renren-admin/src/main/java/io/renren/modules/sys/service/SysMenuService.java index 28c007f4..57a8a328 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/SysMenuService.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/SysMenuService.java @@ -26,7 +26,7 @@ public interface SysMenuService extends BaseService { * * @param type 菜单类型 */ - List getAllMenuList(Integer type); + List getAllMenuList(Integer type, String name); /** * 用户菜单列表 diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysMenuServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysMenuServiceImpl.java index a505fa67..f97029c7 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysMenuServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysMenuServiceImpl.java @@ -76,8 +76,8 @@ public class SysMenuServiceImpl extends BaseServiceImpl getAllMenuList(Integer type) { - List menuList = baseDao.getMenuList(type, HttpContextUtils.getLanguage()); + public List getAllMenuList(Integer type, String name) { + List menuList = baseDao.getMenuList(type, HttpContextUtils.getLanguage(), name); List dtoList = ConvertUtils.sourceToTarget(menuList, SysMenuDTO.class); @@ -90,7 +90,7 @@ public class SysMenuServiceImpl extends BaseServiceImpl - - - - - - - - - - update sys_user_token set expire_date = #{expireDate} where user_id = #{userId} - - - - \ No newline at end of file diff --git a/renren-admin/src/main/resources/mapper/sys/SysMenuDao.xml b/renren-admin/src/main/resources/mapper/sys/SysMenuDao.xml index bae830e0..8832dd90 100644 --- a/renren-admin/src/main/resources/mapper/sys/SysMenuDao.xml +++ b/renren-admin/src/main/resources/mapper/sys/SysMenuDao.xml @@ -14,14 +14,20 @@ diff --git a/renren-admin/src/main/resources/mapper/sys/SysUserTokenDao.xml b/renren-admin/src/main/resources/mapper/sys/SysUserTokenDao.xml index a740f630..29328e61 100644 --- a/renren-admin/src/main/resources/mapper/sys/SysUserTokenDao.xml +++ b/renren-admin/src/main/resources/mapper/sys/SysUserTokenDao.xml @@ -8,7 +8,7 @@ From 7e54dcebba6a68d2408b79fe7b5e4f90d5e93c9a Mon Sep 17 00:00:00 2001 From: dinggang <2498628697@qq.com> Date: Tue, 15 Nov 2022 16:52:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=BC=8F=E6=8F=90=E4=BA=86...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SysUserTokenServiceImpl.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/renren-admin/src/main/java/io/renren/modules/security/service/impl/SysUserTokenServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/security/service/impl/SysUserTokenServiceImpl.java index afc3307b..5b2460e3 100644 --- a/renren-admin/src/main/java/io/renren/modules/security/service/impl/SysUserTokenServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/security/service/impl/SysUserTokenServiceImpl.java @@ -12,6 +12,7 @@ import io.renren.modules.security.entity.SysUserTokenEntity; import io.renren.modules.security.oauth2.TokenGenerator; import io.renren.modules.security.service.SysUserTokenService; import io.renren.modules.sys.entity.SysOnlineEntity; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.Date; @@ -21,11 +22,17 @@ import java.util.Map; @Service public class SysUserTokenServiceImpl extends BaseServiceImpl implements SysUserTokenService { + + /** * 12小时后过期 */ private final static int EXPIRE = 3600 * 12; + @Value("${system.allowSimultaneousLogin}") + private int allowSimultaneousLogin; + + /* @Override public Result createToken(Long userId) { //用户token @@ -81,6 +88,56 @@ public class SysUserTokenServiceImpl extends BaseServiceImpl map = new HashMap<>(2); + map.put(Constant.TOKEN_HEADER, token); + map.put("expire", EXPIRE); + return new Result().ok(map); + } + @Override public void logout(Long userId) {