diff --git a/config/db/V3.1__sys_user_token_drop_index.sql b/config/db/V3.1__sys_user_token_drop_index.sql new file mode 100644 index 00000000..91682ede --- /dev/null +++ b/config/db/V3.1__sys_user_token_drop_index.sql @@ -0,0 +1,23 @@ +DROP PROCEDURE IF EXISTS del_idx; + +create procedure del_idx(IN p_tablename varchar(200), IN p_idxname VARCHAR(200)) + +begin + +DECLARE str VARCHAR(250); + +set @str=concat(' drop index ',p_idxname,' on ',p_tablename); + +select count(*) into @cnt from information_schema.statistics where table_name=p_tablename and index_name=p_idxname ; + +if @cnt >0 then + +PREPARE stmt FROM @str; + +EXECUTE stmt ; + +end if; + +end ; + +call del_idx('sys_user_token','user_id'); \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/common/interceptor/YaweiSSOProperties.java b/renren-admin/src/main/java/io/renren/common/interceptor/YaweiSSOProperties.java index d50e7542..a6e48645 100644 --- a/renren-admin/src/main/java/io/renren/common/interceptor/YaweiSSOProperties.java +++ b/renren-admin/src/main/java/io/renren/common/interceptor/YaweiSSOProperties.java @@ -13,4 +13,5 @@ public class YaweiSSOProperties { private String domain; private String ssoKey; private String keeperUrl; + private String logoutUrl; } diff --git a/renren-admin/src/main/java/io/renren/modules/security/controller/LoginController.java b/renren-admin/src/main/java/io/renren/modules/security/controller/LoginController.java index 8ca7443b..aa3d1d42 100644 --- a/renren-admin/src/main/java/io/renren/modules/security/controller/LoginController.java +++ b/renren-admin/src/main/java/io/renren/modules/security/controller/LoginController.java @@ -13,6 +13,7 @@ import io.renren.modules.log.enums.LoginStatusEnum; import io.renren.modules.log.service.SysLogLoginService; import io.renren.modules.security.dto.LoginDTO; import io.renren.modules.security.oauth2.Oauth2Filter; +import io.renren.modules.security.oauth2.SSOValidator; import io.renren.modules.security.oauth2.YaWeiCookieManage; import io.renren.modules.security.password.PasswordUtils; import io.renren.modules.security.service.CaptchaService; @@ -26,6 +27,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -59,6 +61,9 @@ public class LoginController { @Autowired private SysLogLoginService sysLogLoginService; + @Autowired(required = false) + private SSOValidator ssoValidator; + @Value("${yawei.enable}") private Boolean yaweiEnable; // 亚微登录? @@ -158,7 +163,14 @@ public class LoginController { UserDetail user = SecurityUser.getUser(); //退出 - sysUserTokenService.logout(user.getId()); +// sysUserTokenService.logout(user.getId()); + + String token = request.getHeader(Constant.TOKEN_HEADER); + if (StringUtils.isBlank(token)) { + return new Result<>().error("请传入token"); + } + + sysUserTokenService.logoutByToken(token); //用户信息 SysLogLoginEntity log = new SysLogLoginEntity(); @@ -172,6 +184,10 @@ public class LoginController { log.setCreateDate(new Date()); sysLogLoginService.save(log); + if (ssoValidator != null && ssoValidator.getLogoutUrl() != null) { + response.addHeader("REDIRECT", ssoValidator.getLogoutUrl()); + } + return new Result(); } diff --git a/renren-admin/src/main/java/io/renren/modules/security/oauth2/CasSSOValidator.java b/renren-admin/src/main/java/io/renren/modules/security/oauth2/CasSSOValidator.java index 5e6e3518..9ba491ba 100644 --- a/renren-admin/src/main/java/io/renren/modules/security/oauth2/CasSSOValidator.java +++ b/renren-admin/src/main/java/io/renren/modules/security/oauth2/CasSSOValidator.java @@ -24,8 +24,8 @@ public class CasSSOValidator implements SSOValidator { private String serverUrlPrefix; @Value("${cas.server-login-url}") private String serverLoginUrl; - @Value("${cas.client-host-url}") - private String clientHostUrl; + @Value("${cas.server-logout-url}") + private String serverLogoutUrl; private Cas30JsonServiceTicketValidator ticketValidator; @@ -88,6 +88,11 @@ public class CasSSOValidator implements SSOValidator { return serverLoginUrl + "?service=" + URLEncoder.encode(removeCreditParame(callBackUrl)); } + @Override + public String getLogoutUrl() { + return serverLogoutUrl; + } + private static String getParema(String urlStr, String field) { String result = ""; Pattern pXM = Pattern.compile(field + "=([^&|^#]*)"); diff --git a/renren-admin/src/main/java/io/renren/modules/security/oauth2/SSOValidator.java b/renren-admin/src/main/java/io/renren/modules/security/oauth2/SSOValidator.java index c76dd559..ea620394 100644 --- a/renren-admin/src/main/java/io/renren/modules/security/oauth2/SSOValidator.java +++ b/renren-admin/src/main/java/io/renren/modules/security/oauth2/SSOValidator.java @@ -11,4 +11,6 @@ public interface SSOValidator { String removeCreditParame(String url); String getLoginUrl(String callBackUrl); + + String getLogoutUrl(); } diff --git a/renren-admin/src/main/java/io/renren/modules/security/oauth2/YaweiSSOValidator.java b/renren-admin/src/main/java/io/renren/modules/security/oauth2/YaweiSSOValidator.java index 28182561..14967259 100644 --- a/renren-admin/src/main/java/io/renren/modules/security/oauth2/YaweiSSOValidator.java +++ b/renren-admin/src/main/java/io/renren/modules/security/oauth2/YaweiSSOValidator.java @@ -77,6 +77,11 @@ public class YaweiSSOValidator implements SSOValidator { return keeperUrl; } + @Override + public String getLogoutUrl() { + return yaweiSSOProperties.getLogoutUrl(); + } + private String getSSOToken(String url){ String ssoMatchKey = yaweiSSOProperties.getSsoKey() + "="; int startIndex = url.indexOf(ssoMatchKey) + ssoMatchKey.length(); diff --git a/renren-admin/src/main/java/io/renren/modules/security/service/SysUserTokenService.java b/renren-admin/src/main/java/io/renren/modules/security/service/SysUserTokenService.java index 858784fb..dd60ebb7 100644 --- a/renren-admin/src/main/java/io/renren/modules/security/service/SysUserTokenService.java +++ b/renren-admin/src/main/java/io/renren/modules/security/service/SysUserTokenService.java @@ -26,6 +26,12 @@ public interface SysUserTokenService extends BaseService { */ void logout(Long userId); + /** + * 退出 + * @param token 用户token + */ + void logoutByToken(String token); + /** * 在线用户分页 */ 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 07374369..2571962c 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 @@ -1,5 +1,6 @@ package io.renren.modules.security.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import io.renren.common.constant.Constant; import io.renren.common.page.PageData; @@ -21,9 +22,9 @@ import java.util.Map; @Service public class SysUserTokenServiceImpl extends BaseServiceImpl implements SysUserTokenService { /** - * 12小时后过期 修改成 7天 + * 12小时后过期 */ - private final static int EXPIRE = 3600 * 24 * 7; + private final static int EXPIRE = 3600 * 12; @Override public Result createToken(Long userId) { @@ -34,37 +35,47 @@ public class SysUserTokenServiceImpl extends BaseServiceImpl map = new HashMap<>(2); map.put(Constant.TOKEN_HEADER, token); @@ -78,6 +89,14 @@ public class SysUserTokenServiceImpl extends BaseServiceImpl wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SysUserTokenEntity::getToken, token); + baseDao.delete(wrapper); + } + @Override public PageData onlinePage(Map params) { //转换成like diff --git a/renren-admin/src/main/resources/application.yml b/renren-admin/src/main/resources/application.yml index b11fba29..7e7c6a06 100644 --- a/renren-admin/src/main/resources/application.yml +++ b/renren-admin/src/main/resources/application.yml @@ -119,6 +119,7 @@ sso: cas: server-url-prefix: http://10.134.135.81:11188/cas server-login-url: http://10.134.135.81:11188/cas/login + server-logout-url: http://10.134.135.81:11188/cas/logout client-host-url: http://localhost:9999/#/ use-session: false validation-type: cas3 diff --git a/renren-admin/src/main/resources/yaweisso.properties b/renren-admin/src/main/resources/yaweisso.properties index 45e5f05e..c29577e4 100644 --- a/renren-admin/src/main/resources/yaweisso.properties +++ b/renren-admin/src/main/resources/yaweisso.properties @@ -1,3 +1,4 @@ sso.domain=jhoa.qd.gov.cn sso.ssoKey=SSOToken -sso.keeperUrl=http://jhoa.qd.gov.cn/Keeper.aspx \ No newline at end of file +sso.keeperUrl=http://jhoa.qd.gov.cn/Keeper.aspx +sso.logoutUrl=http://jhoa.qd.gov.cn/LogoutSSO.aspx \ No newline at end of file