本文整理匯總了Java中org.apache.shiro.spring.web.ShiroFilterFactoryBean類的典型用法代碼示例。如果您正苦於以下問題:Java ShiroFilterFactoryBean類的具體用法?Java ShiroFilterFactoryBean怎麽用?Java ShiroFilterFactoryBean使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ShiroFilterFactoryBean類屬於org.apache.shiro.spring.web包,在下文中一共展示了ShiroFilterFactoryBean類的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: getShiroFilterFactoryBean
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入依賴的package包/類
/**
* ShiroFilter<br/>
* 注意這裏參數中的 StudentService 和 IScoreDao 隻是一個例子,因為我們在這裏可以用這樣的方式獲取到相關訪問數據庫的對象,
* 然後讀取數據庫相關配置,配置到 shiroFilterFactoryBean 的訪問規則中。實際項目中,請使用自己的Service來處理業務邏輯。
*
* @param securityManager
* @param casFilter
* @param userDao
* @return
* @author SHANHY
* @create 2016年1月14日
*/
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager securityManager, CasFilter casFilter, UserDao userDao) {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
// 必須設置 SecurityManager
shiroFilterFactoryBean.setSecurityManager(securityManager);
// 如果不設置默認會自動尋找Web工程根目錄下的"/login.jsp"頁麵
shiroFilterFactoryBean.setLoginUrl(loginUrl);
// 登錄成功後要跳轉的連接
shiroFilterFactoryBean.setSuccessUrl(loginSuccessUrl);
shiroFilterFactoryBean.setUnauthorizedUrl(unauthorizedUrl);
// 添加casFilter到shiroFilter中
Map<String, Filter> filters = new HashMap<>();
filters.put("casFilter", casFilter);
// filters.put("logout",logoutFilter());
shiroFilterFactoryBean.setFilters(filters);
loadShiroFilterChain(shiroFilterFactoryBean, userDao);
return shiroFilterFactoryBean;
}
示例3: 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);
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: shiroFilterFactoryBean
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入依賴的package包/類
/**
* 對過濾器進行調整
*
* @param securityManager
* @return
*/
@Bean(name = "shiroFilter")
protected ShiroFilterFactoryBean shiroFilterFactoryBean(DefaultWebSecurityManager securityManager, Config config) {
ShiroFilterFactoryBean filterFactoryBean = super.shiroFilterFactoryBean();
filterFactoryBean.setSecurityManager(securityManager);
//過濾器設置
Map<String, Filter> filters = new HashMap<>();
SecurityFilter securityFilter = new SecurityFilter();
securityFilter.setClients("cas,rest,jwt");
securityFilter.setConfig(config);
filters.put("casSecurityFilter", securityFilter);
CallbackFilter callbackFilter = new CallbackFilter();
callbackFilter.setConfig(config);
filters.put("callbackFilter", callbackFilter);
filterFactoryBean.setFilters(filters);
return filterFactoryBean;
}
示例8: 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);
}
示例9: getObject
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入依賴的package包/類
public Object getObject() throws Exception {
logger.info(">>> create filter bean : {}, singleton : {}", getObjectType(), isSingleton());
ReflectionUtils.setFieldValue(ReflectionUtils.findField(ShiroFilterFactoryBean.class, "instance"), this, null);
Map<String, String> filterChainDefinitionMap = (Map<String, String>) applicationContext.getBean(Ini.Section.class);
setFilterChainDefinitionMap(filterChainDefinitionMap);
return super.getObject();
}
示例10: 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;
}
示例11: getShiroFilterFactoryBean
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; //導入依賴的package包/類
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean getShiroFilterFactoryBean(
DefaultWebSecurityManager securityManager,
FormAuthenticationFilter formAuthenticationFilter) {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
// 必須設置 SecurityManager
shiroFilterFactoryBean.setSecurityManager(securityManager);
// 如果不設置默認會自動尋找Web工程根目錄下的"/login.jsp"頁麵
shiroFilterFactoryBean.setLoginUrl("/oss/login");
// 登錄成功後要跳轉的連接
shiroFilterFactoryBean.setSuccessUrl("/admin/index");
shiroFilterFactoryBean.setUnauthorizedUrl("/403");
Map map=new HashMap<>();
// map.put("authc",formAuthenticationFilter);
shiroFilterFactoryBean.setFilters(map);
loadShiroFilterChain(shiroFilterFactoryBean);
return shiroFilterFactoryBean;
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}