Bläddra i källkod

修改登录验证

huangyh 6 år sedan
förälder
incheckning
a1aa5e3cc7
7 ändrade filer med 702 tillägg och 502 borttagningar
  1. 11 10
      controllers/gen/SsoController_gen.go
  2. 30 1
      controllers/partial/SsoController.go
  3. 469 469
      light-apiengine.xml
  4. 31 6
      middleware/login_ware.go
  5. 64 0
      models/time.go
  6. 13 12
      routers/sso.go
  7. 84 4
      utils/token_store.go

+ 11 - 10
controllers/gen/SsoController_gen.go

@@ -1,11 +1,10 @@
-
 package gen
 
 import (
-	"git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
-	"github.com/gin-gonic/gin"
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/controllers/partial"
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/engine"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
+	"github.com/gin-gonic/gin"
 )
 
 // SsoController operations for Sso
@@ -18,30 +17,32 @@ func NewSsoController(e *engine.ApiEngine) *SsoController {
 	return controller
 }
 
-
-
 // Login
 // @Title Login
-// @Description 用户登录         
-// @Param	logininfo      false  "登录信息"  
+// @Description 用户登录
+// @Param	logininfo      false  "登录信息"
 // @Success 200 {object} sysReturn
 // @Failure 403 :id is empty
 // @router /login  [post,get,put]
 func (c *SsoController) Login(ctx *gin.Context) {
 	//
-	db:=c.apiengine.BusinessOrmEngine[ctx.GetString("domain")]
+	db := c.apiengine.BusinessOrmEngine[ctx.GetString("domain")]
 	partial.Sso_Login(&entitys.CtrlContext{ctx, db, c.apiengine.PlatformOrmEngine})
 }
 
 // Logout
 // @Title Logout
-// @Description 用户退出         
+// @Description 用户退出
 // @Success 200 {object} sysReturn
 // @Failure 403 :id is empty
 // @router /logout  [post,get]
 func (c *SsoController) Logout(ctx *gin.Context) {
 	//
-	db:=c.apiengine.BusinessOrmEngine[ctx.GetString("domain")]
+	db := c.apiengine.BusinessOrmEngine[ctx.GetString("domain")]
 	partial.Sso_Logout(&entitys.CtrlContext{ctx, db, c.apiengine.PlatformOrmEngine})
 }
 
+func (c *SsoController) Validate(ctx *gin.Context) {
+	db := c.apiengine.BusinessOrmEngine[ctx.GetString("domain")]
+	partial.Sso_Validate(&entitys.CtrlContext{ctx, db, c.apiengine.PlatformOrmEngine})
+}

+ 30 - 1
controllers/partial/SsoController.go

@@ -3,6 +3,7 @@ package partial
 import (
 	"fmt"
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/logs"
 	sysmodel "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
 	sysutils "git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
 	"strconv"
@@ -44,7 +45,8 @@ func Sso_Login(c *entitys.CtrlContext) {
 			//token.Password = pwd
 			token.ServerIp = ""
 			token.Domain = user.Domain
-			sysutils.GetGlobalTokenStore().Set(sec_tooken, token)
+			//sysutils.GetGlobalTokenStore().Set(sec_tooken, token)
+			sysutils.GetGlobalTokenStore().Set(token.LoginID+user.Domain, token)
 		} else {
 			token = v
 		}
@@ -82,6 +84,33 @@ func Sso_Logout(c *entitys.CtrlContext) {
 	}
 }
 
+func Sso_Validate(c *entitys.CtrlContext) {
+	accessToken := c.Ctx.Query("access_token")
+	loginId := c.Ctx.Query("username")
+	requesterType := c.Ctx.Query("type")
+
+	if requesterType == "app" {
+		//timestamp := c.Ctx.Query("timestamp")
+		//signature := c.Ctx.Query("signature")
+		//token, err := models.ValidateApp(loginId, accessToken, timestamp, signature)
+		//if err != nil {
+		//	this.Ctx.WriteString(err.Error())
+		//	this.Ctx.Output.SetStatus(401)
+		//	return
+		//}
+		//this.Ctx.Output.JSON(token, false, false)
+	} else {
+		domain := strings.TrimSpace(strings.ToLower(c.Ctx.Query("domain")))
+		token, err := sysutils.Validate(accessToken, loginId, domain)
+		if err != nil {
+			logs.Error(accessToken, loginId, "校验AccessToken失败:", err)
+			c.Ctx.Data(401, "text", []byte(err.Error()))
+			return
+		}
+		c.Ctx.JSON(200, token)
+	}
+}
+
 func __none_func_sso__(params ...interface{}) bool {
 	return true
 }

+ 469 - 469
light-apiengine.xml

@@ -1,469 +1,469 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<application xmlns="http://qianqiusoft.com/developer"
-             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-             xsi:schemaLocation="http://qianqiusoft.com/developer"
-             name="light-apiengine"
-             desc="千秋开发平台"
-             packagename="git.qianqiusoft.com/qianqiusoft/light-apiengine">
-    <controllers>
-        <controller name="sso" desc="用户单点登录功能" skip_login="true">
-            <api name="login" desc="用户登录" method="post,get,put">
-                <param name="logininfo" ref="$login_info" desc="登录信息"></param>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="logout" desc="用户退出" method="post,get">
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-        </controller>
-        <controller name="sys_attachment" desc="系统管理">
-            <api name="upload" desc="上传文件" method="post">
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="download" desc="下载文件" method="get">
-                <param name="id" type="string" desc="文件ID"></param>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="delete" desc="删除文件" method="get">
-                <param name="id" type="string" desc="文件ID"></param>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-        </controller>
-        <controller name="system" desc="系统管理">
-            <api name="sidebar" function="tree" table="sys_menu" desc="获取导航菜单" method="post,get">
-                <param name="user" type="string" desc="用户id"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="find_user_page" desc="获取用户分页数" function="page" table="sys_user" method="get,post" >
-            </api>
-            <api name="get_org_tree" desc="获取组织架构树" function="tree" table="sys_org" method="get,post" >
-            </api>
-            <api name="get_menu_tree" desc="获取菜单树" function="tree" table="sys_menu" method="get,post" >
-            </api>
-            <api name="get_domain_tree" desc="获取菜单树" function="tree" table="sys_domain" method="get,post" >
-            </api>
-            <api name="find_org_page" desc="获取组织架构分页数" function="page" table="sys_org" method="get,post" >
-            </api>
-            <api name="find_role_page" desc="获取角色分页数" function="page" table="sys_role" method="get,post" >
-            </api>
-            <api name="find_menu_page" desc="获取菜单分页数" function="page" table="sys_menu" method="get,post" >
-            </api>
-            <api name="find_domain_page" desc="获取菜单分页数" function="page" table="sys_domain" method="get,post" >
-            </api>
-            <api name="add_user" desc="添加用户" method="post,get,put">
-                <param name="login_id" type="string" desc="登录ID"/>
-                <param name="password" type="string" desc="密码"/>
-                <param name="org_id" type="string" desc="组织ID"/>
-                <param name="email" type="string" desc="邮箱"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="del_user" desc="删除用户" method="post,get,put">
-                <param name="id" type="string" desc="用户ID"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="update_user" desc="修改用户" method="post,get,put">
-                <param name="login_id" type="string" desc="登录ID"/>
-                <param name="password" type="string" desc="密码"/>
-                <param name="org_id" type="string" desc="组织ID"/>
-                <param name="email" type="string" desc="邮箱"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="add_role" desc="添加角色" method="post,get,put">
-                <param name="name" type="string" desc="角色名称"/>
-                <param name="remark" type="string" desc="备注"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="del_role" desc="添加角色" method="post,get,put">
-                <param name="id" type="string" desc="角色ID"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="update_role" desc="修改角色" method="post,get,put">
-                <param name="id" type="string" desc="角色ID"/>
-                <param name="name" type="string" desc="角色名称"/>
-                <param name="remark" type="string" desc="备注"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="find_role_menu" desc="查找角色权限" method="post,get,put">
-                <param name="role_id" type="string" desc="角色id"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="save_role_menu" desc="保存角色权限" method="post,get,put">
-                <param name="role_menu" ref="$save_role_menu array" type="string" desc="角色权限"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="role_all" desc="查找所有角色" method="post,get,put">
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="find_permissions" desc="查找用户权限" method="post,get,put">
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="add_menu" desc="添加菜单" method="post,get,put">
-                <param name="" ref="$sys_menu" type="string" desc="菜单"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="del_menu" desc="删除菜单" method="post,get,put">
-                <param name="id"  type="string" desc="菜单ID"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="update_menu" desc="更新菜单" method="post,get,put">
-                <param name="" ref="$sys_menu" type="string" desc="菜单"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="add_org" desc="添加组织" method="post,get,put">
-                <param name="" ref="$sys_org" type="string" desc="组织"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="del_org" desc="删除组织" method="post,get,put">
-                <param name="id"  type="string" desc="组织ID"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-            <api name="update_org" desc="更新组织" method="post,get,put">
-                <param name="" ref="$sys_org" type="string" desc="组织"/>
-                <return>
-                    <success ref="$sys_return"></success>
-                    <failure ref="$sys_return"></failure>
-                </return>
-            </api>
-        </controller>
-        <controller name="api" desc="api接口">
-            <api name="api_doc" method="get" desc="api文档">
-                <param name="sys" desc="是否包含用户管理相关接口" type="string"></param>
-            </api>
-        </controller>
-    </controllers>
-    <beans>
-        <bean name="sys_menu_tree" desc="系统菜单树" inher="$sys_menu">
-            <prop name="children" caption="子列表" type="$sys_menu_tree array" />
-            <prop name="level" caption="目录层级" type="int32" />
-            <prop name="parent_name" caption="父节点名称" type="string" />
-        </bean>
-        <bean name="sys_org_tree" desc="组织架构" inher="$sys_org">
-            <prop name="children" caption="子列表" type="$sys_org_tree array" />
-        </bean>
-        <bean name="user_info" desc="用户信息" inher="$sys_user">
-            <prop name="org_name" caption="部门名称" type="string" />
-            <prop name="role_name" caption="角色名称" type="string" />
-            <prop name="user_role" caption="用户角色" type="$sys_user_role array" />
-        </bean>
-        <bean name="login_info" desc="登录信息">
-            <prop name="account" caption="用户id" type="string" />
-            <prop name="password" caption="密码" type="string" />
-            <prop name="captcha" caption="验证码" type="string" />
-        </bean>
-        <bean name="login_return_info" desc="登录信息" inher="$sys_user">
-            <prop name="token" caption="token" type="string" />
-        </bean>
-        <bean name="get_page_info" desc="分页参数">
-            <prop name="pageNum" caption="页码" type="int" />
-            <prop name="pageSize" caption="单页数" type="int" />
-            <prop name="columnFilters" caption="过滤条件" type="$column_filters"/>
-        </bean>
-        <bean name="column_filters" desc="分页参数_过滤条件列表">
-            <prop name="name" caption="过滤名称列表" type="$column_filter" />
-        </bean>
-        <bean name="column_filter" desc="分页参数_过滤条件">
-            <prop name="name" caption="过滤名称列表" type="string" />
-            <prop name="value" caption="过滤值" type="string" />
-        </bean>
-        <bean name="sys_user_page_info">
-            <prop name="pageNum" caption="页码" type="int" />
-            <prop name="pageSize" caption="单页数" type="int" />
-            <prop name="totalSize" caption="总页数" type="int" />
-            <prop name="content" caption="内容" type="$user_info array" />
-        </bean>
-        <bean name="sys_return" desc="系统返回">
-            <prop name="code" caption="代码" type="int32" />
-            <prop name="msg" caption="描述" type="string" />
-            <prop name="data" caption="数据" type="interface{}" />
-        </bean>
-        <bean name="sys_role_page_info">
-            <prop name="pageNum" caption="页码" type="int" />
-            <prop name="pageSize" caption="单页数" type="int" />
-            <prop name="totalSize" caption="总页数" type="int" />
-            <prop name="content" caption="内容" type="$sys_role array" />
-        </bean>
-        <bean name="save_role_menu" desc="保存角色权限参数">
-            <prop name="role_id" caption="角色ID" type="string" />
-            <prop name="menu_id" caption="菜单ID" type="string" />
-        </bean>
-        <bean name="storage_result" desc="附件返回">
-            <prop name="result" caption="result" type="string" />
-            <prop name="ip" caption="ip" type="string" />
-            <prop name="port" caption="port" type="string" />
-            <prop name="id" caption="id" type="string" />
-            <prop name="hash" caption="hash" type="string" />
-            <prop name="len" caption="len" type="int32" />
-            <prop name="error" caption="error" type="string" />
-        </bean>
-        <bean name="page_result" desc="分页结果">
-            <prop name="page" caption="页码" type="int" />
-            <prop name="rows" caption="单页数" type="int" />
-            <prop name="totalSize" caption="总页数" type="int64" />
-            <prop name="content" caption="内容" type="interface{}" />
-        </bean>
-        <bean name="tree_node" desc="树结点">
-            <prop name="id" caption="ID" type="string" />
-            <prop name="text" caption="标题" type="string" />
-            <prop name="parent" caption="父结点" type="string" />
-            <prop name="nodes" caption="子结点" type="*TreeNode array" />
-            <prop name="tag" caption="tag" type="interface{}" />
-        </bean>
-        <bean name="join" desc="连表查询">
-            <prop name="joinOperator" caption="连接方式" type="string" />
-            <prop name="tabelName" caption="连接表名" type="string" />
-            <prop name="condition" caption="连接条件" type="string" />
-        </bean>
-        <bean name="page_query_param" desc="分页参数">
-            <prop name="table_name" caption="表名" type="string" />
-            <prop name="select_fields" caption="选择列" type="[]string" />
-            <prop name="join_tables" caption="总数" type="$join array" />
-            <!--<prop name="page_info" caption="内容" type="$get_page_info" />-->
-        </bean>
-
-    </beans>
-    <tables>
-        <table name="sys_user" desc="用户表">
-            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
-                    type="string" size="36">
-                <auto value="$uuid" update="false">
-                </auto>
-            </column>
-            <column isNull="false" name="login_id" caption="登录ID" type="string" dbtype="varchar(36)" size="36" />
-            <column isNull="false" name="password" caption="密码" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="name" caption="名字" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="full_name" caption="全名" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="mobile" caption="电话" type="string" size="50" dbtype="varchar(50)"/>
-            <column isNull="false" name="email" caption="邮箱" type="string" size="50" dbtype="varchar(50)"/>
-            <column isNull="false" name="org_id" caption="组织ID" type="string" size="36" dbtype="varchar(36)"/>
-            <column name="gender" caption="性别 0:女    1:男 " type="int32"/>
-            <column name="type" caption="用户类型" type="int32"/>
-            <column name="status" caption="状态 0:禁用   1:正常" type="int32"/>
-            <column isNull="false" name="avatar" caption="头像" type="string" size="255" dbtype="varchar(255)"/>
-            <column isNull="false" name="domain" caption="域" type="string" size="50" dbtype="varchar(50)"/>
-            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
-            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
-            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
-        </table>
-        <table name="sys_org" desc="组织架构">
-            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
-                    type="string" size="36">
-                <auto value="$uuid" update="false">
-                </auto>
-            </column>
-            <column isNull="true" name="parent" caption="上级组织" type="string" size="36" dbtype="varchar(36)" />
-            <column isNull="true" name="inheritance" caption="继承关系" type="string" size="500" dbtype="varchar(500)"/>
-            <column isNull="false" name="name" caption="名称" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="full_name" caption="全名" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="leader" caption="领导人" type="string" size="36" dbtype="varchar(36)"/>
-            <column name="type" caption="组织类型" type="int32"/>
-            <column name="order" caption="排序" type="int32"/>
-            <column name="status" caption="状态 0:禁用   1:正常" type="int32"/>
-            <column isNull="false" name="domain" caption="域" type="string" size="50" dbtype="varchar(36)"/>
-            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
-            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
-            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
-        </table>
-        <table name="sys_role" desc="用户角色">
-            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
-                    type="string" size="36">
-                <auto value="$uuid" update="false">
-                </auto>
-            </column>
-            <column isNull="false" name="name" caption="名称" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="code" caption="编码" type="string" size="36" dbtype="varchar(36)"/>
-            <column name="remark" caption="备注" type="string" size="100" dbtype="varchar(100)"/>
-            <column name="status" caption="状态 0:禁用   1:正常" type="int32"/>
-            <column isNull="false" name="domain" caption="域" type="string" size="50" dbtype="varchar(50)"/>
-            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
-            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
-            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
-        </table>
-        <table name="sys_user_role" desc="用户与角色对应">
-            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
-                    type="string" size="36">
-                <auto value="$uuid" update="false">
-                </auto>
-            </column>
-            <column isNull="false" name="user_id" caption="用户ID" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="role_id" caption="角色ID" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="domain" caption="域" type="string" size="50" dbtype="varchar(50)"/>
-            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
-            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
-            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
-        </table>
-        <table name="sys_menu" desc="系统菜单">
-            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
-                    type="string" size="36">
-                <auto value="$uuid" update="false">
-                </auto>
-            </column>
-            <column isNull="false" name="name" caption="菜单名称" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="code" caption="编码" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="true" name="parent" caption="父菜单ID,一级菜单为null" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="true" name="inheritance" caption="继承关系" type="string" size="500" dbtype="varchar(500)"/>
-            <column name="url" type="string" size="200" dbtype="varchar(200)" caption="菜单URL,类型:1.普通页面(如用户管理, /sys/user) 2.嵌套完整外部页面,以http(s)开头的链接 3.嵌套服务器页面,使用iframe:前缀+目标URL(如SQL监控, iframe:/druid/login.html, iframe:前缀会替换成服务器地址)"/>
-            <column name="component" type="string" size="100" dbtype="varchar(100)" caption="菜单组件"/>
-            <column isNull="true" name="perms" caption="授权(多个用逗号分隔,如:sys:user:add,sys:user:edit)" type="string" size="500" dbtype="varchar(500)"/>
-            <column name="type" caption="类型 0:目录   1:菜单   2:按钮" type="int32"/>
-            <column isNull="false" name="icon" caption="菜单图标" type="string" size="50" dbtype="varchar(50)"/>
-            <column isNull="false" name="order_num" caption="排序" type="int32"/>
-            <column isNull="false" name="domain" caption="域" type="string" size="50" dbtype="varchar(50)"/>
-            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
-            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
-            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
-        </table>
-        <table name="sys_role_menu" desc="角色与菜单对应">
-            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
-                    type="string" size="36">
-                <auto value="$uuid" update="false">
-                </auto>
-            </column>
-            <column isNull="false" name="role_id" caption="用户ID" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="menu_id" caption="角色ID" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="domain" caption="域" type="string" size="50" />
-            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
-            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
-            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
-        </table>
-        <table name="sys_permission" desc="权限表">
-            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
-                    type="string" size="36">
-                <auto value="$uuid" update="false">
-                </auto>
-            </column>
-            <column isNull="false" name="perms" caption="权限标识" type="string" size="100" dbtype="varchar(100)"/>
-            <column isNull="false" name="domain" caption="域" type="string" size="50" />
-            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
-            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
-            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
-        </table>
-        <table name="sys_role_permission" desc="角色权限表">
-            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
-                    type="string" size="36">
-                <auto value="$uuid" update="false">
-                </auto>
-            </column>
-            <column isNull="false" name="permission_id" caption="权限ID" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="role_id" caption="角色ID" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="domain" caption="域" type="string" size="50" />
-            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
-            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
-            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
-        </table>
-        <table name="sys_attachment" desc="附件表">
-            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
-                    type="string" size="36">
-                <auto value="$uuid" update="false">
-                </auto>
-            </column>
-            <column isNull="false" name="name" caption="名称" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="size" caption="大小" type="int32" size="50" />
-            <column isNull="false" name="ext" caption="ext" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="hash" caption="哈希值" type="string" />
-            <column isNull="false" name="url" caption="链接地址" type="string" size="200" dbtype="varchar(200)"/>
-            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
-            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
-        </table>
-        <table name="sys_domain" desc="用户域">
-            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
-                    type="string" size="36">
-                <auto value="$uuid" update="false">
-                </auto>
-            </column>
-            <column isNull="false" name="name" caption="名称" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="full_name" caption="全名" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="contact_name" caption="负责人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="contact_email" caption="负责人邮箱" type="string" size="50" dbtype="varchar(50)"/>
-            <column isNull="false" name="contact_mobile" caption="负责人电话" type="string" size="50" dbtype="varchar(50)"/>
-            <column isNull="false" name="data_source" caption="数据库链接串" type="string" size="200" dbtype="varchar(200)"/>
-            <column isNull="false" name="domain_url" caption="网址" type="string" size="200" dbtype="varchar(200)"/>
-            <column name="type" caption="域类型" type="int32"/>
-            <column name="status" caption="状态 0:禁用   1:正常" type="int32"/>
-            <column isNull="false" name="domain" caption="域" type="string" size="50" dbtype="varchar(36)"/>
-            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
-            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
-            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
-            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
-        </table>
-    </tables>
-</application>
+<?xml version="1.0" encoding="utf-8" ?>
+<application xmlns="http://qianqiusoft.com/developer"
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+             xsi:schemaLocation="http://qianqiusoft.com/developer"
+             name="light-apiengine"
+             desc="千秋开发平台"
+             packagename="git.qianqiusoft.com/qianqiusoft/light-apiengine">
+    <controllers>
+        <!--<controller name="sso" desc="用户单点登录功能" skip_login="true">-->
+            <!--<api name="login" desc="用户登录" method="post,get,put">-->
+                <!--<param name="logininfo" ref="$login_info" desc="登录信息"></param>-->
+                <!--<return>-->
+                    <!--<success ref="$sys_return"></success>-->
+                    <!--<failure ref="$sys_return"></failure>-->
+                <!--</return>-->
+            <!--</api>-->
+            <!--<api name="logout" desc="用户退出" method="post,get">-->
+                <!--<return>-->
+                    <!--<success ref="$sys_return"></success>-->
+                    <!--<failure ref="$sys_return"></failure>-->
+                <!--</return>-->
+            <!--</api>-->
+        <!--</controller>-->
+        <controller name="sys_attachment" desc="系统管理">
+            <api name="upload" desc="上传文件" method="post">
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="download" desc="下载文件" method="get">
+                <param name="id" type="string" desc="文件ID"></param>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="delete" desc="删除文件" method="get">
+                <param name="id" type="string" desc="文件ID"></param>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+        </controller>
+        <controller name="system" desc="系统管理">
+            <api name="sidebar" function="tree" table="sys_menu" desc="获取导航菜单" method="post,get">
+                <param name="user" type="string" desc="用户id"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="find_user_page" desc="获取用户分页数" function="page" table="sys_user" method="get,post" >
+            </api>
+            <api name="get_org_tree" desc="获取组织架构树" function="tree" table="sys_org" method="get,post" >
+            </api>
+            <api name="get_menu_tree" desc="获取菜单树" function="tree" table="sys_menu" method="get,post" >
+            </api>
+            <api name="get_domain_tree" desc="获取菜单树" function="tree" table="sys_domain" method="get,post" >
+            </api>
+            <api name="find_org_page" desc="获取组织架构分页数" function="page" table="sys_org" method="get,post" >
+            </api>
+            <api name="find_role_page" desc="获取角色分页数" function="page" table="sys_role" method="get,post" >
+            </api>
+            <api name="find_menu_page" desc="获取菜单分页数" function="page" table="sys_menu" method="get,post" >
+            </api>
+            <api name="find_domain_page" desc="获取菜单分页数" function="page" table="sys_domain" method="get,post" >
+            </api>
+            <api name="add_user" desc="添加用户" method="post,get,put">
+                <param name="login_id" type="string" desc="登录ID"/>
+                <param name="password" type="string" desc="密码"/>
+                <param name="org_id" type="string" desc="组织ID"/>
+                <param name="email" type="string" desc="邮箱"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="del_user" desc="删除用户" method="post,get,put">
+                <param name="id" type="string" desc="用户ID"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="update_user" desc="修改用户" method="post,get,put">
+                <param name="login_id" type="string" desc="登录ID"/>
+                <param name="password" type="string" desc="密码"/>
+                <param name="org_id" type="string" desc="组织ID"/>
+                <param name="email" type="string" desc="邮箱"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="add_role" desc="添加角色" method="post,get,put">
+                <param name="name" type="string" desc="角色名称"/>
+                <param name="remark" type="string" desc="备注"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="del_role" desc="添加角色" method="post,get,put">
+                <param name="id" type="string" desc="角色ID"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="update_role" desc="修改角色" method="post,get,put">
+                <param name="id" type="string" desc="角色ID"/>
+                <param name="name" type="string" desc="角色名称"/>
+                <param name="remark" type="string" desc="备注"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="find_role_menu" desc="查找角色权限" method="post,get,put">
+                <param name="role_id" type="string" desc="角色id"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="save_role_menu" desc="保存角色权限" method="post,get,put">
+                <param name="role_menu" ref="$save_role_menu array" type="string" desc="角色权限"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="role_all" desc="查找所有角色" method="post,get,put">
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="find_permissions" desc="查找用户权限" method="post,get,put">
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="add_menu" desc="添加菜单" method="post,get,put">
+                <param name="" ref="$sys_menu" type="string" desc="菜单"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="del_menu" desc="删除菜单" method="post,get,put">
+                <param name="id"  type="string" desc="菜单ID"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="update_menu" desc="更新菜单" method="post,get,put">
+                <param name="" ref="$sys_menu" type="string" desc="菜单"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="add_org" desc="添加组织" method="post,get,put">
+                <param name="" ref="$sys_org" type="string" desc="组织"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="del_org" desc="删除组织" method="post,get,put">
+                <param name="id"  type="string" desc="组织ID"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+            <api name="update_org" desc="更新组织" method="post,get,put">
+                <param name="" ref="$sys_org" type="string" desc="组织"/>
+                <return>
+                    <success ref="$sys_return"></success>
+                    <failure ref="$sys_return"></failure>
+                </return>
+            </api>
+        </controller>
+        <controller name="api" desc="api接口">
+            <api name="api_doc" method="get" desc="api文档">
+                <param name="sys" desc="是否包含用户管理相关接口" type="string"></param>
+            </api>
+        </controller>
+    </controllers>
+    <beans>
+        <bean name="sys_menu_tree" desc="系统菜单树" inher="$sys_menu">
+            <prop name="children" caption="子列表" type="$sys_menu_tree array" />
+            <prop name="level" caption="目录层级" type="int32" />
+            <prop name="parent_name" caption="父节点名称" type="string" />
+        </bean>
+        <bean name="sys_org_tree" desc="组织架构" inher="$sys_org">
+            <prop name="children" caption="子列表" type="$sys_org_tree array" />
+        </bean>
+        <bean name="user_info" desc="用户信息" inher="$sys_user">
+            <prop name="org_name" caption="部门名称" type="string" />
+            <prop name="role_name" caption="角色名称" type="string" />
+            <prop name="user_role" caption="用户角色" type="$sys_user_role array" />
+        </bean>
+        <bean name="login_info" desc="登录信息">
+            <prop name="account" caption="用户id" type="string" />
+            <prop name="password" caption="密码" type="string" />
+            <prop name="captcha" caption="验证码" type="string" />
+        </bean>
+        <bean name="login_return_info" desc="登录信息" inher="$sys_user">
+            <prop name="token" caption="token" type="string" />
+        </bean>
+        <bean name="get_page_info" desc="分页参数">
+            <prop name="pageNum" caption="页码" type="int" />
+            <prop name="pageSize" caption="单页数" type="int" />
+            <prop name="columnFilters" caption="过滤条件" type="$column_filters"/>
+        </bean>
+        <bean name="column_filters" desc="分页参数_过滤条件列表">
+            <prop name="name" caption="过滤名称列表" type="$column_filter" />
+        </bean>
+        <bean name="column_filter" desc="分页参数_过滤条件">
+            <prop name="name" caption="过滤名称列表" type="string" />
+            <prop name="value" caption="过滤值" type="string" />
+        </bean>
+        <bean name="sys_user_page_info">
+            <prop name="pageNum" caption="页码" type="int" />
+            <prop name="pageSize" caption="单页数" type="int" />
+            <prop name="totalSize" caption="总页数" type="int" />
+            <prop name="content" caption="内容" type="$user_info array" />
+        </bean>
+        <bean name="sys_return" desc="系统返回">
+            <prop name="code" caption="代码" type="int32" />
+            <prop name="msg" caption="描述" type="string" />
+            <prop name="data" caption="数据" type="interface{}" />
+        </bean>
+        <bean name="sys_role_page_info">
+            <prop name="pageNum" caption="页码" type="int" />
+            <prop name="pageSize" caption="单页数" type="int" />
+            <prop name="totalSize" caption="总页数" type="int" />
+            <prop name="content" caption="内容" type="$sys_role array" />
+        </bean>
+        <bean name="save_role_menu" desc="保存角色权限参数">
+            <prop name="role_id" caption="角色ID" type="string" />
+            <prop name="menu_id" caption="菜单ID" type="string" />
+        </bean>
+        <bean name="storage_result" desc="附件返回">
+            <prop name="result" caption="result" type="string" />
+            <prop name="ip" caption="ip" type="string" />
+            <prop name="port" caption="port" type="string" />
+            <prop name="id" caption="id" type="string" />
+            <prop name="hash" caption="hash" type="string" />
+            <prop name="len" caption="len" type="int32" />
+            <prop name="error" caption="error" type="string" />
+        </bean>
+        <bean name="page_result" desc="分页结果">
+            <prop name="page" caption="页码" type="int" />
+            <prop name="rows" caption="单页数" type="int" />
+            <prop name="totalSize" caption="总页数" type="int64" />
+            <prop name="content" caption="内容" type="interface{}" />
+        </bean>
+        <bean name="tree_node" desc="树结点">
+            <prop name="id" caption="ID" type="string" />
+            <prop name="text" caption="标题" type="string" />
+            <prop name="parent" caption="父结点" type="string" />
+            <prop name="nodes" caption="子结点" type="*TreeNode array" />
+            <prop name="tag" caption="tag" type="interface{}" />
+        </bean>
+        <bean name="join" desc="连表查询">
+            <prop name="joinOperator" caption="连接方式" type="string" />
+            <prop name="tabelName" caption="连接表名" type="string" />
+            <prop name="condition" caption="连接条件" type="string" />
+        </bean>
+        <bean name="page_query_param" desc="分页参数">
+            <prop name="table_name" caption="表名" type="string" />
+            <prop name="select_fields" caption="选择列" type="[]string" />
+            <prop name="join_tables" caption="总数" type="$join array" />
+            <!--<prop name="page_info" caption="内容" type="$get_page_info" />-->
+        </bean>
+
+    </beans>
+    <tables>
+        <table name="sys_user" desc="用户表">
+            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
+                    type="string" size="36">
+                <auto value="$uuid" update="false">
+                </auto>
+            </column>
+            <column isNull="false" name="login_id" caption="登录ID" type="string" dbtype="varchar(36)" size="36" />
+            <column isNull="false" name="password" caption="密码" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="name" caption="名字" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="full_name" caption="全名" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="mobile" caption="电话" type="string" size="50" dbtype="varchar(50)"/>
+            <column isNull="false" name="email" caption="邮箱" type="string" size="50" dbtype="varchar(50)"/>
+            <column isNull="false" name="org_id" caption="组织ID" type="string" size="36" dbtype="varchar(36)"/>
+            <column name="gender" caption="性别 0:女    1:男 " type="int32"/>
+            <column name="type" caption="用户类型" type="int32"/>
+            <column name="status" caption="状态 0:禁用   1:正常" type="int32"/>
+            <column isNull="false" name="avatar" caption="头像" type="string" size="255" dbtype="varchar(255)"/>
+            <column isNull="false" name="domain" caption="域" type="string" size="50" dbtype="varchar(50)"/>
+            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
+            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
+            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
+        </table>
+        <table name="sys_org" desc="组织架构">
+            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
+                    type="string" size="36">
+                <auto value="$uuid" update="false">
+                </auto>
+            </column>
+            <column isNull="true" name="parent" caption="上级组织" type="string" size="36" dbtype="varchar(36)" />
+            <column isNull="true" name="inheritance" caption="继承关系" type="string" size="500" dbtype="varchar(500)"/>
+            <column isNull="false" name="name" caption="名称" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="full_name" caption="全名" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="leader" caption="领导人" type="string" size="36" dbtype="varchar(36)"/>
+            <column name="type" caption="组织类型" type="int32"/>
+            <column name="order" caption="排序" type="int32"/>
+            <column name="status" caption="状态 0:禁用   1:正常" type="int32"/>
+            <column isNull="false" name="domain" caption="域" type="string" size="50" dbtype="varchar(36)"/>
+            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
+            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
+            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
+        </table>
+        <table name="sys_role" desc="用户角色">
+            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
+                    type="string" size="36">
+                <auto value="$uuid" update="false">
+                </auto>
+            </column>
+            <column isNull="false" name="name" caption="名称" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="code" caption="编码" type="string" size="36" dbtype="varchar(36)"/>
+            <column name="remark" caption="备注" type="string" size="100" dbtype="varchar(100)"/>
+            <column name="status" caption="状态 0:禁用   1:正常" type="int32"/>
+            <column isNull="false" name="domain" caption="域" type="string" size="50" dbtype="varchar(50)"/>
+            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
+            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
+            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
+        </table>
+        <table name="sys_user_role" desc="用户与角色对应">
+            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
+                    type="string" size="36">
+                <auto value="$uuid" update="false">
+                </auto>
+            </column>
+            <column isNull="false" name="user_id" caption="用户ID" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="role_id" caption="角色ID" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="domain" caption="域" type="string" size="50" dbtype="varchar(50)"/>
+            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
+            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
+            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
+        </table>
+        <table name="sys_menu" desc="系统菜单">
+            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
+                    type="string" size="36">
+                <auto value="$uuid" update="false">
+                </auto>
+            </column>
+            <column isNull="false" name="name" caption="菜单名称" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="code" caption="编码" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="true" name="parent" caption="父菜单ID,一级菜单为null" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="true" name="inheritance" caption="继承关系" type="string" size="500" dbtype="varchar(500)"/>
+            <column name="url" type="string" size="200" dbtype="varchar(200)" caption="菜单URL,类型:1.普通页面(如用户管理, /sys/user) 2.嵌套完整外部页面,以http(s)开头的链接 3.嵌套服务器页面,使用iframe:前缀+目标URL(如SQL监控, iframe:/druid/login.html, iframe:前缀会替换成服务器地址)"/>
+            <column name="component" type="string" size="100" dbtype="varchar(100)" caption="菜单组件"/>
+            <column isNull="true" name="perms" caption="授权(多个用逗号分隔,如:sys:user:add,sys:user:edit)" type="string" size="500" dbtype="varchar(500)"/>
+            <column name="type" caption="类型 0:目录   1:菜单   2:按钮" type="int32"/>
+            <column isNull="false" name="icon" caption="菜单图标" type="string" size="50" dbtype="varchar(50)"/>
+            <column isNull="false" name="order_num" caption="排序" type="int32"/>
+            <column isNull="false" name="domain" caption="域" type="string" size="50" dbtype="varchar(50)"/>
+            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
+            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
+            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
+        </table>
+        <table name="sys_role_menu" desc="角色与菜单对应">
+            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
+                    type="string" size="36">
+                <auto value="$uuid" update="false">
+                </auto>
+            </column>
+            <column isNull="false" name="role_id" caption="用户ID" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="menu_id" caption="角色ID" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="domain" caption="域" type="string" size="50" />
+            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
+            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
+            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
+        </table>
+        <table name="sys_permission" desc="权限表">
+            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
+                    type="string" size="36">
+                <auto value="$uuid" update="false">
+                </auto>
+            </column>
+            <column isNull="false" name="perms" caption="权限标识" type="string" size="100" dbtype="varchar(100)"/>
+            <column isNull="false" name="domain" caption="域" type="string" size="50" />
+            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
+            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
+            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
+        </table>
+        <table name="sys_role_permission" desc="角色权限表">
+            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
+                    type="string" size="36">
+                <auto value="$uuid" update="false">
+                </auto>
+            </column>
+            <column isNull="false" name="permission_id" caption="权限ID" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="role_id" caption="角色ID" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="domain" caption="域" type="string" size="50" />
+            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
+            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
+            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
+        </table>
+        <table name="sys_attachment" desc="附件表">
+            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
+                    type="string" size="36">
+                <auto value="$uuid" update="false">
+                </auto>
+            </column>
+            <column isNull="false" name="name" caption="名称" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="size" caption="大小" type="int32" size="50" />
+            <column isNull="false" name="ext" caption="ext" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="hash" caption="哈希值" type="string" />
+            <column isNull="false" name="url" caption="链接地址" type="string" size="200" dbtype="varchar(200)"/>
+            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
+            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
+        </table>
+        <table name="sys_domain" desc="用户域">
+            <column isNull="false" isPK="true" name="id" caption="主键" dbtype="varchar(36)"
+                    type="string" size="36">
+                <auto value="$uuid" update="false">
+                </auto>
+            </column>
+            <column isNull="false" name="name" caption="名称" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="full_name" caption="全名" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="contact_name" caption="负责人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="contact_email" caption="负责人邮箱" type="string" size="50" dbtype="varchar(50)"/>
+            <column isNull="false" name="contact_mobile" caption="负责人电话" type="string" size="50" dbtype="varchar(50)"/>
+            <column isNull="false" name="data_source" caption="数据库链接串" type="string" size="200" dbtype="varchar(200)"/>
+            <column isNull="false" name="domain_url" caption="网址" type="string" size="200" dbtype="varchar(200)"/>
+            <column name="type" caption="域类型" type="int32"/>
+            <column name="status" caption="状态 0:禁用   1:正常" type="int32"/>
+            <column isNull="false" name="domain" caption="域" type="string" size="50" dbtype="varchar(36)"/>
+            <column isNull="false" name="create_by" caption="创建人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="create_time" caption="创建时间" type="datetime" />
+            <column isNull="false" name="last_update_by" caption="最后更新人" type="string" size="36" dbtype="varchar(36)"/>
+            <column isNull="false" name="last_update_time" caption="最后更新时间" type="int64" />
+            <column isNull="false" name="del_flag" caption="是否删除 1:删除   0:正常" type="int32"/>
+        </table>
+    </tables>
+</application>

+ 31 - 6
middleware/login_ware.go

@@ -1,32 +1,57 @@
 package middleware
 
 import (
-	sysmodel "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
+	"encoding/base64"
+	"fmt"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/config"
+	sysmodels "git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/wfclient"
 	"github.com/gin-gonic/gin"
+	"strings"
 )
 
 func LoginWare() gin.HandlerFunc {
 	return func(c *gin.Context) {
 		//验证登陆
-		token := c.GetHeader("token")
+		//fmt.Println("header-Authorization:" + c.GetHeader("Authorization"))
+		s := strings.SplitN(c.GetHeader("Authorization"), " ", 2)
 
-		if token == "" {
-			c.AbortWithStatusJSON(401, sysmodel.SysReturn{401, "token is empty", ""})
+		if len(s) != 2 {
+			fmt.Println("sso header not found.")
 			c.Redirect(302, "/login")
 			return
 		}
 
-		tk := utils.GetGlobalTokenStore().Get(token)
+		b, err := base64.StdEncoding.DecodeString(s[1])
+		fmt.Println("base64 decode:" + string(b))
+		if err != nil {
+			fmt.Println("sso header decode error." + err.Error())
+			c.Redirect(302, "/login")
+			return
+		}
+
+		pair := strings.SplitN(string(b), ":", 3)
+		if len(pair) != 3 {
+			fmt.Println("sso header len(pair) !=3")
+			c.Redirect(302, "/login")
+			return
+		}
+
+		tk := utils.GetGlobalTokenStore().Get(pair[0] + pair[2])
 		if tk == nil {
-			c.AbortWithStatusJSON(401, sysmodel.SysReturn{401, "token Invalid", ""})
+			c.AbortWithStatusJSON(401, sysmodels.SysReturn{401, "token Invalid", ""})
 			c.Redirect(302, "/login")
 			return
 		}
 
+		wfendpoint := config.AppConfig.GetKey("wfendpoint")
+		wfclient.Instance().Init(wfendpoint, tk.UserId, tk.LoginID, tk.AccessToken, tk.Domain)
+
 		c.Set("token", tk)
 		c.Set("user_id", tk.UserId)
 		c.Set("domain", tk.Domain)
 		c.Next()
+
 	}
 }

+ 64 - 0
models/time.go

@@ -0,0 +1,64 @@
+package models
+
+import (
+	"strings"
+	"time"
+)
+
+type Time time.Time
+
+const (
+	timeFormat = "2006-01-02 15:04:05"
+)
+
+func NowLocal() Time {
+	return Time(time.Now())
+}
+
+func (t *Time) UnmarshalJSON(data []byte) error {
+	if data[0] == '"' && data[len(data)-1] == '"' {
+		data = data[1 : len(data)-1]
+	}
+
+	dataStr := strings.TrimSpace(string(data))
+	if dataStr == "" {
+		now, err := time.ParseInLocation(timeFormat, string(data), time.Local)
+		*t = Time(now)
+		return err
+	}
+
+	var err error
+	var now time.Time
+
+	if strings.Index(dataStr, "T") > 0 {
+		dataStr = strings.Replace(dataStr, "T", " ", 1)
+	}
+
+	if len(dataStr) > 19 {
+		dataStr = dataStr[0:19]
+		if dataStr == "0001-01-01 00:00:00" {
+			dataStr = timeFormat
+		}
+	} else if len(dataStr) == 10 {
+		dataStr += " 00:00:00"
+	} else if len(dataStr) == 13 {
+		dataStr += ":00:00"
+	} else if len(dataStr) == 16 {
+		dataStr += ":00"
+	}
+
+	now, err = time.ParseInLocation(timeFormat, dataStr, time.Local)
+
+	*t = Time(now)
+
+	return err
+}
+
+func (t Time) MarshalJSON() ([]byte, error) {
+	b := make([]byte, 0, len(timeFormat)+2)
+	b = append(b, '"')
+	b = time.Time(t).AppendFormat(b, timeFormat)
+	b = append(b, '"')
+
+	return b, nil
+}

+ 13 - 12
routers/sso.go

@@ -1,30 +1,31 @@
-
 package routers
 
 import (
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/engine"
-	
+
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/controllers/gen"
 )
 
-func init(){
+func init() {
 	addRegisterHandler(registerSsoRouter)
 }
 
-func registerSsoRouter(e *engine.ApiEngine){
-	api:=e.GinEngine.Group("/api")
-	v1:=api.Group("/v1/sso")
-	
+func registerSsoRouter(e *engine.ApiEngine) {
+	api := e.GinEngine.Group("/api")
+	v1 := api.Group("/v1/sso")
 
 	ctrler := gen.NewSsoController(e)
 
+	v1.GET("/login", ctrler.Login)
+	v1.POST("/login", ctrler.Login)
 
+	v1.GET("/logout", ctrler.Logout)
+	v1.POST("/logout", ctrler.Logout)
 
-	v1.GET("/login",ctrler.Login)
-	v1.POST("/login",ctrler.Login)
+	ssoclient := e.GinEngine.Group("/local/openid")
+	ssoclient.GET("/validate", ctrler.Validate)
 
-	v1.GET("/logout",ctrler.Logout)
-	v1.POST("/logout",ctrler.Logout)
+	openIdValidate := e.GinEngine.Group("/openid")
+	openIdValidate.GET("/validate", ctrler.Validate)
 
 }
-

+ 84 - 4
utils/token_store.go

@@ -1,12 +1,14 @@
 package utils
 
 import (
+	"errors"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/config"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/logs"
 	"log"
+	"strings"
 	"sync"
 	"time"
-
-	"git.qianqiusoft.com/qianqiusoft/light-apiengine/config"
-	"git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
 )
 
 type TokenStore struct {
@@ -17,7 +19,7 @@ type TokenStore struct {
 
 var globalTokenStore *TokenStore = nil
 
-func init(){
+func init() {
 	globalTokenStore = &TokenStore{name: "sso", lock: new(sync.RWMutex), tokens: make(map[string]*entitys.Token)}
 	go globalTokenStore.startTokenCheckProcess()
 }
@@ -93,3 +95,81 @@ func (t *TokenStore) startTokenCheckProcess() {
 		}
 	}
 }
+
+func Validate(accessToken, loginId string, domain string) (*entitys.Token, error) {
+	token := globalTokenStore.Get(loginId + domain)
+	if token != nil {
+		if strings.EqualFold(token.AccessToken, accessToken) {
+			logs.Info("get the token ", accessToken, " of id ", loginId+domain)
+			globalTokenStore.Refresh(loginId + domain)
+			return token, nil
+		} else {
+			logs.Error(token.AccessToken, "is not equal to", accessToken)
+			return token, errors.New(token.AccessToken + " is not equal to " + accessToken)
+		}
+	} else {
+		logs.Error("can not get the token of", loginId+domain)
+		return token, errors.New("can not get the token of " + loginId + domain)
+	}
+
+}
+
+//func ValidateApp(appName, accessToken, timestamp, signature string) (*entitys.Token, error) {
+//	fmt.Println(appName, accessToken, timestamp, signature)
+//	if appName == "" || timestamp == "" || accessToken == "" || signature == "" {
+//		return nil, errors.New("some param is empty")
+//	}
+//
+//	// check time out
+//	timestampi, err := strconv.ParseInt(timestamp, 10, 64)
+//	if err != nil {
+//		return nil, err
+//	}
+//
+//	timestampt := time.Unix(timestampi, 0)
+//	subval := time.Now().Sub(timestampt)
+//
+//	period := config.ApiConfig.GetInt("period")
+//
+//	if subval.Seconds() < 0 || subval.Seconds() > float64(period) {
+//		return nil, errors.New("the request is out of time")
+//	}
+//	// end of check time out
+//
+//	// validate accessToken
+//	appInfo, err := appManager.GetUamAppByName(appName)
+//	if err != nil {
+//		return nil, err
+//	}
+//	fmt.Println("----------------------------3")
+//
+//	signatureOrg := appInfo.Name + "." + timestamp + "." + appInfo.Token // generate the
+//	hs := md5.New()
+//	hs.Write([]byte(signatureOrg))
+//	signatureStr := base64.StdEncoding.EncodeToString(hs.Sum(nil))
+//
+//	fmt.Println("-----------------signatureStr", signatureStr)
+//
+//	if signatureStr != signature {
+//		return nil, errors.New("the signature is invalid")
+//	}
+//	fmt.Println("----------------------------2")
+//
+//	str := appInfo.Token + "." + timestamp // generate accesstoken
+//	hs = md5.New()
+//	hs.Write([]byte(str))
+//	md5Str := base64.StdEncoding.EncodeToString(hs.Sum(nil))
+//	if accessToken != md5Str {
+//		return nil, errors.New("token is invalid")
+//	}
+//
+//	fmt.Println("----------------------------1")
+//
+//	rt := &entitys.Token{}
+//	rt.AccessToken = utils.GenerateToken(accessToken + "." + timestamp)
+//	rt.Result = 0
+//	rt.UserId = appInfo.Id
+//	rt.LoginID = appInfo.Name
+//	rt.TimeStamp = uint64(timestampi)
+//	return rt, nil
+//}