shrio cas integration, configuration of multiple login pages, customization of session expiration verification

shrio cas integration, configuration of multiple login pages, customization of session expiration verification:

A: The client configures the request and return

1. Login, logout, and login failure interception:

This directly configures shrio's ordinary page configuration road, and changes it to the login and logout address of the cas server, and the parameter address with it is the corresponding completion function.

The address of this service to be called later:

 

<bean id="logoutFilter" class="org.apache.shiro.web.filter.authc.LogoutFilter">

<property name="redirectUrl"

value="http://10.0.1.222:8080/cas/logout?service=http://localhost:8080/web/siteindex.do" />

</bean>

 

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">

<property name="securityManager" ref="securityManager" />

<property name="loginUrl"

value="http://10.0.1.222:8080/cas/login?service=http://localhost:8080/web/cas" />

<!-- <property name="successUrl"

value="http://10.0.1.222:8080/web/1.jsp" /> -->

<property name="successUrl"

value="http://localhost:8080/web/siteindex.do" />

<property name="filters">

<map>

<!-- <entry key="authc" value-ref="formAuthenticationFilter" /> -->

<entry key="cas" value-ref="casFilter" />

<entry key="logout" value-ref="logoutFilter" />

</map>

</property>

<!-- Important: /cas = cas must be added to tell /cas to use casFilter for processing -->

<!-- Important: logout is the logout filter -->

<property name="filterChainDefinitions">

<value>

/resources /** =anon (this typed variable is now on the path or released to a subdirectory) ( @RequestMapping(value = "/chat/offer/list/{conobjKey}")

public String chatWithConobjKey(@RequestParam(value="tradeCustomerKey", required=false) String tradeCustomerKey,HttpSession session, HttpServletRequest request,HttpServletResponse response, Model model, @PathVariable String conobjKey

) throws EsteelException, UnsupportedEncodingException 

/reg/**=anon

/etc/**=anon

/js/**=anon

/plugins/**=anon

/cas = cas

/logout = logout

/** = user

</value>

</property>

</bean>

 

2,项目请求的拦截

 

 

在CasRealm中配置一个为每一个请求接收ticket的拦截的请求,并且验证放行,这里配置的是

哪里的过滤器那么之后所有的请求的项目地址就是那个

 

<bean id="casRealm" class="org.apache.shiro.cas.CasRealm">

<property name="defaultRoles" value="ROLE_USER" />

<!-- 重要:这个是用来获取ticket的casServerURL的前缀,所以不能有login -->

<property name="casServerUrlPrefix" value="http://10.0.1.222:8080/cas/" />//////cas服务不要login

<!--客户端的回调地址设置,必须和上面的shiro-cas过滤器拦截的地址一致 -->

<!-- <property name="casService" value="http://localhost:8080/web/cas" /> -->

        <property name="casService" value="http://localhost:8080/web/cas" />///////////自己集成的过滤器

</bean>

 

 

 

 

<!-- 用来接受ticket的filter -->

<bean id="casFilter" class="org.apache.shiro.cas.CasFilter">

<!-- <property name="failureUrl"

value="http://localhost:8080/web/resources/failure.html" /> -->

<property name="failureUrl"

value="http://10.0.1.222:8080/esteelHome/index" />

<!-- <property name="successUrl"

value="http://10.0.1.222:8080/esteelHome/index" />  -->

            </bean>

 

 

 

 

 

 

 

B:cas服务端

将https改为http否则session写不进去

<bean id="proxyAuthenticationHandler"

          class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"

 p:requireSecure="false"        

p:httpClient-ref="httpClient" />

一般服务端只需要配置验证方式,及加密方式

http://wenku.baidu.com/link?url=lE3_0nBGsLtAQtHp9Bo_rD8ScUSMGjSaKwBW5BxfLhU4GU55sXN15UegxaFs1i6V7lULhoEL9DHC-kasUx1zPlPic26FR7SwPMjfMcnKPgi

可以设置同一个浏览器关闭打开都可

 

同时有关验证方式,机密算法等都在服务端配置

 

C:配置解析

 

 

登入配置要带内部的票拦截器,登出不必只要带本地服务的登出地址,权限中的请求也要带票据拦截器(cas不必带login)

cas服务地址后面的就是cas服务执行完了之后回调客户端的地址比如回调的登出页面,本系统的ticket过滤器。

 

 

D:多个登录页面实现的方案:

 

登录登出配置时需要传参的&转义,这种传参数可以在这个默认页面的基础上根据参数值显示不同的登录页面

客户端配置:

 

<property name="loginUrl" value="http://localhost:8080/cas/login?a=222&amp;service=http://localhost:8080/web/cas" />

 

配置多个登录的拦截器(实际上一个拦截器,不同的名字)(符合这些拦截器的特征的就走这几个拦截跳出不同的登录页,不符合的就用默认的拦截器的配置的地址参数,

用,默认的登录页)

 

换句话说:不同loginurl请求用不同的过滤器即可,在shrio中加过滤器,类似用过滤规则获取用户信息,但是又不要登录,

不同的过滤规则对应不同的路劲

 

参考:

http://bbs.csdn.net/topics/390578669

shiro中多用户的登陆页面(multiple login pages)配置

http://blog.csdn.net/win7system/article/details/50827250

 

本项目的多登陆页面的配置示例:

                 <!--左上角登录请求  -->

<bean id="osLogin"  

   class="org.apache.shiro.web.filter.authc.FormAuthenticationFilter">  

   <property name="loginUrl" value="http://localhost:8080/cas/login?a=0&amp;service=http://localhost:8081/web/cas" />  

   <property name="successUrl" value="http://localhost:8081/web/siteindex.do" />  

</bean>  

<!--中间会员中心登录请求  -->

<bean id="oiLogin"  

   class="org.apache.shiro.web.filter.authc.FormAuthenticationFilter">  

   <property name="loginUrl" value="http://localhost:8080/cas/login?a=3&amp;service=http://localhost:8081/web/cas" />  

   <property name="successUrl" value="http://localhost:8081/web/siteindex.do" />  

</bean> 

<!-- 会员中心登录请求 -->

<bean id="csLogin"  

   class="org.apache.shiro.web.filter.authc.FormAuthenticationFilter">  

   <property name="loginUrl" value="http://localhost:8080/cas/login?a=2&amp;service=http://localhost:8081/web/cas" />  

   <property name="successUrl" value="http://localhost:8081/web/siteindex.do" />  

</bean> 

 

//默认的登录拦截根据需要写一个参数(决定调用哪个页面)

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">

<property name="securityManager" ref="securityManager" />

<!-- <property name="loginUrl"

value="http://10.0.1.222:8080/cas/login?service=http://localhost:8081/web/cas" /> -->

<property name="loginUrl"

value="http://localhost:8080/cas/login?a=2&amp;service=http://localhost:8081/web/cas" >

</property>

<property name="successUrl"

value="http://localhost:8081/web/siteindex.do" />

<property name="filters">

<map>

<!-- <entry key="authc" value-ref="formAuthenticationFilter" /> -->

<entry key="cas" value-ref="casFilter" />

<entry key="logout" value-ref="logoutFilter" />

<entry key="osLogin" value-ref="osLogin" />

<entry key="oiLogin" value-ref="oiLogin" />

<entry key="csLogin" value-ref="csLogin" />

</map>

</property>

<!-- 重要:必须加上/cas = cas来告诉/cas用casFilter来处理 -->

<!-- 重要:logout为登出filter /myaccount/getFirmCenter =csLogin-->

<property name="filterChainDefinitions">

<value>

   /wareTpl/showWares.do=anon

   /siteindex.do/**=anon

   /showPurpose=anon

   /information/info/toOreShipments=anon

   /jiaoyiguize=anon

   /bid/issue/toInvitationUI=anon

   /bid/issue/toBidNoticeUI=anon

   /biden!noticeIndexUI.do=anon

   /buding.jsp=anon

   /hqConObj/cjjl.do=anon

   /myaccount/getPowerCount=anon

   /tbPowerGroup/createTopMenuTree=anon

   /reg/registerUI= anon

   /register/**=anon

/resources/**=anon

/reg/**=anon

/etc/**=anon

/js/**=anon

/plugins/**=anon

/cas = cas

/logout = logout

/osLogin = osLogin

/oiLogin = oiLogin

/csLogin = csLogin

/osLogin/login = user

       /oiLogin/login = user

   /csLogin/login = user

/** = user

</value>

</property>

</bean>

 

 

服务端获取:

cas传的值页面可以直接getParameter();(CAS服务的默认登录页面,view/jsp/default/ui/casLoginView.jsp)

<%

String path = request.getContextPath();

request.setAttribute("path", path);

String sform=(String)request.getParameter("a");

out.print("=========="+sform);

%>

 

 

<% out.print("=========="+sform);%>

如果jsp有错,刷新时有时会出现有时不会出现,并且> token引用错误

 

 

E:session的校验订制化

jseesionId 就是cookie就是TGT的id

 

如果用定制化的cookie即就是有特定名称的cookie,不叫jsessionId其他一样只要配置即可esteelHome中,

<property name="domain" value="10.0.1.222" />这个不写则罢默认取A/N(但是验证和域名无关)

(不像单纯用cookie要用一级域名相同才可),如果写的话就同样写一级域名,这是几个单点的系统都需要一级域名相同

才可单点登录否则获取不到之前其他点登录的cookie所以就不能完成单点登录,回写用户信息(baidu.com 一级域名  www.baidu.com 二级域名 m.v.baidu.com三级域名

后缀(.com)前面有n个点这个域名就是(n+1)级域名

com.cn这种后缀要连起来看做一个后缀整体。)

 

 

注:cas的单点登录和域名无关,所以domain属性可以注释掉

 

之所以定制sessionId即cookie,是为了实现定时检验cookie的有效性,无效时重行登录,这个一般集成在权限管理器中

<!-- 28行引用的,安全管理器 -->

<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">

<property name="realm" ref="casRealm" />

<property name="subjectFactory" ref="casSubjectFactory" />

<property name="rememberMeManager" ref="rememberMeManager" />

<property name="sessionManager" ref="sessionManager" />

<!-- <property name="sessionMode" value="native" /> -->

<!-- <property name="cacheManager" ref="cacheManager" /> -->

</bean>

 

<!-- f6行引用的,session管理器 -->

<bean id="sessionManager"

class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">

<property name="globalSessionTimeout" value="1800000" />

<property name="deleteInvalidSessions" value="true" />

<property name="sessionValidationSchedulerEnabled" value="true" />

<property name="sessionValidationScheduler" ref="sessionValidationScheduler" />

<property name="sessionDAO" ref="sessionDAO" />

<property name="sessionIdCookieEnabled" value="true" />

<property name="sessionIdCookie" ref="sessionIdCookie" />

</bean>

 

<!-- 73行引用的, 会话验证调度器,用于定期的验证会话是否已过期,如果过期将停止会话 -->

<bean id="sessionValidationScheduler"

class="org.apache.shiro.session.mgt.ExecutorServiceSessionValidationScheduler">

<property name="interval" value="1800000" />

<property name="sessionManager" ref="sessionManager" />

</bean>

<!-- 81行引用的, sessionIdCookie -->

<bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie">

<!-- 默认name=JSESSIONID -->

<constructor-arg value="FFF6COOKIE" />

<property name="path" value="/" />

<property name="maxAge" value="3600" />

<property name="httpOnly" value="true" />

<!-- 注释掉domain为A/N -->

<property name="domain" value="10.0.1.222" />//写成和其他单点系统相同的域名,如果其他是localhost,这个也要换成localhost

</bean>

 

 

 

session的设置及前端获取类似普通的值桟:

CusUserBean cusUserBean = CASUtil.getCusUserBean();

 

session.setAttribute(Constants.SESSION_FIRM,cusUserBean);

${SESSION_FIRM.WEB_USERID}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326486120&siteId=291194637