`
nvry
  • 浏览: 316497 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

单点登录cas与权限管理框架shiro集成-spring项目方式 .

    博客分类:
  • Java
阅读更多

       之前那篇文章介绍了普通web项目中单点登录cas与权限管理框架shiro集成方式,这里说下spring项目中的集成方式,首先还是配置一个filter

<filter>
	    <filter-name>shiroFilter</filter-name>
	    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
	    <init-param>
	        <param-name>targetFilterLifecycle</param-name>
	        <param-value>true</param-value>
	    </init-param>
	</filter>
	
	<filter-mapping>
	    <filter-name>shiroFilter</filter-name>
	    <url-pattern>/*</url-pattern>
	</filter-mapping>

 

       然后就是shiro的spring bean配置,其实就是把之前的shiro.ini的东西配成spring的bean,shiro-config.xml文件如下:

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.0.xsd
     http://www.springframework.org/schema/util
     http://www.springframework.org/schema/util/spring-util-3.0.xsd"
	default-lazy-init="true">
	
	<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
    	<property name="securityManager" ref="securityManager"/>
    	<!-- 设定角色的登录链接,这里为cas登录页面的链接可配置回调地址  -->
    	<property name="loginUrl" value="https://www.cas.com/login?service=http://www.example.com/shiro-cas" />
	    
	    <property name="filters">
	        <util:map>
	        	<!-- 添加casFilter到shiroFilter -->
	            <entry key="casFilter" value-ref="casFilter"/>
	        </util:map>
	    </property> 
    	<property name="filterChainDefinitions">
        	<value>        		
	            /shiro-cas = casFilter
				/admin/** = roles[ROLE_USER]
				/** = anon
        	</value>
    	</property>
	</bean>
	
	<bean id="casFilter" class="org.apache.shiro.cas.CasFilter">
		<!-- 配置验证错误时的失败页面  -->
		<property name="failureUrl" value="/error.jsp"/>
	</bean>
	
	<bean id="casRealm" class="org.apache.shiro.cas.CasRealm">
		<property name="defaultRoles" value="ROLE_USER"/>		
		<property name="casServerUrlPrefix" value="https://www.cas.com"/>
		<!-- 客户端的回调地址设置,必须和下面的shiro-cas过滤器拦截的地址一致 -->
		<property name="casService" value="http://www.example.com/shiro-cas"/>
	</bean>
	
	<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">  	
    	<property name="realm" ref="casRealm"/>
    	<property name="subjectFactory" ref="casSubjectFactory"/>
	</bean>
	
	<!-- 如果要实现cas的remember me的功能,需要用到下面这个bean,并设置到securityManager的subjectFactory中 -->
	<bean id="casSubjectFactory" class="org.apache.shiro.cas.CasSubjectFactory"/>

	
	<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

	<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    	<property name="staticMethod" value="org.apache.shiro.SecurityUtils.setSecurityManager"/>
    	<property name="arguments" ref="securityManager"/>
	</bean>
</beans>

 

分享到:
评论
4 楼 liveabc 2015-10-30  
你好,能发送一份代码不? liveabc@163.com 谢谢了
3 楼 zqb666kkk 2015-09-26  
请问有示例源码吗
2 楼 nvry 2013-07-12  
little_shieh 写道
<!-- For simplest integration, so that all SecurityUtils.* methods work in all cases, -->
<!-- make the securityManager bean a static singleton.  DO NOT do this in web  applications - see the 'Web Applications' section below instead.                 -->

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="staticMethod" value="org.apache.shiro.SecurityUtils.setSecurityManager"/>
    <property name="arguments" ref="securityManager"/>
</bean>

你确认你按照这个配置CAS成功了吗?


-----------------------
成功了,我是按照这种方式配置的。
1 楼 little_shieh 2013-07-05  
<!-- For simplest integration, so that all SecurityUtils.* methods work in all cases, -->
<!-- make the securityManager bean a static singleton.  DO NOT do this in web  applications - see the 'Web Applications' section below instead.                 -->

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="staticMethod" value="org.apache.shiro.SecurityUtils.setSecurityManager"/>
    <property name="arguments" ref="securityManager"/>
</bean>

你确认你按照这个配置CAS成功了吗?

相关推荐

    shiro-jar-1.7.0.zip相关资源包

    解决:升級1.7后附件...shiro-cas-1.7.0.jar shiro-core-1.7.0.jar shiro-ehcache-1.7.0.jar shiro-spring-1.7.0.jar shiro-web-1.7.0.jar CustomShiroFilterFactoryBean.java spring-context-shiro.xml 修改说明.txt

    shiro-jar.zip

    shiro-all-1.7.1.jar,shiro-aspectj-1.7.1.jar,shiro-cache-1.7.1.jar,shiro-config-core-1.7.1.jar,shiro-config-ogdl-1.7.1.jar,shiro-core-1.7.1.jar,shiro-crypto-cipher-1.7.1.jar,shiro-crypto-core-1.7.1.jar...

    shiro-spring-1.3.2-API文档-中英对照版.zip

    赠送jar包:shiro-spring-1.3.2.jar 赠送原API文档:shiro-spring-1.3.2-javadoc.jar 赠送源代码:shiro-spring-1.3.2-sources.jar 包含翻译后的API文档:shiro-spring-1.3.2-javadoc-API文档-中文(简体)-英语-...

    单点登录CAS与权限管理框架Shiro集成

    CAS与权限管理框架Shiro集成

    shiro-cas-1.2.3-API文档-中英对照版.zip

    赠送jar包:shiro-cas-1.2.3.jar; 赠送原API文档:shiro-cas-1.2.3-javadoc.jar; 赠送源代码:shiro-cas-1.2.3-sources.jar; 赠送Maven依赖信息文件:shiro-cas-1.2.3.pom; 包含翻译后的API文档:shiro-cas-...

    shiro(shiro-all-1.8.0.jar)

    shiro(shiro-all-1.8.0.jar)

    shiro-spring-1.3.2-API文档-中文版.zip

    赠送jar包:shiro-spring-1.3.2.jar; 赠送原API文档:shiro-spring-1.3.2-javadoc.jar; 赠送源代码:shiro-spring-1.3.2-sources.jar; 包含翻译后的API文档:shiro-spring-1.3.2-javadoc-API文档-中文(简体)版...

    shiro-cas-1.2.3-API文档-中文版.zip

    赠送jar包:shiro-cas-1.2.3.jar; 赠送原API文档:shiro-cas-1.2.3-javadoc.jar; 赠送源代码:shiro-cas-1.2.3-sources.jar; 赠送Maven依赖信息文件:shiro-cas-1.2.3.pom; 包含翻译后的API文档:shiro-cas-...

    shiro-spring-1.2.3-API文档-中英对照版.zip

    赠送jar包:shiro-spring-1.2.3.jar; 赠送原API文档:shiro-spring-1.2.3-javadoc.jar; 赠送源代码:shiro-spring-1.2.3-sources.jar; 赠送Maven依赖信息文件:shiro-spring-1.2.3.pom; 包含翻译后的API文档:...

    shiro-spring-1.4.0-API文档-中英对照版.zip

    赠送jar包:shiro-spring-1.4.0.jar; 赠送原API文档:shiro-spring-1.4.0-javadoc.jar; 赠送源代码:shiro-spring-1.4.0-sources.jar; 赠送Maven依赖信息文件:shiro-spring-1.4.0.pom; 包含翻译后的API文档:...

    shiro-spring-1.4.0-API文档-中文版.zip

    赠送jar包:shiro-spring-1.4.0.jar; 赠送原API文档:shiro-spring-1.4.0-javadoc.jar; 赠送源代码:shiro-spring-1.4.0-sources.jar; 赠送Maven依赖信息文件:shiro-spring-1.4.0.pom; 包含翻译后的API文档:...

    shiro-spring-boot-web-starter-1.4.0.jar

    java运行依赖jar包

    shiro-spring-1.2.2.jar

    shiro spring 1 2 2 jar

    单点登录sso-shiro-cas-maven

    #### 以上就是单点登录管理的主要配置 ## 应用系统的配置node1 1. 应用系统采用shiro做权限控制,并且跟cas集成 2. 在/spring-node-1/src/main/resources/conf/shiro.properties 文件中 ``` properties shiro....

    shiro-spring-1.2.3-API文档-中文版.zip

    赠送jar包:shiro-spring-1.2.3.jar; 赠送原API文档:shiro-spring-1.2.3-javadoc.jar; 赠送源代码:shiro-spring-1.2.3-sources.jar; 赠送Maven依赖信息文件:shiro-spring-1.2.3.pom; 包含翻译后的API文档:...

    shiro-all-1.3.2.jar

    shiro-all-1.3.2.jar

    shiro-all-1.2.3.jar

    apache权限框架的缓存管理器要用到的jar包 shiro-all-1.2.3.jar

    shiro-config-core-1.4.0-API文档-中英对照版.zip

    赠送jar包:shiro-config-core-1.4.0.jar; 赠送原API文档:shiro-config-core-1.4.0-javadoc.jar; 赠送源代码:shiro-config-core-1.4.0-sources.jar; 赠送Maven依赖信息文件:shiro-config-core-1.4.0.pom; ...

    shiro-web-1.2.0.jar

    shiro-web-1.2.0.jar

Global site tag (gtag.js) - Google Analytics