cas認證過濾器shiro
★. 有没有靠谱的净水或纯水设备的厂家,求联系方式!
这要看你要的具体设备是什么了?之前我们工厂新上的一个纯水设备是悦纯的。当时是我负责这块,机器的安装调试都是悦纯工厂亲自来人做的,包括调试、试用、讲解全部都说的很清楚。我感觉他们服务和产品质量都挺好的,有需要你可以联系下,联系方式是 18156052550 (微信同号)
1. shiro過濾器/* = authc把自己寫的都攔截了,走了上面的攔截器後還是會被/*攔截
我也碰到這種情況了,,,發現filters.put("authc", filter_Authc());這種方式注入filter的時候,攔截順序會失效回,,,要改成答new xx()這種方式才可以filters.put("authc", new Filter_Authc());
2. springside4.1的shiro+cas會陷入認證死循環,跳到cas伺服器登陸後無法打開頁面.Firefox提示請求循環重定
尊敬的用戶,您好!很高興為您答疑。
您在利用cas開發單點登錄系統時,不應該使用跨域的跳轉,如果因為伺服器部署架構的問題,不得不跨域也該考慮利用介面進行數據傳遞。而您貼出來的實例bean亦或濾鏡等代碼,並不會對於您瀏覽器的跳轉產生實質的影響。您的主要問題是在地址重定向上出現了邏輯上的死循環。
希望我的回答對您有所幫助,如有疑問,歡迎繼續咨詢我們。
3. shiro cas 重定向循環 怎麼解決的 哥們
多種情況會導致【循環重定向】即302報錯。你提到了shiro,在shiro最常見的情況是過濾器循環觸發,檢查思路:
通過瀏覽器debug, 找到循環訪問了哪個請求【狀態為302】, 根據這個請求url,修改shiro配置文件中:
bean名為[org.apache.shiro.spring.web.ShiroFilterFactoryBean]中
property名為[filterChainDefinitions]中的[value]對應的過濾值
當然也有可能是其他filter、controller類中的代碼反復觸發了這個url。
【建議寫一個能夠捕獲所有請求的類,例如HandlerInterceptorAdapter類,在preHandle方法中,獲取每次請求的url,有助於快速定位存在問題的uri,再找到觸發這個請求的源頭。】
4. sso和shiro的區別
SSO是單點登錄,Shiro是許可權管理,但是配合CAS可以實現SSO
推薦一套完整的Shiro Demo,免費的。
Shiro介紹文檔:http://www.sojson.com/shiro
Demo已經部署到線上,ShiroDemo:http://shiro.itboy.net
管理員帳號:admin,密碼:sojson.com 如果密碼錯誤,請用sojson。PS:你可以注冊自己的帳號,然後用管理員賦許可權給你自己的帳號,但是,每20分鍾會把數據初始化一次。建議自己下載源碼,讓Demo跑起來,然後跑的更快。
5. shiro和cas整合,web.xml怎麼配置
一、前言
Apache Shiro與Spring Security一樣是Java的一個安全框架。那為什麼與Spring整合卻用Shiro?不要問為什麼,任性!開個玩笑:D 其實我個人是認為Spring Security太過於笨重,要寫太多的過濾器。我是個怕麻煩的人,Shiro的配置簡單這就是我選擇的理由,何況Spring官方自己都推薦使用Shiro。而Shiro許可權控制與CAS單點登錄的組合更是堪稱Java安全中的***~( ̄_, ̄ )……但本文只介紹它們三者的整合配置(說白了就是給自己留個學習筆記啦),若對此方面內容感興趣的可以到網上搜索學習,在此推薦開濤大神的:《跟我學shiro》。
再次強調,以下內容僅為個人學習筆記,不是篇教程。
二、配置
Shiro最主要的就是認證與授權,而CAS的重點在於單點登錄,其實CAS與Shiro整合的話就是關於認證那塊的整合。
我們先來看web.xml中Shiro與CAS的配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!-- 引入詳情配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/cas-client-shiro.xml
</param-value>
</context-param>
<!-- shiro配置 (需寫在Spring MVC Servlet配置之前)-->
<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>
spring mvc servlet配置……
<!-- 退出 -->
<filter>
<filter-name>logoutFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>logoutFilter</filter-name>
<url-pattern>/logout</url-pattern>
</filter-mapping>
<!-- 該過濾器用於實現單點登出功能,可選配置。-->
<filter>
<filter-name>CAS Single Sign Out Filter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetBeanName</param-name>
<param-value>singleSignOutFilter</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CAS Single Sign Out Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
………………其它配置省略………………
在上面的配置中是否有留意到這貨:DelegatingFilterProxy,它會自動的把filter請求交給相應名稱的bean處理。例如在啟動時,spring會有一個filter請求,這個請求轉交給了shiroFilter這個bean去處理了。so^接下來我們就得去找找看shiroFilter在哪?
此為上文載入的cas-client-shiro.xml配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!-- shiro配置 -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<!-- 設定角色的登錄鏈接,這里為cas登錄頁面的鏈接和可配置回調地址 -->
<property name="loginUrl" value="${cas.casServerLoginUrl}?service=${cas.service}login/" />
<property name="successUrl" value="/" />
<property name="filters">
<util:map>
<!-- 添加casFilter到shiroFilter整合 -->
<entry key="casFilter" value-ref="casFilter"/>
</util:map>
</property>
<property name="filterChainDefinitions">
<value>
/login/ = casFilter
/logout = anon
/** = authc
</value>
</property>
</bean>
<!-- CasFilter為自定義的單點登錄Fileter -->
<bean id="casFilter" class="com.test.shiro.filter.CasFilter">
<!-- 配置驗證錯誤時的失敗頁面 -->
<property name="failureUrl" value="${cas.casServerLogoutUrl}?service=${cas.logoutRedirectUrl}"/>
<property name="realm" ref="casRealm"/>
</bean>
<!-- MyRealm為自定義的Realm -->
<bean id="casRealm" class="com.test.shiro.realm.MyRealm">
<property name="cacheManager" ref="shiroMemcacheManager" />
<property name="appId" value="${roomy.uap.client.appId}"/>
<property name="casServerUrlPrefix" value="${cas.host}"/>
<!-- 客戶端的回調地址設置 -->
<property name="casService" value="${cas.service}login/"/>
</bean>
<!-- 緩存管理器 -->
………………
<!-- 會話sessionDAO -->
………………
<!-- 會話管理器sessionManager -->
………………
<!-- 會話驗證調度器sessionValidationScheler -->
………………
<!-- 安全管理器securityManager -->
………………
<!-- Shiro生命周期處理器lifecycleBeanPostProcessor-->
………………
<!-- 退出 -->
<bean name="logoutFilter" class="com.test.cas.client.filter.LogoutFilterWithShiro">
<property name="casServerLogoutUrl" value="${cas.casServerLogoutUrl}"></property>
<property name="redirectUrl" value="${cas.logoutRedirectUrl}"></property>
</bean>
<!-- 單點登出 -->
<bean name="singleSignOutFilter"
class="com.test.cas.client.session.SingleSignOutFilter">
<property name="sessionMappingStorage" ref="sessionMappingStorage">
</property>
</bean>
<bean id="sessionMappingStorage" class="com.test.cas.client.session.">
<property name="cacheManager" ref="shiroMemcacheManager" />
<property name="sessionManager" ref="sessionManager" />
</bean>
以上內容眾多省略,其實我想強調的是MyRealm。恩,我們要實現的認證、預授權操作都在此自定義的Realm中實現操作。MyRealm繼承了CasRealm,CasRealm又繼承了AuthorizingRealm。所以,MyRealm中具體寫了授權實現邏輯,而認證則調用了CasRealm中的方法……
三、結語
為什麼不好好的寫一篇博文教程?首先,這方面的東西內容非常多,不是一兩篇能說的清楚的。其次,自己也是剛開始學習,並未完全掌握。最後,本人特別懶,目前只是想給自己留個學習筆記而已。
6. 怎麼自定義shiro中的過濾器來允許ajax請求後台數據
自定義過濾器:
public class extends FormAuthenticationFilter {
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
if (isLoginRequest(request, response)) {
if (isLoginSubmission(request, response)) {
return executeLogin(request, response);
} else {
// 放行 allow them to see the login page ;)
return true;
}
} else {
HttpServletRequest httpRequest = WebUtils.toHttp(request);
if (ShiroFilterUtils.isAjax(httpRequest)) {
HttpServletResponse httpServletResponse = WebUtils.toHttp(response);
httpServletResponse.sendError(ShiroFilterUtils.HTTP_STATUS_SESSION_EXPIRE);
return false;
} else {
saveRequestAndRedirectToLogin(request, response);
}
return false;
}
}
/**
* 判斷ajax請求
* @param request
* @return
*/
boolean isAjax(HttpServletRequest request){
return (request.getHeader("X-Requested-With") != null && "XMLHttpRequest".equals( request.getHeader("X-Requested-With").toString()) ) ;
}
}
封裝ajax
var Error = function () {
return {
// 初始化各個函數及對象
init: function () {
},
// 顯示或者記錄錯誤
displayError: function(response, ajaxOptions, thrownError) {
if (response.status == 404) {// 頁面沒有找到
pageContent.load($("#hdnContextPath").val() + "/page/404.action");
} else if (response.status == 401) {// session過期
SweetAlert.errorSessionExpire();
} else if (response.status == 507) {// 用戶訪問次數太頻繁
SweetAlert.error("您的訪問次數太頻繁, 請過一會再試...");
} else {//其他錯誤
window.location = $("#hdnContextPath").val() + "/page/500.action";
}
console.log(thrownError);
}
};
}();
jQuery(document).ready(function() {
Error.init();
});
JS的引用處如下:
App.blockUI();
$.ajax({
url: $("#hdnContextPath").val() + "/feedback/queryFeedBackDetail.action",
type: "POST",
async: false,
data: {"feedbackId": feedbackId, "userId": userId, "status": status},
success: function(data) {
// 忽略
7. 過濾器里獲得shiro登陸與否
Shiro的過濾器的配置是結合使用Spring的DelegatingFilterProxy與FactoryBean2種技術來完成自身過濾器的植入的,所以理專解Shiro的過濾器首先要理屬解這2者的使用。
DelegatingFilterProxy :
Spring提供的一個簡便的過濾器的處理方案,它將具體的操作交給內部的Filter對象delegate去處理,而這個delegate對象通過Spring IOC容器獲取,這里採用的是Spring的FactoryBean的方式獲取這個對象。
ShiroFilterFactoryBean:
配置如下 :
[html] view plainprint?
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
..
</bean>
由於它是個FactroyBean,所以上面的delegate真正的對象是通過它的getObject()獲取的。
8. shiro基於form表單的身份驗證過濾器可否配置兩個成功頁面
Shiro的過濾器的抄配置是結合使用Spring的DelegatingFilterProxy與FactoryBean2種技術來完成自身襲過濾器的植入的,所以理解Shiro的過濾器首先要理解這2者的使用。
DelegatingFilterProxy :
Spring提供的一個簡便的過濾器的處理方案,它將具體的操作交給內部的Filter對象delegate去處理,而這個delegate對象通過Spring IOC容器獲取,這里採用的是Spring的FactoryBean的方式獲取這個對象。
9. shiro 可以有多個過濾器嗎
可以的呢。中間用「,」分割即可,從前到後,依次執行!
推薦一套完整的Shiro Demo,免費的。
Shiro介紹文檔:http://www.sojson.com/shiro
Demo已經部署到線上,地址是http://shiro.itboy.net
管理員帳號:admin,密碼:sojson.com 如果密碼錯誤,請用sojson。PS:你可以注冊自己的帳號,然後用管理員賦許可權給你自己的帳號,但是,每20分鍾會把數據初始化一次。建議自己下載源碼,讓Demo跑起來,然後跑的更快。
10. cas有些請求路徑不需要單點登錄過濾器攔截
業務系統web應用在使用單點登錄組件時,有些請求路徑不需要單點登錄過濾器攔截,比如公共開放的路徑,不需要認證都可以自由訪問的路徑,單點登錄過濾器配置的映射路徑一般以通配符匹配路徑,但要把這些路徑單獨提取出來,讓過濾器不攔截做單點登錄處理,就需要對原有過濾器進行擴展改造,才能實現這個功能。
擴展實現代碼如下:
public class CASFilter implements Filter {
public static enum ResponseType {
BREAK, GOON, RETURN
}
...
public void doFilter(
ServletRequest request,
ServletResponse response,
FilterChain fc){
。。。
CASReceipt receipt = (CASReceipt) session.getAttribute(CAS_FILTER_RECEIPT);
if (receipt != null && isReceiptAcceptable(receipt)) {
log.trace("CAS_FILTER_RECEIPT attribute was present and acceptable - passing request through filter..");
fc.doFilter(request, response);
return;
}else{
responeType = beforeDoSSOFilter(request, response);
if(ResponseType.RETURN==responeType){
return ;
}else if(ResponseType.BREAK==responeType) {
fc.doFilter(request, response);
return;
} //else go on
}
}
//過濾器的前置處理
public ResponseType beforeDoSSOFilter(ServletRequest request,
ServletResponse response) {
return ResponseType.GOON;
}
}
註:主要看原CASFilter 類紅字部分擴展代碼。
擴展實現類BMCASFilter
package com.sitechasia.sso.bmext;
public class BMCASFilter extends CASFilter {
private final Log log = LogFactory.getLog(this.getClass());
private static String ssoclient_passedPathSet;//設置不被sso過濾器攔截的請求路徑,需要符合url路徑通配符,多個路徑可以","分割
public static final String PASSEDPATHSET_INIT_PARAM="passedPathSet";//web.xml配置文件中的參數
@Override
public void init(FilterConfig config) throws ServletException {
super.init(config);
ssoclient_passedPathSet = SSOClientPropertiesSingleton.getInstance().getProperty(ClientConstants.SSOCLIENT_PASSEDPATHSET)==null?config.getInitParameter(PASSEDPATHSET_INIT_PARAM):SSOClientPropertiesSingleton.getInstance().getProperty(ClientConstants.SSOCLIENT_PASSEDPATHSET);
}
@Override
public ResponseType beforeDoSSOFilter(ServletRequest request,
ServletResponse response) {
if (ssoclient_passedPathSet != null) {//路徑過濾
HttpServletRequest httpRequest =(HttpServletRequest)request;
String requestPath = httpRequest.getRequestURI();
// String ls_requestPath = UrlUtils.buildFullRequestUrl(httpRequest.getScheme(), httpRequest.getServerName(), httpRequest.getServerPort(), requestPath, null);
PathMatcher matcher = new AntPathMatcher();
String passedPaths[]=null;
passedPaths =ssoclient_passedPathSet.split(",");
if(passedPaths!=null){
boolean flag;
for (String passedPath : passedPaths) {
flag = matcher.match(passedPath, requestPath);//ls_requestPath
if(flag){
log.info("sso client request path '"+requestPath+"'is matched,filter chain will be continued.");
return ResponseType.BREAK;
}
}
}
}
return ResponseType.GOON;
}
}
web.xml文件中配置修改如下:
<filter>
<description>單點登陸請求過濾器</description>
<filter-name>CASFilter</filter-name>
<filter-class>com.sitechasia.sso.dmext.filter.DMCASFilter</filter-class>
...
<init-param>
<description>排除路徑</description>
<param-name>passedPathSet</param-name>
<param-value>
/**/restful/userLogin/findPassword,
/**/restful/userLogin/findIllegalLoginCount,
/**/restful/tenantManager/**,
/**/restful/lock/**,
/**/restful/export/**
</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CASFilter</filter-name>
<url-pattern>/index.jsp</url-pattern>
< /filter-mapping>
。。。
註:紅字部分為相應配置內容擴展部分
經過上述這樣擴展,配置的排除路徑作為請求時,單點登錄過濾攔截就會忽略處理,實現了目標功能要求。