《权限系列shiro+cas》----Cas服务端的配置

2024-08-27 20:38

本文主要是介绍《权限系列shiro+cas》----Cas服务端的配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前言

  • 小编用的casServer版本是4.0的,在4.0之后cas做了升级,据说变化很大,大家如果有兴趣可以到cas的官网查看。下面的所有操作都时在源码中cas文件夹中操作的。

源码地址

点击这里,去小编的GitHub上下载源码

去掉Https协议

  • 小编做的项目是企业内部使用的,如果此项目放到外网上去访问,建议不要去掉https协议。下面是去掉https协议的教程。

  • 到webapps\cas\WEB-INF\spring-configuration\warnCookieGenerator.xml
    ,找到如下配置

<bean id="warnCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"p:cookieSecure="true"p:cookieMaxAge="-1"p:cookieName="CASPRIVACY"p:cookiePath="/cas"/>
修改  p:cookieSecure="true" 为 p:cookieSecure="false"
  • webapps\cas\WEB-INF\spring-configuration\ticketGrantingTicketCookieGenerator.xml,找到如下配置
<bean id="ticketGrantingTicketCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"p:cookieSecure="true"p:cookieMaxAge="-1"p:cookieName="CASTGC"p:cookiePath="/cas"/>修改  p:cookieSecure="true" 为 p:cookieSecure="false"
  • webapps\cas\WEB-INF\deployerConfigContext.xml 文件 ,找到如下配置:
<bean id="proxyAuthenticationHandler" 
class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"p:httpClient-ref="httpClient"/>增加p:requireSecure="false"即HTTPS为不采用。
修改后为:<bean id="proxyAuthenticationHandler"
class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"p:httpClient-ref="httpClient" p:requireSecure="false"/>

修改验证方式

  • cas的服务端有默认的登录名密码,我们需要将其注释掉然后通过访问数据库校验用户名和密码。修改WEB-INF下的deployerConfigContext.xml 配置如下
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xmlns:c="http://www.springframework.org/schema/c"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:util="http://www.springframework.org/schema/util"xmlns:sec="http://www.springframework.org/schema/security"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"><bean id="authenticationManager" class="org.jasig.cas.authentication.PolicyBasedAuthenticationManager"><constructor-arg><map><entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" /><entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" /></map></constructor-arg><property name="authenticationPolicy"><bean class="org.jasig.cas.authentication.AnyAuthenticationPolicy" /></property></bean><!-- Required for proxy ticket mechanism. --><bean id="proxyAuthenticationHandler"class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"p:httpClient-ref="httpClient" p:requireSecure="false"/><!-- 设置密码的加密方式,这里使用的是MD5加密 --><bean id="passwordEncoder"class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder"c:encodingAlgorithm="MD5"p:characterEncoding="UTF-8" /><!-- 通过数据库验证身份,这个得自己去实现 --><bean id="primaryAuthenticationHandler"class="com.distinct.cas.jdbc.QueryDatabaseAuthenticationHandler"p:dataSource-ref="dataSource"p:passwordEncoder-ref="passwordEncoder"p:sql="select password from t_user where account=? and status = 'active'" /><!-- Required for proxy ticket mechanism --><bean id="proxyPrincipalResolver"class="org.jasig.cas.authentication.principal.BasicPrincipalResolver" /><!--| Resolves a principal from a credential using an attribute repository that is configured to resolve| against a deployer-specific store (e.g. LDAP).--><bean id="primaryPrincipalResolver"class="org.jasig.cas.authentication.principal.PersonDirectoryPrincipalResolver" ><property name="attributeRepository" ref="attributeRepository" /></bean><!--Bean that defines the attributes that a service may return.  This example uses the Stub/Mock version.  A real implementationmay go against a database or LDAP server.  The id should remain "attributeRepository" though.+--><bean id="attributeRepository" class="org.jasig.services.persondir.support.StubPersonAttributeDao"p:backingMap-ref="attrRepoBackingMap" /><util:map id="attrRepoBackingMap"><entry key="uid" value="uid" /><entry key="eduPersonAffiliation" value="eduPersonAffiliation" /> <entry key="groupMembership" value="groupMembership" /></util:map><!-- Sample, in-memory data store for the ServiceRegistry. A real implementationwould probably want to replace this with the JPA-backed ServiceRegistry DAOThe name of this bean should remain "serviceRegistryDao".+--><bean id="serviceRegistryDao" class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl"p:registeredServices-ref="registeredServicesList" /><util:list id="registeredServicesList"><bean class="org.jasig.cas.services.RegexRegisteredService"p:id="0" p:name="HTTP and IMAP" p:description="Allows HTTP(S) and IMAP(S) protocols"p:serviceId="^(https?|imaps?)://.*" p:evaluationOrder="10000001" /></util:list><bean id="auditTrailManager" class="com.github.inspektr.audit.support.Slf4jLoggingAuditTrailManager" /><bean id="healthCheckMonitor" class="org.jasig.cas.monitor.HealthCheckMonitor" p:monitors-ref="monitorsList" /><util:list id="monitorsList"><bean class="org.jasig.cas.monitor.MemoryMonitor" p:freeMemoryWarnThreshold="10" /><!--NOTEThe following ticket registries support SessionMonitor:* DefaultTicketRegistry* JpaTicketRegistryRemove this monitor if you use an unsupported registry.--><bean class="org.jasig.cas.monitor.SessionMonitor"p:ticketRegistry-ref="ticketRegistry"p:serviceTicketCountWarnThreshold="5000"p:sessionCountWarnThreshold="100000" /></util:list><!-- 设置数据源 --><bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"></property><property name="url" value="jdbc:mysql://127.0.0.1:3306/itoo_test?useUnicode=true&amp;characterEncoding=utf8"></property><property name="username" value="root"></property><property name="password" value="123456"></property>  </bean></beans>

小结

  • cas的登录校验大概就是这样,下一步就是更改cas的默认登录页了,我们可以将cas的默认登录页修改成自己公司的logo,下一篇文章介绍。

这篇关于《权限系列shiro+cas》----Cas服务端的配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1112723

相关文章

Redis Cluster模式配置

《RedisCluster模式配置》:本文主要介绍RedisCluster模式配置,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录分片 一、分片的本质与核心价值二、分片实现方案对比 ‌三、分片算法详解1. ‌范围分片(顺序分片)‌2. ‌哈希分片3. ‌虚

SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志

《SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志》在SpringBoot项目中,使用logback-spring.xml配置屏蔽特定路径的日志有两种常用方式,文中的... 目录方案一:基础配置(直接关闭目标路径日志)方案二:结合 Spring Profile 按环境屏蔽关

Maven 配置中的 <mirror>绕过 HTTP 阻断机制的方法

《Maven配置中的<mirror>绕过HTTP阻断机制的方法》:本文主要介绍Maven配置中的<mirror>绕过HTTP阻断机制的方法,本文给大家分享问题原因及解决方案,感兴趣的朋友一... 目录一、问题场景:升级 Maven 后构建失败二、解决方案:通过 <mirror> 配置覆盖默认行为1. 配置示

Springboot3+将ID转为JSON字符串的详细配置方案

《Springboot3+将ID转为JSON字符串的详细配置方案》:本文主要介绍纯后端实现Long/BigIntegerID转为JSON字符串的详细配置方案,s基于SpringBoot3+和Spr... 目录1. 添加依赖2. 全局 Jackson 配置3. 精准控制(可选)4. OpenAPI (Spri

maven私服配置全过程

《maven私服配置全过程》:本文主要介绍maven私服配置全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录使用Nexus作为 公司maven私服maven 私服setttings配置maven项目 pom配置测试效果总结使用Nexus作为 公司maven私

springboot加载不到nacos配置中心的配置问题处理

《springboot加载不到nacos配置中心的配置问题处理》:本文主要介绍springboot加载不到nacos配置中心的配置问题处理,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录springboot加载不到nacos配置中心的配置两种可能Spring Boot 版本Nacos

Python FastMCP构建MCP服务端与客户端的详细步骤

《PythonFastMCP构建MCP服务端与客户端的详细步骤》MCP(Multi-ClientProtocol)是一种用于构建可扩展服务的通信协议框架,本文将使用FastMCP搭建一个支持St... 目录简介环境准备服务端实现(server.py)客户端实现(client.py)运行效果扩展方向常见问题结

Nacos注册中心和配置中心的底层原理全面解读

《Nacos注册中心和配置中心的底层原理全面解读》:本文主要介绍Nacos注册中心和配置中心的底层原理的全面解读,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录临时实例和永久实例为什么 Nacos 要将服务实例分为临时实例和永久实例?1.x 版本和2.x版本的区别

如何搭建并配置HTTPD文件服务及访问权限控制

《如何搭建并配置HTTPD文件服务及访问权限控制》:本文主要介绍如何搭建并配置HTTPD文件服务及访问权限控制的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、安装HTTPD服务二、HTTPD服务目录结构三、配置修改四、服务启动五、基于用户访问权限控制六、

CentOS 7 YUM源配置错误的解决方法

《CentOS7YUM源配置错误的解决方法》在使用虚拟机安装CentOS7系统时,我们可能会遇到YUM源配置错误的问题,导致无法正常下载软件包,为了解决这个问题,我们可以替换YUM源... 目录一、备份原有的 YUM 源配置文件二、选择并配置新的 YUM 源三、清理旧的缓存并重建新的缓存四、验证 YUM 源