UniAuth 开源权限管理框架

我要开发同款
匿名用户2017年03月14日
41阅读
开发技术JavaHTML/CSS
所属分类安全相关框架、程序开发
授权协议Apache

作品详情

一.关于UNIAUTH1.1.uniauth干什么的

它是一个统一登录+鉴权+权限管理的综合系统;它适用于各系统需要通过统一认证/授权,并能根据既定的角色和权限来规范业务操作的多子系统环境。

1.2.uniauth技术选型

基于jdk7,使用springmvc4.2+mybatis3+springsecurity4+cas+cxf作为基础框架,数据库为mysql5.7,配置管理使用zookeeper3.4,redis作为可选项用于保存ticket和session信息,前端使用angularJS1.x;

二.快速开始2.1.编译打包

在源码目录执行命令

gradle warUniAuthServer、 gradle warCas、 gradle warTechopsWebsite,

分别可以在uniauth-server,cas,techops项目的build路径下得到uniauth.war、 cas.war、 techops.war;

2.2.初始化数据库

在mysql中createdatabaseuniauth,然后按rt顺序执行uniauth-server/src/script/sql中所有的脚本;管理员账号: shuanggui.fan@dianrong.com ,密码:$1234qweR

2.3.配置tomcat7

添加环境参数修改tomcatbin目录中catalina.sh文件,在正文首行后加入下面环境参数:

JAVA_OPTS="$JAVA_OPTS -Dcatalina.logs=/var/lib/tomcat/logs"  # log outputDR_CFG_ZOOKEEPER_ENV_URL="10.8.12.85:2181,10.8.12.85:2182,10.8.12.85:2183"  # zookeeper cluster addressexport DR_CFG_ZOOKEEPER_ENV_URL

修改端口将上面tomcat复制粘贴三份,分别叫做tomcatuniauth、 tomcatcas、tomcat_techops,分别修改server.xml中监听端口,假定分别是:8080,8081,8082,注意:同时修改其他shutdown,ajp端口

uniauth添加jndi数据源在tomcat_uniauth的context.xml中

2.4.配置zookeeper

在zokeeper中create下面节点数据

/com/dianrong/cfg/1.0.0/uniauth/cas_server.iscookiesecure false   // 线上环境一定是true/com/dianrong/cfg/1.0.0/uniauth/cas_server https://localhost:8081/cas // cas服务器的部署base地址/com/dianrong/cfg/1.0.0/uniauth/domains.techops https://localhost:8082/techops // techops的部署base地址/com/dianrong/cfg/1.0.0/uniauth/uniauth_ws_endpoint https://localhost:8080/uniauth/ws/rs  // uniauth的webservice endpoint地址, base+/ws/rs

zookeeper的配置根路径为/com/dianrong/cfg/1.0.0,该默认路径可通过在catalina.sh中export DR_CFG_ZOOKEEPER_BASE_PATH变量来更改

2.5.部署启动

按下面顺序启动

1.启动tomcatuniauth将uniauth.war部署到tomcatuniauth的webapps目录,启动tomcat

2.启动tomcatcas将cas.war部署到tomcatcas的webapps目录,启动tomcat

3.启动tomcattechops将techops.war部署到tomcattechops的webapps目录,启动tomcat

访问管理控制台techops

 

三.系统结构3.1.模块组件依赖

如上图,uniauth的核心模块:uniauth-server,common,share-rw,ss-client,cas,techops。

三个独立应用:

(1)uniauth-server是提供数据访问的REST服务;用户,资源,权限数据通过它进行访问;(2)techops是web界面的管理控制台;通过techops录入资源,角色,做权限分配;(3)cas是单点登录系统;各个subsystem通过cas做sso认证;

三个关键模块:(4)common定义了读uniauth-server的接口,接口的数据模型以及cxf方式的访问实现;由它定义了数据接口,因此各个模块必须依赖它;(5)share-rw提供对uniauth-server中写功能的访问接口定义,cxf方式访问实现,由于牵涉到对数据的修改,因此只有管理系统才能依赖这个模块,如techops(6)ss-client是uniauth提供的sdk,各子系统依赖它后只需要少量的配置就可以完成sso,authentication和authorization的业务(7)subsystem代表各个子系统,也是uniauth的客户端,各个需要用到sso,authentication和authorization的系统,比如techops。

3.2.系统架构

上图中分两条线

step1-7,includessoandauthentication

Betweenstep7and8,theuniauthclientsendrequesttocasserverforauthenticationuserwithst(getfromstep6)thentheclientcangetcredentials(*includeusername*)fromresponsedata。

step8,includeauthorizationAftergotcredentials,uniauthclientcalluniauth-servertogetuserdetailsandallpermissions.

四.参数配置

配置都是在zookeeper中添加节点数据

4.1.核心配置

(1)cas本身的配置

/com/dianrong/cfg/1.0.0/uniauth/cas_server.iscookiesecure true #是否采用https的形式写cookie,生产为true/com/dianrong/cfg/1.0.0/uniauth/cas_server     https://localhost:8081/cas  #cas的地址 。比如:https://localhost:8080/cas/com/dianrong/cfg/1.0.0/uniauth/cas.st_use_times  2  #配置cas的service ticket可验证的次数,现在默认是2次。其实正常情况下只验证一次是最安全的。/com/dianrong/cfg/1.0.0/uniauth/tenancyIdentity.check.switch   true #配置true 或 false。 用于指定是否强制的验证访问uniauth-server请求是否带有租户的验证信息/com/dianrong/cfg/1.0.0/uniauth/uniauth_ws_endpoint    https://localhost:8090/uniauth/ws/rs #配置的uniauth-server的地址。比如:https://localhost:8090/uniauth/ws/rs

(2)邮箱配置邮箱主要是为了验证码发送,密码重置

/com/dianrong/cfg/1.0.0/uniauth/internal.mail.smtp.host    邮箱服务器host,比如:smtp-dev.sl.com(默认值)/com/dianrong/cfg/1.0.0/uniauth/internal.mail.smtp.port    邮箱服务器port,比如:25(默认值)/com/dianrong/cfg/1.0.0/uniauth/internal.mail.smtp.femail   uniauth系统邮件的发送者,比如:TechOps-Notification(默认值)4.2.redis配置a 普通模式  /com/dianrong/cfg/1.0.0/uniauth/redis.host  localhost    #cas采用的redis的host  /com/dianrong/cfg/1.0.0/uniauth/redis.port   6379        #redis的portb 哨兵模式  /com/dianrong/cfg/1.0.0/uniauth/redis.database 0     #redis的数据库index  /com/dianrong/cfg/1.0.0/uniauth/cas.iscluster true   #true or false  cas是否采用redis存储登陆的ticket  /com/dianrong/cfg/1.0.0/uniauth/redis.password ''    #指定redis密码  /com/dianrong/cfg/1.0.0/uniauth/redis.master  mymaster  #指定master节点name  /com/dianrong/cfg/1.0.0/uniauth/redis.sentinels  10.18.19.51:5000,10.18.19.101:5000    #指定 redis集群节点列表,例如:10.18.19.67:5000,10.18.19.51:5000,10.18.19.101:50004.3.集成系统配置

下面的xxx就是定义好的domain,如techops,crm,pms,cms,etc

/com/dianrong/cfg/1.0.0/uniauth/domains.xxx    https://localhost:8100/techops/  #xxx系统的地址。比如:https://localhost:8100/techops//com/dianrong/cfg/1.0.0/uniauth/domainx.xxx.loginPage  https://localhost:8100/techops/login.jsp #如果xxx系统采用自定义登陆页面,则此处配置其自定义登陆页面地址。/com/dianrong/cfg/1.0.0/uniauth/domainx.xxx.auth_fail_url    https://localhost:8100/techops/login_fail.jsp  #如果xxx系统在进行st认证失败的时候跳转到失败页面(需要客户端集成做一些配置)。/com/dianrong/cfg/1.0.0/uniauth/domains.xxx.showInHomePage true  #明确指定是否在uniauth登陆页能跳转到xxx系统的登陆页(是否出现选项框中),例如:true
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论