CAS学习笔记(三):认证中心返回多属性配置

2023-05-16

 

概述

cas-server默认的可用信息只有用户名, 如果我还想知道他的角色类型等其它属性,这时候就需要做一些配置了。其它代码编写代码方式这里不做介绍,只做简单配置的方式介绍。

 

配置操作

1、cas-server项目自行根据CAS学习笔记(二)来搭建

具体目录结构如下:

2、application.properties 配置多属性,这里配置多一个数据表角色字段

##
# CAS Server Context Configuration
#
server.context-path=/cas
server.port=8443

#server.ssl.key-store=file:/etc/cas/thekeystore
#server.ssl.key-store-password=changeit
#server.ssl.key-password=changeit
# server.ssl.ciphers=
# server.ssl.client-auth=
# server.ssl.enabled=
# server.ssl.key-alias=
# server.ssl.key-store-provider=
# server.ssl.key-store-type=
# server.ssl.protocol=
# server.ssl.trust-store=
# server.ssl.trust-store-password=
# server.ssl.trust-store-provider=
# server.ssl.trust-store-type=

server.max-http-header-size=2097152
server.use-forward-headers=true
server.connection-timeout=20000
server.error.include-stacktrace=ALWAYS

server.compression.enabled=true
server.compression.mime-types=application/javascript,application/json,application/xml,text/html,text/xml,text/plain

server.tomcat.max-http-post-size=2097152
server.tomcat.basedir=build/tomcat
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms)
server.tomcat.accesslog.suffix=.log
server.tomcat.max-threads=10
server.tomcat.port-header=X-Forwarded-Port
server.tomcat.protocol-header=X-Forwarded-Proto
server.tomcat.protocol-header-https-value=https
server.tomcat.remote-ip-header=X-FORWARDED-FOR
server.tomcat.uri-encoding=UTF-8

spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

##
# CAS Cloud Bus Configuration
#
spring.cloud.bus.enabled=false
# spring.cloud.bus.refresh.enabled=true
# spring.cloud.bus.env.enabled=true
# spring.cloud.bus.destination=CasCloudBus
# spring.cloud.bus.ack.enabled=true

endpoints.enabled=false
endpoints.sensitive=true

endpoints.restart.enabled=false
endpoints.shutdown.enabled=false

management.security.enabled=true
management.security.roles=ACTUATOR,ADMIN
management.security.sessions=if_required
management.context-path=/status
management.add-application-context-header=false

security.basic.authorize-mode=role
security.basic.enabled=false
security.basic.path=/cas/status/**

##
# CAS Web Application Session Configuration
#
server.session.timeout=300
server.session.cookie.http-only=true
server.session.tracking-modes=COOKIE

##
# CAS Thymeleaf View Configuration
#
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.cache=true
spring.thymeleaf.mode=HTML
##
# CAS Log4j Configuration
#
# logging.config=file:/etc/cas/log4j2.xml
server.context-parameters.isLog4jAutoInitializationDisabled=true

##
# CAS AspectJ Configuration
#
spring.aop.auto=true
spring.aop.proxy-target-class=true

##
# CAS Authentication Credentials
#
#cas.authn.accept.users=user::123

cas.tgc.secure=false
#使用json配置
cas.serviceRegistry.initFromJson=true

#允许退出之后重定向页面
cas.logout.followServiceRedirects=true

#Query Database Authentication 数据库查询校验用户名开始
#查询账号密码sql,必须包含密码字段
cas.authn.jdbc.query[0].sql=select * from t_sso_user where status=1 and username=?
#指定上面的sql查询字段名(必须)
cas.authn.jdbc.query[0].fieldPassword=password
#指定过期字段,1为过期,若过期不可用
#cas.authn.jdbc.query[0].fieldExpired=expired
#为不可用字段段,1为不可用,需要修改密码
#cas.authn.jdbc.query[0].fieldDisabled=disabled
#数据库方言hibernate的
cas.authn.jdbc.query[0].dialect=org.hibernate.dialect.MySQLDialect
#数据库驱动
cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver
#数据库连接
cas.authn.jdbc.query[0].url=jdbc:mysql://192.168.0.166:3306/gf_sso?useUnicode=true&characterEncoding=UTF-8
#数据库用户名
cas.authn.jdbc.query[0].user=root
#数据库密码
cas.authn.jdbc.query[0].password=hfocean123
#默认加密策略,通过encodingAlgorithm来指定算法,默认NONE不加密
cas.authn.jdbc.query[0].passwordEncoder.type=DEFAULT
cas.authn.jdbc.query[0].passwordEncoder.characterEncoding=UTF-8
cas.authn.jdbc.query[0].passwordEncoder.encodingAlgorithm=MD5
#Query Database Authentication 数据库查询校验用户名结束


#多属性
#配置多属性返回
#----------------------单列值情况----------------------------
#定义一个属性的单列
cas.authn.attributeRepository.jdbc[0].attributes.role=role
#设置数据为单行的情况
cas.authn.attributeRepository.jdbc[0].singleRow=true
cas.authn.attributeRepository.jdbc[0].order=0
cas.authn.attributeRepository.jdbc[0].url=${cas.authn.jdbc.query[0].url}
#这个相当于查询的sql,设定查询的字段
cas.authn.attributeRepository.jdbc[0].username=username
#多个属性的情况
cas.authn.attributeRepository.jdbc[0].user=${cas.authn.jdbc.query[0].user}
cas.authn.attributeRepository.jdbc[0].password=${cas.authn.jdbc.query[0].password}
#这个地方的{0} 就是  cas.authn.attributeRepository.jdbc[0].username  对于的查询条件
cas.authn.attributeRepository.jdbc[0].sql=select * from t_sso_user where {0}
cas.authn.attributeRepository.jdbc[0].dialect=${cas.authn.jdbc.query[0].dialect}
cas.authn.attributeRepository.jdbc[0].ddlAuto=none
cas.authn.attributeRepository.jdbc[0].driverClass=${cas.authn.jdbc.query[0].driverClass}
cas.authn.attributeRepository.jdbc[0].leakThreshold=10
cas.authn.attributeRepository.jdbc[0].propagationBehaviorName=PROPAGATION_REQUIRED
cas.authn.attributeRepository.jdbc[0].batchSize=1
cas.authn.attributeRepository.jdbc[0].failFast=true
#----------------------单列值情况----------------------------


# 默认主题配置
#cas.theme.defaultThemeName=anumbrella

主要是这一段配置role多属性返回,如下:

#多属性
#配置多属性返回
#----------------------单列值情况----------------------------
#定义一个属性的单列
cas.authn.attributeRepository.jdbc[0].attributes.role=role
#设置数据为单行的情况
cas.authn.attributeRepository.jdbc[0].singleRow=true
cas.authn.attributeRepository.jdbc[0].order=0
cas.authn.attributeRepository.jdbc[0].url=${cas.authn.jdbc.query[0].url}
#这个相当于查询的sql,设定查询的字段
cas.authn.attributeRepository.jdbc[0].username=username
#多个属性的情况
cas.authn.attributeRepository.jdbc[0].user=${cas.authn.jdbc.query[0].user}
cas.authn.attributeRepository.jdbc[0].password=${cas.authn.jdbc.query[0].password}
#这个地方的{0} 就是  cas.authn.attributeRepository.jdbc[0].username  对于的查询条件
cas.authn.attributeRepository.jdbc[0].sql=select * from t_sso_user where {0}
cas.authn.attributeRepository.jdbc[0].dialect=${cas.authn.jdbc.query[0].dialect}
cas.authn.attributeRepository.jdbc[0].ddlAuto=none
cas.authn.attributeRepository.jdbc[0].driverClass=${cas.authn.jdbc.query[0].driverClass}
cas.authn.attributeRepository.jdbc[0].leakThreshold=10
cas.authn.attributeRepository.jdbc[0].propagationBehaviorName=PROPAGATION_REQUIRED
cas.authn.attributeRepository.jdbc[0].batchSize=1
cas.authn.attributeRepository.jdbc[0].failFast=true
#----------------------单列值情况----------------------------

注意,其中cas.authn.attributeRepository.jdbc[0].attributes.role=role , role对应数据表role角色字段。

3、HTTPSandIMAPS-10000001.json 配置也对应修改下

{
  "@class" : "org.apereo.cas.services.RegexRegisteredService",
  "serviceId" : "^(https|http|imaps)://.*",
  "name" : "HTTPS and IMAPS",
  "id" : 10000001,
  "description" : "This service definition authorizes all application urls that support HTTPS and IMAPS protocols.",
  "evaluationOrder" : 10000,
  /*,"theme": "anumbrella"*/
  "attributeReleasePolicy" : {
    "@class" : "org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy",
    "allowedAttributes" : [ "java.util.ArrayList", ["role"] ]
  }
}

主要是增加下面这几句

 "attributeReleasePolicy" : {
    "@class" : "org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy",
    "allowedAttributes" : [ "java.util.ArrayList", ["role"] ]
  }

其中role对应上面的配置属性字段命名

4、客户端获取role属性方法

 AttributePrincipal principal = AssertionHolder.getAssertion().getPrincipal();
 final Map attributes = principal.getAttributes();
 Integer role = new Integer(attributes.get("role").toString());

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CAS学习笔记(三):认证中心返回多属性配置 的相关文章

  • 使用Docker安装ROS2 (ros-humble) 并开启对Wayland的支持

    前言 ROS Robot Operating System 是主流的机器人开发框架之一 截止目前 xff08 2020 10 xff09 xff0c 已经推出了ros humble版本 xff0c ROS2相比ROS1有很大的不同 xff0
  • linux下添加永久路由

    在linux下永久保存路由表的写法 一 SuSe Linux 在 etc sysconfig network routes里添加 etc sysconfig network routes格式如下 xff1a Destination Dumm
  • MySQL远程访问及访问速度慢等问题解决

    1 访问速度慢 现象 访问数据库速度慢 xff0c 完成一次连接或数据访问需要将近5s左右 原因 每次访问数据库 xff0c mysql就会试图去解析来访问的机器的domain name xff0c 如果这时解析不料 xff0c 等一段时间
  • JVM实战1-JVM虚拟机内存区域划分

    1 程序计数器 PC寄存器 当前线程所执行的字节码的行号指示器 在虚拟机的概念模型里 xff0c 字节码解析器工作就是通过这个计数器的值来选取下一条要执行的字节码指令 xff0c 分支 xff0c 循环 xff0c 跳转 xff0c 异常处
  • 2014,我还是一名菜鸟

    正如题目所提到 xff0c 菜鸟 什么是菜鸟呢 xff0c 不够成熟 xff0c 不够厉害 xff0c 对所从事和正在进行的工作不入流 反应痴呆 生疏 对于作为一名刚刚升大二的计算机专业的学生的我来说 xff0c 就是菜鸟 我所在的地方 x
  • Linux下so文件的生成和使用

    环境 xff1a Vmware Workstation xff1b CentOS 6 4 x86 64 说明 xff1a 1 源文件中不能有main函数 xff1b 写so文件的时候使用C语言写 xff0c 不要用C 43 43 2 在使用
  • 2014嗖的一声就过去了

    项目结束 xff0c 在CSDN一通乱逛看大牛所写文章 xff0c 正待如饥似渴 xff0c 突然瞄到右边栏有 我的2014 醒目字样 xff0c 以为是哪位大牛总结自己的2014 xff0c 没曾想到是CSDN发出的活动 xff0c 看到
  • IOS缓存基本知识和清除缓存的方法

    第一 NSURLRequest的缓存设置 id initWithURL NSURL URL cachePolicy NSURLRequestCachePolicy cachePolicy timeoutInterval NSTimeInte
  • CentOS7,玩转samba服务,基于身份验证的共享

    以前我们在Windows上共享文件的话 xff0c 只需右击要共享的文件夹然后选择共享相关的选项设置即可 然而如何实现Windows和Linux的文件共享呢 xff1f 这就涉及到了samba服务了 xff0c 这个软件配置起来也不难 xf
  • 清除浏览器的缓存,使js,css等修改后的内容生效

    方法1 ctrl 43 F5 方法2 在页面文件中添加如下代码 xff0c 禁用缓存 span class token tag span class token tag span class token punctuation lt spa
  • NORMFACE:L2 hypersphere embedding for face Verification

    https github com happynear NormFace 本文的思想很简单 xff0c 就是通过验证研究正则化的本质 xff0c 来设计网络结构 提取问题 xff1a 1 xff0c 为什么用classificatin los
  • Spark MLlib 机器学习

    本章导读 机器学习 machine learning ML 是一门涉及概率论 统计学 逼近论 凸分析 算法复杂度理论等多领域的交叉学科 ML专注于研究计算机模拟或实现人类的学习行为 xff0c 以获取新知识 新技能 xff0c 并重组已学习
  • Eigen 3.2稀疏矩阵入门

    https my oschina net cvnote blog 166980 Eigen自带的稀疏矩阵分解功能包括LDLt LLt分解 xff08 即Cholesky分解 xff0c 这个功能是LGPL许可 xff0c 不是Eigen的M
  • CentOS7 Vi编辑文件后无法保存成功问题(报错:Can't open file for writing)的几种可能原因

    根据教程在CentOS7上安装eclipse 在安装的最后需要创建一个文件 并在文件中写入了内容 按照正常操作直接输入vi XXXX XXXXX XXXXX XXX 打开文件编辑界面后 输入文件内容 输完点击esc 然后 wq 居然报错了
  • win10安装vmware tools + 无法拖拽文件解决

    1 加载VMware Tools安装光盘 打开虚拟机VMware Workstation xff0c 启动 Ubuntu 系统 菜单栏 虚拟机 安装VMware Tools 2 将安装文件提取到本地磁盘 打开加载的VMwareTools光盘
  • 问题“The connection to the server....:6443 was refused - did you specify the right host or port?”的处理!

    问题 The connection to the server lt master gt 6443 was refused did you specify the right host or port 的处理 xff01 一 故障产生 在不
  • 去马赛克神器 JavPlayer TG Modle 最新版

    本帖最后由 cyberim 于 2019 8 28 22 13 编辑 知识点 Mosaic的原理就是将1个像素的颜色填满一个小区域 xff0c 所以在平面图片上是无法还原的 简单说就是单一图片的Mosaic不可逆 但是 如果是Mosaic影
  • CentOS6 配置 yum 阿里源

    一 CentOS6停止维护更新日期2020年11月30日 二 2020年12月2日下架了包括官方所有的CentOS6源 xff08 包括国内的镜像站 xff09 三 CentOS6也完成了它的历史使命 在生产的环境中依旧由很多CentOS6
  • Jetson nano上部署自己的Yolov5模型(TensorRT加速)onnx模型转engine文件

    Jetson nano上部署自己的Yolov5模型 xff08 TensorRT加速 xff09 onnx模型转engine文件 背景 在主机上训练自己的Yolov5模型 xff0c 转为TensorRT模型并部署到Jetson Nano上
  • 安卓应用在各大应用市场上架方法整理

    安卓应用在各大应用市场上架方法整理 正在上传 重新上传取消 ASO优化师 酱紫 酱紫ASO ASA推广运营研究 关注她 1 人赞同了该文章 想要把APP上架到应用市场都要先注册开发者账号才可以 这里的方法包括注册帐号和后期上架及一些需要注意

随机推荐

  • YOLOv5的详细使用教程,以及使用yolov5训练自己的数据集

    YOLOv5的详细使用教程 xff0c 以及使用yolov5训练自己的数据集 文章目录 xff1a 1 安装环境依赖 1 1 克隆项目1 2 安装必要的环境依赖2 下载预训练模型和标注的数据集 2 1 下载预训练模型 2 1 1 执行脚本下
  • Can‘t find a suitable configuration file in this directory or any parent. 报错解决错误

    docker compose 执行的时候报错 Can 39 t find a suitable configuration file in this directory or any parent Are you in the right
  • ST-GCN训练自建数据集

    参考了许多博文 xff0c 慢慢地也就把st gcn跑出来了 xff0c 参考的文章一会附在文章里面 xff0c 实测有用 1 安装st gcn 复现STGCN CPU版 xff08 ubuntu16 04 43 pytorch0 4 0
  • 复现STGCN CPU版 (ubuntu16.04+pytorch0.4.0+openpose+caffe)

    前提 xff1a ubuntu下将python3 5 2设为默认 xff08 百度 xff09 一 下载stgcn xff08 gitbub上fork后导入到gitee快些 xff09 st gcn Spatial Temporal Gra
  • python新建txt文件,并逐行写入数据

    python2新建txt文件 xff0c 并逐行写入数据 coding 61 utf 8 import os txtName 61 34 codingWord txt 34 f 61 file txtName 34 a 43 34 for
  • SQLServer 調用 WebAPI [WSDL]

    某陌習慣調用ASMX文件 xff0c 開發語言最近比較常用C 結果這次合作的同事習慣用Python xff0c 還強調只會用REST風格的WebService 某陌心想這不是WebAPI嗎 xff1f 趕緊學習 正式引入WebAPI之前先簡
  • 知识图谱(Knowledge Graph, KG)(王昊奋老师-课程学习笔记)

    主要内容 xff1a 1 知识图谱的概念 2 典型知识库介绍 xff08 简 xff09 3 知识图谱技术概览 4 典型案例简介 知识图谱 KG 的概念 知识图谱 KG 得益于Web的发展 xff08 更多的是数据层面 xff09 xff0
  • Boa+CGI环境搭建笔记

    转自 xff1a https www sfantree com boa web cgi utm source 61 tuicool amp utm medium 61 referral BOA看了 xff0c CGI 原理也大概了解 现在要
  • 2021 CondaHTTPError: HTTP 000 CONNECTION FAILED for url 的问题终极解决方案

    一 首先执行命令 xff0c 查看自己的镜像源 conda config show channels 二 可以首先删除已经存在的镜像源 xff08 注 xff1a 上述三个镜像源无需删除 xff01 xff01 xff01 xff09 xf
  • K8s bridge、ip分配原理

    一个Blog jerichoking wtf 自建网站欢迎来戳 一 项目地址 GitHub containernetworking plugins Some reference and example networking plugins
  • RT-Thread系统的SysTick和pendSV的中断优先级

    问题描述 xff1a SysTick和pendSV的中断优先级分别设置为0和15 SysTick中断用于系统心跳 pendSV中断用于任务调度 代码证明 xff1a RT Thread中设置pendSV中断优先级的代码在cpu文件夹下con
  • curl的安装

    window下 xff1a 开启curl的步骤 span class hljs number 1 span 在localhost站点下输出一下phpinfo xff0c 以此来检测php ini的所在 xff08 因为我在开启CURL的时候
  • Hive DDL常见操作

    文章目录 Hive中DDL的使用Hive数据库介绍Hive数据库的操作Hive创建表操作数据类型分隔符指定默认分隔符创建表的示例 Hive show语法 Hive数据模型图 Hive中DDL的使用 Hive SQL xff08 HQL xf
  • 判断两个ip地址是否属于同一子网

    include lt stdio h gt include lt string h gt include lt stdlib h gt 功能 判断两台计算机IP地址是同一子网络 原型 xff1a int checkNetSegment ch
  • 做一个程序媛

    高考过去 xff0c 又一届的本科小鲜肉也毕业了 xff0c 办公室里面的实习生也换了一批 xff0c 忽然间有一点感慨 xff0c 转眼间 xff0c 也做了一年的程序猿了呀 这两天csdn从高考的程序员正巧在征文 xff0c 我也来蹭一
  • Ubuntu 进不了图形界面 硬盘文件系统错误 /dev/sda1 :clean...只有命令界面 give root password for maintaince. or press contro

    故障原因 xff1a 非法关机 xff0c 造成文件系统损坏 现象 xff1a 如题 xff0c 开机可以进入grub xff0c 但是任何选项都是无法进入图形界面 recovery 模式下选择菜单也无响应 正常开机只能进入如下图的状态 网
  • 花开两朵 天各一方

    他和她最后一次见面 xff0c 大约是四年前的毕业季 xff0c 分别的场景似乎已经模糊了 xff0c 但她临别的那句 到了深圳照顾好自己 xff0c 等国庆了我就去看你 却将美好的青春永远的定格在了那黄昏的站台 他和她相识是在十一年前的开
  • 嵌入式平台安装pandas以及其他包常见问题解决

    1 在嵌入式平台例如树莓派上安装python包常见问题解决 xff1a 问题1 xff1a 在使用pip进行安装pandas的时候 xff0c 安装完成之后在终端输入python3 然后导入pandas时出错 出现这个问题的最大原因就是pi
  • 从高考到程序员

    转瞬之间 xff0c 大四也已经结束了 天气晴朗 xff0c 毕业典礼上也人声鼎沸 xff0c 让我不禁想起了四年前 xff0c 高考结束大家急忙收拾东西逃离校园参加班级聚餐的情形 xff0c 与今日独自回宿舍最后清理一遍行李箱后拖着就走的
  • CAS学习笔记(三):认证中心返回多属性配置

    概述 cas server默认的可用信息只有用户名 xff0c 如果我还想知道他的角色类型等其它属性 xff0c 这时候就需要做一些配置了 其它代码编写代码方式这里不做介绍 xff0c 只做简单配置的方式介绍 配置操作 1 cas serv