spring mvc 使用 pac4j-cas 和 buji-pac4j(pac4j for shiro) 进行登录
ShiroCasProperties
cas.shiro.login-url: http://passport.xxx.com:8088/cas/login
cas.shiro.callback-url: /callback
cas:
shiro:
filter-chain-definition-map:
/page1: securityFilter
/callback: callbackFilter
/logout: logout
config 配置:
@Bean
public Config config() {
final CasConfiguration configuration = new CasConfiguration(shiroCasProperties.getLoginUrl());
final CasClient casClient = new CasClient(configuration);
casClient.setUrlResolver(new RelativeUrlResolver());
final Clients clients = new Clients(shiroCasProperties.getCallbackUrl(), casClient);
final Config config = new Config(clients);
config.setSessionStore(new J2ESessionStore());
return config;
}
shiroFilter 配置:
@Bean
public ShiroFilterFactoryBean shiroFilterFactoryBean() {
final Config config = config();
ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(new Pac4jRealm());
shiroFilter.setSecurityManager(securityManager);
shiroFilter.setFilterChainDefinitionMap(shiroCasProperties.getFilterChainDefinitionMap());
shiroFilter.setFilters(new LinkedHashMap() {{
CallbackFilter callbackFilter = new CallbackFilter();
callbackFilter.setConfig(config);
put("callbackFilter", callbackFilter);
SecurityFilter securityFilter = new SecurityFilter();
securityFilter.setConfig(config);
securityFilter.setClients("CasClient");
put("securityFilter", securityFilter);
LogoutFilter logoutFilter = new LogoutFilter();
logoutFilter.setConfig(config);
logoutFilter.setCentralLogout(true);
put("logout", logoutFilter);
}});
return shiroFilter;
}
完整源码见: TODO