package com.fable.shiro.shiro;
import com.fable.shiro.domain.CasConfig;
import org.apache.shiro.cache.ehcache.EhCacheManager;
import org.apache.shiro.cas.CasFilter;
import org.apache.shiro.cas.CasSubjectFactory;
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.DelegatingFilterProxy;
import javax.servlet.Filter;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Shiro集成CAS配置
*/
@Configuration
@EnableConfigurationProperties(CasConfig.class)
public class ShiroCasConfiguration {
private static final String CAS_FILTER = "casFilter";
@Bean
public EhCacheManager ehcacheManager(){
EhCacheManager ehcacheManager = new EhCacheManager();
ehcacheManager.setCacheManagerConfigFile("classpath:ehcache-shiro.xml");
return ehcacheManager;
}
@Bean(name = "myShiroCasRealm")
public MyShiroCasRealm myShiroRealm(EhCacheManager ehCacheManager, CasConfig casConfig){
MyShiroCasRealm realm = new MyShiroCasRealm();
realm.setCacheManager(ehCacheManager);
realm.setCasServerUrlPrefix(casConfig.getCasServerUrlPrefix());
realm.setCasService(casConfig.getCasService());
return realm;
}
/**
* 注册shiroFilter
*/
@Bean
public FilterRegistrationBean filterRegistrationBean(){
FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
filterRegistration.setFilter(new DelegatingFilterProxy("shiroFilter"));
// 该值缺省为false,表示生命周期有SpringApplicationContext管理,设置为true则表示由ServletContainer管理
filterRegistration.addInitParameter("targetFilterLifecycle", "true");
filterRegistration.setEnabled(true);
filterRegistration.addUrlPatterns("/*");
return filterRegistration;
}
@Bean(name = "lifecycleBeanPostProcessor")
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor(){
return new LifecycleBeanPostProcessor();
}
@Bean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator(){
DefaultAdvisorAutoProxyCreator creator = new DefaultAdvisorAutoProxyCreator();
creator.setProxyTargetClass(true);
return creator;
}
@Bean(name = "securityManager")
public DefaultWebSecurityManager defaultWebSecurityManager(MyShiroCasRealm realm){
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(realm);
securityManager.setCacheManager(ehcacheManager());
// 指定SubjectFactory
securityManager.setSubjectFactory(new CasSubjectFactory());
return securityManager;
}
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(DefaultWebSecurityManager securityManager){
AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
advisor.setSecurityManager(securityManager);
return advisor;
}
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean shiroFilterFactoryBean(DefaultWebSecurityManager securityManager, CasConfig casConfig, CasFilter casFilter){
ShiroFilterFactoryBean factoryBean = new MyShiroFilterFactoryBean();
factoryBean.setSecurityManager(securityManager);
factoryBean.setLoginUrl(casConfig.getLocalServerLoginUrl());
factoryBean.setSuccessUrl("/user");
factoryBean.setUnauthorizedUrl("/403");
// 添加casFilter到shiroFilter中
Map<String, Filter> filterMap = new HashMap<String, Filter>(1);
filterMap.put(CAS_FILTER, casFilter);
factoryBean.setFilters(filterMap);
loadShiroFilterChain(factoryBean, casConfig);
return factoryBean;
}
/**
* 加载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("/user/edit/**", "authc,perms[user:edit]");
filterChainMap.put("/**", "anon");
factoryBean.setFilterChainDefinitionMap(filterChainMap);
}
/**
* CAS过滤器
*/
@Bean
public CasFilter casFilter(CasConfig casConfig){
CasFilter casFilter = new CasFilter();
casFilter.setName(CAS_FILTER);
casFilter.setEnabled(true);
casFilter.setFailureUrl(casConfig.getLocalServerLoginUrl());
return casFilter;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
spring boot+jpa+cas+shiro
共169个文件
xml:120个
class:14个
java:13个
5星 · 超过95%的资源 需积分: 9 594 下载量 155 浏览量
2016-12-08
12:33:14
上传
评论 7
收藏 36.04MB ZIP 举报
温馨提示
一个用spring boot+jpa+cas+shiro+freemarker做的完整demo。
资源推荐
资源详情
资源评论
收起资源包目录
spring boot+jpa+cas+shiro (169个子文件)
ShiroCasConfiguration.class 6KB
UserController.class 5KB
User.class 3KB
Role.class 3KB
MyShiroFilterFactoryBean$MySpringShiroFilter.class 3KB
MyShiroFilterFactoryBean.class 2KB
CasConfig.class 2KB
MyShiroCasRealm.class 2KB
Application.class 2KB
Permission.class 1KB
ShiroTagFreeMarkerConfigurer.class 1KB
UserServiceImpl.class 985B
UserDao.class 670B
UserService.class 315B
user.ftl 1KB
user.ftl 1KB
login.ftl 525B
login.ftl 525B
user_edit.ftl 229B
user_edit.ftl 229B
403.ftl 168B
403.ftl 168B
shiroCAS.iml 12KB
shiro-1.0-SNAPSHOT.jar 39.89MB
ShiroCasConfiguration.java 5KB
UserController.java 3KB
MyShiroFilterFactoryBean.java 3KB
MyShiroCasRealm.java 2KB
CasConfig.java 2KB
User.java 2KB
Role.java 2KB
Application.java 950B
ShiroTagFreeMarkerConfigurer.java 946B
Permission.java 767B
UserServiceImpl.java 655B
UserDao.java 493B
UserService.java 358B
spring-configuration-metadata.json 1KB
inputFiles.lst 1KB
inputFiles.lst 1KB
createdFiles.lst 678B
createdFiles.lst 0B
inputFiles.lst 0B
shiro-1.0-SNAPSHOT.jar.original 24KB
application.properties 1KB
application.properties 1KB
pom.properties 118B
shiroCAS.sql 2KB
shiroCAS.sql 2KB
d23b7691-3642-4a1c-9d61-df1ccb96544c.xml 1.36MB
workspace.xml 112KB
shiroCAS_war_exploded.xml 10KB
shiro_war_exploded.xml 7KB
59dc7501-e7fa-4ce9-8f58-15b18276a197.xml 4KB
pom.xml 4KB
dataSources.xml 2KB
dataSources.local.xml 2KB
logback.xml 1KB
logback.xml 1KB
compiler.xml 1KB
misc.xml 1KB
Maven__org_springframework_boot_spring_boot_configuration_processor_1_4_1_RELEASE.xml 804B
Maven__org_springframework_boot_spring_boot_starter_freemarker_1_4_1_RELEASE.xml 769B
Maven__org_springframework_boot_spring_boot_starter_data_jpa_1_4_1_RELEASE.xml 755B
Maven__org_springframework_boot_spring_boot_starter_logging_1_4_1_RELEASE.xml 748B
Maven__org_springframework_integration_spring_integration_core_4_3_2_RELEASE.xml 748B
Maven__org_springframework_integration_spring_integration_mail_4_3_2_RELEASE.xml 748B
Maven__org_springframework_boot_spring_boot_starter_tomcat_1_4_1_RELEASE.xml 741B
Maven__org_springframework_boot_spring_boot_autoconfigure_1_4_1_RELEASE.xml 734B
Maven__org_hibernate_common_hibernate_commons_annotations_5_0_1_Final.xml 732B
Maven__org_springframework_boot_spring_boot_starter_jdbc_1_4_1_RELEASE.xml 727B
Maven__org_hibernate_javax_persistence_hibernate_jpa_2_1_api_1_0_0_Final.xml 720B
Maven__org_springframework_boot_spring_boot_starter_aop_1_4_1_RELEASE.xml 720B
Maven__org_springframework_boot_spring_boot_starter_web_1_4_1_RELEASE.xml 720B
Maven__org_springframework_data_spring_data_commons_1_12_3_RELEASE.xml 699B
Maven__org_springframework_spring_context_support_4_3_3_RELEASE.xml 693B
Maven__org_springframework_boot_spring_boot_starter_1_4_1_RELEASE.xml 692B
Maven__org_springframework_data_spring_data_jpa_1_10_3_RELEASE.xml 671B
Maven__org_hibernate_hibernate_entitymanager_5_0_11_Final.xml 669B
Maven__org_springframework_spring_expression_4_3_3_RELEASE.xml 658B
Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_5_5.xml 653B
Maven__org_springframework_spring_messaging_4_3_3_RELEASE.xml 651B
Maven__org_springframework_retry_spring_retry_1_1_4_RELEASE.xml 647B
Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_3.xml 644B
Maven__com_google_inject_extensions_guice_multibindings_3_0.xml 638B
Maven__org_springframework_spring_context_4_3_3_RELEASE.xml 637B
Maven__org_springframework_spring_aspects_4_3_3_RELEASE.xml 637B
Maven__org_springframework_boot_spring_boot_1_4_1_RELEASE.xml 636B
Maven__org_hibernate_hibernate_validator_5_2_4_Final.xml 634B
Maven__org_springframework_spring_webmvc_4_3_3_RELEASE.xml 630B
Maven__com_fasterxml_jackson_core_jackson_databind_2_8_3.xml 623B
Maven__org_springframework_spring_beans_4_3_3_RELEASE.xml 623B
Maven__org_apache_tomcat_embed_tomcat_embed_core_8_5_5.xml 618B
Maven__org_freemarker_freemarker_2_3_25_incubating.xml 617B
Maven__org_springframework_spring_core_4_3_3_RELEASE.xml 616B
Maven__org_springframework_spring_jdbc_4_3_3_RELEASE.xml 616B
Maven__commons_collections_commons_collections_3_2_2.xml 616B
Maven__javax_validation_validation_api_1_1_0_Final.xml 611B
Maven__org_springframework_spring_web_4_3_3_RELEASE.xml 609B
Maven__org_springframework_spring_orm_4_3_3_RELEASE.xml 609B
共 169 条
- 1
- 2
nimeijian
- 粉丝: 31
- 资源: 43
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页