本文整理匯總了Java中org.apache.shiro.spring.web.ShiroFilterFactoryBean.setFilterChainDefinitionMap方法的典型用法代碼示例。如果您正苦於以下問題:Java ShiroFilterFactoryBean.setFilterChainDefinitionMap方法的具體用法?Java ShiroFilterFactoryBean.setFilterChainDefinitionMap怎麽用?Java ShiroFilterFactoryBean.setFilterChainDefinitionMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.spring.web.ShiroFilterFactoryBean
的用法示例。
在下文中一共展示了ShiroFilterFactoryBean.setFilterChainDefinitionMap方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: shiroFilter
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
@Bean
public ShiroFilterFactoryBean shiroFilter() {
ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean();
//設置Filter映射
LinkedHashMap<String, Filter> filterMap = new LinkedHashMap<>();
DefaultCasFilter casFilter = new DefaultCasFilter();
casFilter.setFailureUrl(loginProperties.getFailureUrl()); //配置驗證錯誤時的失敗頁麵
casFilter.setReloginUrl(loginProperties.getCasLogin() + "&msg={0}"); //驗證錯誤後顯示登錄頁麵,並提示錯誤信息。隻試用於ErrorContext異常
casFilter.setLogoutUrl(loginProperties.getCasLogout());
filterMap.put("casFilter", casFilter);
LogoutFilter logoutFilter = new LogoutFilter();
logoutFilter.setRedirectUrl(loginProperties.getCasLogout() + "?service=" + loginProperties.getCasLogoutCallback());
filterMap.put("logoutFilter", logoutFilter);
filterMap.put("perms", new DefaultPermissionsAuthorizationFilter());
filterMap.put("authc", new DefaultFormAuthenticationFilter());
filterMap.put("sense", new SenseLoginFilter());
factoryBean.setFilters(filterMap);
factoryBean.setSecurityManager(securityManager());
factoryBean.setLoginUrl(loginProperties.getCasLogin());
factoryBean.setUnauthorizedUrl(loginProperties.getUnauthorizedUrl());
//加載權限配置
Ini ini = new Ini();
ini.loadFromPath(loginProperties.getShiroFilterFile());
//did they explicitly state a 'urls' section? Not necessary, but just in case:
Ini.Section section = ini.getSection(IniFilterChainResolverFactory.URLS);
if (MapUtils.isEmpty(section)) {
//no urls section. Since this _is_ a urls chain definition property, just assume the
//default section contains only the definitions:
section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
}
factoryBean.setFilterChainDefinitionMap(section);
return factoryBean;
}
示例2: loadShiroFilterChain
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
/**
* 加載shiroFilter權限控製規則(從數據庫讀取然後配置)
*
* @author SHANHY
* @create 2016年1月14日
*/
private void loadShiroFilterChain(ShiroFilterFactoryBean shiroFilterFactoryBean){
/////////////////////// 下麵這些規則配置最好配置到配置文件中 ///////////////////////
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
// authc:該過濾器下的頁麵必須驗證後才能訪問,它是Shiro內置的一個攔截器org.apache.shiro.web.filter.authc.FormAuthenticationFilter
filterChainDefinitionMap.put("/admin/**", "authc");// 這裏為了測試,隻限製/user,實際開發中請修改為具體攔截的請求規則
// anon:它對應的過濾器裏麵是空的,什麽都沒做
logger.info("##################從數據庫讀取權限規則,加載到shiroFilter中##################");
// filterChainDefinitionMap.put("/user/edit/**", "authc,perms[user:edit]");// 這裏為了測試,固定寫死的值,也可以從數據庫或其他配置中讀取
//
filterChainDefinitionMap.put("/login", "anon");
filterChainDefinitionMap.put("/**", "anon");//anon 可以理解為不攔截
// filterChainDefinitionMap.put("/admin/login","anon");
// filterChainDefinitionMap.put("/admin/thymeleaf/cache/clear","anon");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
}
示例3: shiroFilter
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
@Bean(name="shiroFilter")
public ShiroFilterFactoryBean shiroFilter(@Qualifier("securityManager")SecurityManager manager) {
ShiroFilterFactoryBean bean=new ShiroFilterFactoryBean();
bean.setSecurityManager(manager);
//配置登錄的url和登錄成功的url
bean.setLoginUrl("/login");
bean.setSuccessUrl("/home");
//配置訪問權限
LinkedHashMap<String, String> filterChainDefinitionMap=new LinkedHashMap<>();
filterChainDefinitionMap.put("/login", "anon"); //表示可以匿名訪問
filterChainDefinitionMap.put("/common/**", "anon");
filterChainDefinitionMap.put("/js/**","anon");
filterChainDefinitionMap.put("/druid/**","anon");
filterChainDefinitionMap.put("/captcha","anon");
filterChainDefinitionMap.put("/**", "authc");//表示需要認證才可以訪問
bean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return bean;
}
示例4: getShiroFilterFactoryBean
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean getShiroFilterFactoryBean() {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
// 必須設置 SecurityManager
shiroFilterFactoryBean.setSecurityManager(securityManager());
// 如果不設置默認會自動尋找Web工程根目錄下的"/login.jsp"頁麵
shiroFilterFactoryBean.setLoginUrl("/login");
// 登錄成功後要跳轉的連接
shiroFilterFactoryBean.setSuccessUrl("/user");
shiroFilterFactoryBean.setUnauthorizedUrl("/403");
// 添加casFilter到shiroFilter中
Map<String, Filter> filters = new HashMap<String, Filter>();
filters.put("authc",new FormAuthenticationFilter());
shiroFilterFactoryBean.setFilters(filters);
Map<String,String> shiroFilterChainDefinitions = Maps.newHashMap();
shiroFilterChainDefinitions.put("/static/**","anon");
shiroFilterFactoryBean.setFilterChainDefinitionMap(shiroFilterChainDefinitions);
return shiroFilterFactoryBean;
}
示例5: getShiroFilterFactoryBean
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager securityManager) {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
shiroFilterFactoryBean
.setSecurityManager(securityManager);
shiroFilterFactoryBean.setLoginUrl("/login");
shiroFilterFactoryBean.setSuccessUrl("/");
filterChainDefinitionMap.put("/login", "authc");
filterChainDefinitionMap.put("/logout", "logout");
filterChainDefinitionMap.put("/static/**", "anon");
filterChainDefinitionMap.put("/api/**", "anon");
filterChainDefinitionMap.put("/register/**", "anon");
filterChainDefinitionMap.put("/admin/**", "roles[admin]");
filterChainDefinitionMap.put("/**", "user");
shiroFilterFactoryBean
.setFilterChainDefinitionMap(filterChainDefinitionMap);
return shiroFilterFactoryBean;
}
示例6: loadShiroFilterChain
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
/**
* 加載ShiroFilter權限控製規則
*/
private void loadShiroFilterChain(ShiroFilterFactoryBean factoryBean, CasConfig casConfig) {
/**下麵這些規則配置最好配置到配置文件中*/
Map<String, String> filterChainMap = new LinkedHashMap<String, String>();
filterChainMap.put(casConfig.getCasFilterUrlPattern(), CAS_FILTER);//shiro集成cas後,首先添加該規則
filterChainMap.put("/user", "authc");
filterChainMap.put("/inde", "authc");
filterChainMap.put("/userGet", "authc");
filterChainMap.put("/casLogin", "authc");
filterChainMap.put("/user/edit/**", "authc,perms[user:edit]");
filterChainMap.put("/restlogin", "anon");
filterChainMap.put("/**", "anon");
// filterChainMap.put("/shiro-cas", "cas");
factoryBean.setFilterChainDefinitionMap(filterChainMap);
}
示例7: getShiroFilterFactoryBean
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean getShiroFilterFactoryBean() {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
shiroFilterFactoryBean.setSecurityManager(securityManager());
shiroFilterFactoryBean.setLoginUrl("/login.html");
shiroFilterFactoryBean.setSuccessUrl("/overview/dashboard.html");
Map<String, Filter> filters = new LinkedHashMap<String, Filter>();
filters.put("authc", createLoginFilter());
filters.put("forceLogout", new ForceLogoutFilter());
shiroFilterFactoryBean.setFilters(filters);
filterChainDefinitionMap.put("/static/**", "anon");
filterChainDefinitionMap.put("/test/**", "anon");
filterChainDefinitionMap.put("/logout", "logout");
filterChainDefinitionMap.put("/authenticated", "authc");
filterChainDefinitionMap.put("/login.json", "authc");
filterChainDefinitionMap.put("/**", "user");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return shiroFilterFactoryBean;
}
示例8: shirFilter
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
@Bean("shiroFilter")
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
shiroFilter.setSecurityManager(securityManager);
shiroFilter.setLoginUrl("/login.html");
//shiroFilter.setSuccessUrl("/index.html");
shiroFilter.setUnauthorizedUrl("/");
Map<String, String> filterMap = new LinkedHashMap<>();
filterMap.put("/public/**", "anon");
filterMap.put("/webjars/**", "anon");
filterMap.put("/api/**", "anon");
//swagger配置
filterMap.put("/swagger**", "anon");
filterMap.put("/v2/api-docs", "anon");
filterMap.put("/swagger-resources/configuration/ui", "anon");
filterMap.put("/login.html", "anon");
filterMap.put("/sys/login", "anon");
filterMap.put("/captcha.jpg", "anon");
filterMap.put("/**", "authc");
shiroFilter.setFilterChainDefinitionMap(filterMap);
return shiroFilter;
}
示例9: shiroFilter
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
/**
* shiroFilter
* @param manager
* @return
*/
@Bean(name="shiroFilter")
public ShiroFilterFactoryBean shiroFilter(@Qualifier("securityManager") SecurityManager manager) {
ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
bean.setSecurityManager(manager);
// 配置登錄的url
bean.setLoginUrl("/login");
//bean.setSuccessUrl("/admin/main");
// 過濾鏈
LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
filterChainDefinitionMap.put("/login", "anon"); // 表示可以匿名訪問
filterChainDefinitionMap.put("/admin/**", "authc");// 管理員權限需要驗證過濾
bean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return bean;
}
示例10: shiroFilter
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
@Bean(name="shiroFilter")
public ShiroFilterFactoryBean shiroFilter(@Qualifier("securityManager") SecurityManager manager) {
ShiroFilterFactoryBean bean=new ShiroFilterFactoryBean();
bean.setSecurityManager(manager);
//配置登錄的url和登錄成功的url
bean.setLoginUrl("/login");
//配置訪問權限
LinkedHashMap<String, String> filterChainDefinitionMap=new LinkedHashMap<>();
filterChainDefinitionMap.put("/login", "anon"); //表示可以匿名訪問
filterChainDefinitionMap.put("/captcha","anon");
filterChainDefinitionMap.put("/common/**", "anon");
filterChainDefinitionMap.put("/default/**","anon");
filterChainDefinitionMap.put("/druid/**", "anon");
filterChainDefinitionMap.put("/**", "authc");//表示需要認證才可以訪問
//filterChainDefinitionMap.put("/**", "anon");
bean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return bean;
}
示例11: getShiroFilterFactoryBean
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
@Bean(name = "shiroFilter")
@DependsOn("securityManager")
@ConditionalOnMissingBean
public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultSecurityManager securityManager, Realm realm, ShiroFilterRegistry registry) {
securityManager.setRealm(realm);
Map<String, String> filterDef = swapKeyValue(properties.getFilterChainDefinitions());
log.info("過慮器配置: {}", filterDef);
log.info("自定義過慮器: {}", registry.getFilterMap());
ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
shiroFilter.setSecurityManager(securityManager);
shiroFilter.setLoginUrl(properties.getLoginUrl());
shiroFilter.setSuccessUrl(properties.getSuccessUrl());
shiroFilter.setUnauthorizedUrl(properties.getUnauthorizedUrl());
shiroFilter.setFilterChainDefinitionMap(filterDef);
shiroFilter.getFilters().putAll(registry.getFilterMap());
return shiroFilter;
}
示例12: shiroFilter
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean shiroFilter() {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
shiroFilterFactoryBean.setSecurityManager(securityManager);
shiroFilterFactoryBean.setLoginUrl("/admin");
shiroFilterFactoryBean.setSuccessUrl("/admin");
shiroFilterFactoryBean.setUnauthorizedUrl("/error");
Map<String, Filter> filters = Application.getSecurityfilters();
AjaxAuthenticationFilter ajaxAuthenticationFilter = new AjaxAuthenticationFilter();
ajaxAuthenticationFilter.setRobotPrevention(new CaptchaRobotPrevention());
filters.put(DefaultFilter.authc.name(), ajaxAuthenticationFilter);
shiroFilterFactoryBean.setFilters(filters);
shiroFilterFactoryBean.setFilterChainDefinitionMap(Application.getSecurityFilterChainDefinitionMap());
return shiroFilterFactoryBean;
}
示例13: shiroFilter
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
@Bean
public ShiroFilterFactoryBean shiroFilter() {
final ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
shiroFilterFactoryBean.setSecurityManager(securityManager());
shiroFilterFactoryBean.setLoginUrl("/member/login");
shiroFilterFactoryBean.setSuccessUrl("/home/index");
shiroFilterFactoryBean.setUnauthorizedUrl("/error/401");
final Map<String, Filter> filters = Maps.newHashMap();
filters.put("authc", this.authcFilter());
filters.put("membership", this.membershipFilter());
shiroFilterFactoryBean.setFilters(filters);
final Map<String, String> chains = Maps.newLinkedHashMap();
chains.put("/member/logout", "logout");
chains.put("/", this.configProperties.getShiro().getFilters());
chains.put("/home/**", this.configProperties.getShiro().getFilters());
chains.put("/views/**", this.configProperties.getShiro().getFilters());
chains.put("/rest/**", this.configProperties.getShiro().getFilters());
chains.put("/**", "anon");
shiroFilterFactoryBean.setFilterChainDefinitionMap(chains);
return shiroFilterFactoryBean;
}
示例14: shiroFilter
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
@Bean
public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager, LogoutFilter logoutFilter) {
ShiroFilterFactoryBean sffb = new ShiroFilterFactoryBean();
sffb.setSecurityManager(securityManager);
//
sffb.getFilters().put("logout", logoutFilter);
//
sffb.setLoginUrl(WebappPath.getWebappPath() + "/a/user/loginForm");
// TODO: ?? sffb.setSuccessUrl("/");
sffb.setUnauthorizedUrl(WebappPath.getWebappPath() + "/a/error/unauthorized");
//
sffb.setFilterChainDefinitionMap(ImmutableMap.<String, String>builder()
.put(WebappPath.getWebappPath() + "/a/user/loginForm", "authc")
.put(WebappPath.getWebappPath() + "/a/user/logout", "logout")
.put(WebappPath.getWebappPath() + "/a/shiro/restricted", "user")
.put(WebappPath.getWebappPath() + "/a/shiro/privileged", "user, roles[never_given_permission]")
.build());
//
LOG.debug(ObjectUtils.toString(sffb.getFilters()));
//
return sffb;
}
示例15: loadShiroFilterChain
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入方法依賴的package包/類
/**
* 加載shiroFilter權限控製規則(從數據庫讀取然後配置),角色/權限信息由MyShiroCasRealm對象提供doGetAuthorizationInfo實現獲取來的
*
* @author SHANHY
* @create 2016年1月14日
*/
private void loadShiroFilterChain(ShiroFilterFactoryBean shiroFilterFactoryBean, UserDao userDao){
/////////////////////// 下麵這些規則配置最好配置到配置文件中 ///////////////////////
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
// authc:該過濾器下的頁麵必須登錄後才能訪問,它是Shiro內置的一個攔截器org.apache.shiro.web.filter.authc.FormAuthenticationFilter
// anon: 可以理解為不攔截
// user: 登錄了就不攔截
// roles["admin"] 用戶擁有admin角色
// perms["permission1"] 用戶擁有permission1權限
// filter順序按照定義順序匹配,匹配到就驗證,驗證完畢結束。
// url匹配通配符支持:? * **,分別表示匹配1個,匹配0-n個(不含子路徑),匹配下級所有路徑
//1.shiro集成cas後,首先添加該規則
filterChainDefinitionMap.put(casFilterUrlPattern, "casFilter");
//filterChainDefinitionMap.put("/logout","logout"); //logut請求采用logout filter
//2.不攔截的請求
filterChainDefinitionMap.put("/css/**","anon");
filterChainDefinitionMap.put("/js/**","anon");
filterChainDefinitionMap.put("/login", "anon");
filterChainDefinitionMap.put("/logout","anon");
filterChainDefinitionMap.put("/error","anon");
filterChainDefinitionMap.put("/restlogin","anon");
//3.攔截的請求(從本地數據庫獲取或者從casserver獲取(webservice,http等遠程方式),看你的角色權限配置在哪裏)
filterChainDefinitionMap.put("/user", "authc"); //需要登錄
filterChainDefinitionMap.put("/user/add/**", "authc,roles[admin]"); //需要登錄,且用戶角色為admin
filterChainDefinitionMap.put("/user/delete/**", "authc,perms[\"user:delete\"]"); //需要登錄,且用戶有權限為user:delete
//4.登錄過的不攔截
filterChainDefinitionMap.put("/**", "user");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
}