Browse Source

鉴权登录初步实现

huangzhiyong 8 years ago
parent
commit
40e889bc3c

+ 2 - 2
hos-camel/src/main/java/gateway/route/GatewayRouterBuilder.java

@ -1,6 +1,6 @@
package camel.gateway.route;
package gateway.route;
import camel.gateway.processor.GatewayProcessor;
import gateway.processor.GatewayProcessor;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

+ 34 - 0
hos-web-framework/src/main/java/com/yihu/hos/web/framework/util/controller/BaseController.java

@ -3,9 +3,13 @@ package com.yihu.hos.web.framework.util.controller;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.yihu.hos.core.http.HTTPResponse;
import com.yihu.hos.core.http.HttpClientKit;
import com.yihu.hos.core.log.Logger;
import com.yihu.hos.core.log.LoggerFactory;
import com.yihu.hos.web.framework.model.DetailModelResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
@ -16,6 +20,7 @@ import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
//import net.sf.json.JSONArray;
//import net.sf.json.JSONObject;
@ -25,9 +30,13 @@ import java.util.List;
 * @vsrsion 1.0
 * Created at 2016/8/8.
 */
@Component
public class BaseController extends AbstractController {
    static private final Logger logger = LoggerFactory.getLogger(BaseController.class);
    @Value("${service-gateway.portalUrl}")
    public String portalUrl;
    public BaseController() {
    }
@ -92,4 +101,29 @@ public class BaseController extends AbstractController {
        return null;
    }
    public boolean validToken(String clientId,String token) {
        boolean result = false;
        ObjectMapper objectMapper = new ObjectMapper();
        //TODO 设置固定的验证入口地址
        HTTPResponse response = HttpClientKit.post(portalUrl + "/oauth/validToken?clientId=" + clientId + "&accessToken=" + token);
        if (response.getStatusCode() != 200) {
            System.out.println("请求失败!");
            return false;
        }
        try {
            Map map = objectMapper.readValue(response.getBody(), Map.class);
            if ((Boolean) map.get("successFlg")) {
                return true;
            } else {
                System.out.println("验证失败:" + map.get("errorMsg"));
                return false;
            }
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
}

+ 2 - 4
pom.xml

@ -6,10 +6,8 @@
    <groupId>com.yihu.hos</groupId>
    <artifactId>hos-admin</artifactId>
    <version>1.3.0</version>
    <modules>
        <module>hos-camel-parent</module>
    </modules>
    <packaging>pom</packaging>
    <packaging>war</packaging>
    <name>esb</name>
    <description>ESB管理平台</description>

+ 73 - 1
src/main/java/com/yihu/hos/common/CommonPageController.java

@ -118,9 +118,80 @@ public class CommonPageController extends BaseController {
    /*
    首页页面
     */
    @RequestMapping("{tenantName}/indexPage")
    public String tenantIndex(
            @PathVariable(name = "tenantName") String tenantName,
            HttpServletRequest request,Model model) {
        HttpSession session = request.getSession();
        boolean auth = false;
        String clientId  = request.getParameter("clientId");
        String token  = request.getParameter("token");
        boolean succ = validToken(clientId, token);
        if (succ){
            //TODO 根据token和clientId 获取用户信息
            SystemUser userInfo = new SystemUser();
            userInfo.setLoginCode("admin");
            userInfo.setUserName("管理员");
            session.setAttribute("userInfo",userInfo);
            try {
                auth = authenticateService.auth(session, tenantName);
                if (auth){
                }
            }catch (Exception e){
                e.printStackTrace();
            }
            model.addAttribute("userName", "admin");
            model.addAttribute("tenant",tenantName);
            //获取菜单
            String menu = "[{id: 1, text: '任务管理',icon:'${staticRoot}/images/index/menu2_icon.png'},\n" +
                    "        {id: 11, pid: 1, text: '任务跟踪', url: '${contextRoot}/datacollect/trackJob',targetType:'1'},\n" +
                    "        {id: 12, pid: 1, text: '任务补采', url: '${contextRoot}/datacollect/repeatDatacollect'},\n" +
                    "        {id: 13, pid: 1, text: '任务配置', url: '${contextRoot}/datacollect/configJob'},\n" +
                    "        {id: 2, text: '标准管理',icon:'${staticRoot}/images/index/menu3_icon.png'},\n" +
                    "        {id: 21, pid: 2, text: '集成标准', url: '${contextRoot}/integration/initial/standard'},\n" +
                    "        {id: 22, pid: 2, text: '应用标准', url: '${contextRoot}/integration/initial/application'},\n" +
                    "        {id: 23, pid: 2, text: '适配方案', url: '${contextRoot}/adapterPlan/initial'},\n" +
                    "        {id: 3, text: '资源管理',icon:'${staticRoot}/images/index/menu4_icon.png'},\n" +
                    "        {id: 31, pid: 3, text: '资源注册', url: '${contextRoot}/resource/resource/initial'},\n" +
                    "        {id: 32, pid: 3, text: '资源浏览', url: '${contextRoot}/resource/resourcePage'},\n" +
                    "        {id: 34, pid: 3, text: '资源分类', url: '${contextRoot}/resource/rsCategory/initial'},\n" +
                    "        {id: 35, pid: 3, text: '业务资源', url: '${contextRoot}/resourceRest/initial'},\n" +
                    "        {id: 4, text: '维度管理',icon:'${staticRoot}/images/index/menu5_icon.png'},\n" +
                    "        {id: 41, pid: 4, text: '维度配置', url: '${contextRoot}/dimension/dimension'},\n" +
                    "        {id: 42, pid: 4, text: '维度类别配置', url: '${contextRoot}/dimension/dimensioncatetory'},\n" +
                    "        {id: 9, text: '系统配置',icon:'${staticRoot}/images/index/menu6_icon.png'},\n" +
                    "        {id: 91, pid: 9, text: '机构配置', url: '${contextRoot}/org/initial'},\n" +
                    "        {id: 92, pid: 9, text: '数据源配置', url: '${contextRoot}/datasource/configSources'},\n" +
                    "        {id: 93, pid: 9, text: '菜单配置', url: '${contextRoot}/menu/initial'},\n" +
                    "        {id: 100, pid: 9, text: '菜单按钮配置', url: '${contextRoot}/menu/menuAction/initial'},\n" +
                    "        {id: 94, pid: 9, text: '用户管理', url: '${contextRoot}/user/initial'},\n" +
                    "        {id: 95, pid: 9, text: '角色管理', url: '${contextRoot}/role/initial'},\n" +
                    "        {id: 96, pid: 9, text: '权限管理', url: '${contextRoot}/authority/initial'},\n" +
                    "        {id: 97, pid: 9, text: '字典管理', url: '${contextRoot}/dict/initial' },\n" +
                    "        {id: 98, pid: 9, text: '系统参数', url: '${contextRoot}/param/initial'},\n" +
                    "        {id: 99, pid: 9, text: '<spring:message code=\"title.app.manage\"/>', url: '${contextRoot}/app/initial'}]";
            model.addAttribute("menu", menu);
            model.addAttribute("contentPage","/common/index");
        }else {
            //TODO  返回验证错误页面
            model.addAttribute("contentPage","/common/tokenValidFail");
        }
        return "pageView";
    }
    /*
首页页面
 */
    @RequestMapping("indexPage")
    public String index(HttpServletRequest request,Model model) {
        HttpSession session = request.getSession();
        SystemUser user = (SystemUser) session.getAttribute("userInfo");
        TenantSession tenantSession = (TenantSession) session.getAttribute(ContextAttributes.TENANT_SESSION);
@ -162,6 +233,7 @@ public class CommonPageController extends BaseController {
        return "pageView";
    }
    /*
    系统主页
     */

+ 6 - 0
src/main/java/com/yihu/hos/filter/SessionOutTimeFilter.java

@ -42,6 +42,10 @@ public class SessionOutTimeFilter extends OncePerRequestFilter {
            return;
        }
        String token  = httpServletRequest.getParameter("token");
        String clientId  = httpServletRequest.getParameter("clientId");
        if (token == null || clientId == null){
        if (httpServletRequest.getSession(false) == null
                || httpServletRequest.getSession().getAttribute("userInfo")==null) {
@ -56,6 +60,8 @@ public class SessionOutTimeFilter extends OncePerRequestFilter {
            httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + "/" +attachment+  "/loginPage");
            return;
        }
        }
        filterChain.doFilter(httpServletRequest, httpServletResponse);
    }

+ 4 - 2
src/main/resources/application.yml

@ -63,7 +63,8 @@ hos:
    store: ./store
  mysql:
    filePath: e://learn.sql   #租户基础表 sql文件位置
service-gateway:
  portalUrl: http://localhost:444/api/v1.0/portal
---
spring:
  profiles: test
@ -111,7 +112,8 @@ hos:
    store: ./store
  mysql:
    filePath: /usr/local/esb/esb.sql   #租户基础表 sql文件位置
service-gateway:
  portalUrl: http://sdw2:444/api/v1.0/portal
---
spring:
  #SAAS管理员账号,暂时配置在此处

+ 6 - 5
src/main/resources/banner.txt

@ -1,7 +1,8 @@
                ███████╗    ███████╗    ██████╗
                ██╔════╝    ██╔════╝    ██╔══██╗
                █████╗        ███████╗    ██████╔╝
                ██╔══╝        ╚════██║    ██╔══██╗
                ███████╗    ███████║    ██████╔
                    ███████╗    ███████╗    ██████╗
                    ██╔════╝    ██╔════╝    ██╔══██╗
                    █████╗      ███████╗    ██████╔╝
                    ██╔══╝      ╚════██║    ██╔══██╗
                    ███████╗    ███████║    ██████╔╝
                    ╚══════╝    ╚══════╝    ╚═════╝
**************************spring-boot.version: ${spring-boot.version}*****************************

+ 25 - 0
src/main/webapp/WEB-INF/ehr/jsp/common/tokenValidFail.jsp

@ -0,0 +1,25 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="utf-8"%>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
<div id="divErrorContent" style="width:550px;height:400px;margin:0 auto;background: url('${staticRoot}/images/404.png') no-repeat;">
</div>
<%--
<script>
    $(function(){
        var errorMessage="${errorMessage}";
        if(errorMessage.length>0)
        {
        }
        else{
        }
    })
</script>
--%>

BIN
src/main/webapp/develop/images/404.png