完善单点登录

This commit is contained in:
shuzheng 2016-12-11 22:55:26 +08:00
parent 91f7afbf20
commit b256284570
4 changed files with 66 additions and 3 deletions

View File

@ -31,6 +31,12 @@
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- zheng-upms-client -->
<dependency>
<groupId>com.zheng</groupId>
<artifactId>zheng-upms-client</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<profiles>

View File

@ -0,0 +1,27 @@
package com.zheng.cms.job.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 用户管理
* Created by shuzheng on 2016/12/10.
*/
@Controller
@RequestMapping("/manage/user")
public class UserController {
private static Logger _log = LoggerFactory.getLogger(UserController.class);
/**
* 列表
* @return
*/
@RequestMapping("/list")
public String index() {
return "/user/list";
}
}

View File

@ -51,4 +51,22 @@
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- zhang-upms-client -->
<filter>
<filter-name>zheng-upms-client</filter-name>
<filter-class>com.zheng.upms.client.filter.SSOFilter</filter-class>
<init-param>
<param-name>system_name</param-name>
<param-value>zheng-cms-admin</param-value>
</init-param>
<init-param>
<param-name>sso_server_url</param-name>
<param-value>http://upms.zhangshuzheng.cn:1111</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>zheng-upms-client</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

View File

@ -1,5 +1,6 @@
package com.zheng.upms.admin.controller;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -29,6 +30,8 @@ public class SSOController {
*/
@RequestMapping("")
public String index(HttpServletRequest request) throws Exception {
HttpSession session = request.getSession();
String system_name = request.getParameter("system_name");
String backurl = request.getParameter("backurl");
if (StringUtils.isEmpty(system_name) || !system_name.equals("zheng-cms-admin")) {
@ -36,11 +39,20 @@ public class SSOController {
return "/404";
}
// 判断是否存在全局会话
if (null == request.getSession().getAttribute("isLogin")) {
// 未登录
if (null == session.getAttribute("isLogin")) {
return "redirect:/sso/login?backurl=" + URLEncoder.encode(backurl, "utf-8");
}
_log.info("认证中心验证为已登录,跳回:{}", backurl);
return "redirect:" + backurl;
// 已登录
String token = ObjectUtils.toString(session.getAttribute(session.getId()));
String redirectUrl = backurl;
if (backurl.contains("?")) {
redirectUrl += "&token=" + token;
} else {
redirectUrl += "?token=" + token;
}
_log.info("认证中心验证为已登录,跳回:{}", redirectUrl);
return "redirect:" + redirectUrl;
}
/**