update config

This commit is contained in:
东皇 2018-06-27 17:20:07 +08:00
parent 32c9a1c7ee
commit 6722607bf9
4 changed files with 93 additions and 69 deletions

View File

@ -19,13 +19,13 @@
<bean class="org.pac4j.cas.client.CasClient"> <bean class="org.pac4j.cas.client.CasClient">
<constructor-arg> <constructor-arg>
<bean class="org.pac4j.cas.config.CasConfiguration"> <bean class="org.pac4j.cas.config.CasConfiguration">
<constructor-arg value="${cas.server.login-url:${cas.server.addr}/login}" /> <constructor-arg value="${tigon.shiro.cas.login-url:${tigon.shiro.cas.server.addr}/login}" />
<property name="protocol" value="${cas.protocol:CAS20}" /> <property name="protocol" value="${tigon.shiro.cas.protocol:CAS20}" />
<property name="acceptAnyProxy" value="true" /> <property name="acceptAnyProxy" value="true" />
</bean> </bean>
</constructor-arg> </constructor-arg>
<property name="name" value="${spring.application.name}" /> <property name="name" value="${spring.application.name}" />
<property name="callbackUrl" value="${cas.client.login.url:${cas.client.addr}${cas.client.login.path:/cas/login}?client_name=${spring.application.name}}" /> <property name="callbackUrl" value="${tigon.shiro.cas.login-callback-url:${tigon.shiro.cas.client.addr}${tigon.shiro.cas.login-callback-path:/cas/login}?client_name=${spring.application.name}}" />
<property name="profileCreator"> <property name="profileCreator">
<bean class="me.chyxion.tigon.shiro.cas.DefaultProfileCreator" /> <bean class="me.chyxion.tigon.shiro.cas.DefaultProfileCreator" />
</property> </property>
@ -35,34 +35,45 @@
<bean id="shiroFilter" parent="shiroFilterParent"> <bean id="shiroFilter" parent="shiroFilterParent">
<property name="securityManager" ref="securityManager" /> <property name="securityManager" ref="securityManager" />
<property name="loginUrl" value="${shiro.login-url:${cas.server.login-url:${cas.server.addr}/login}}?service=${cas.client.addr}${cas.client.login.path:/cas/login}?client_name=${spring.application.name}}" /> <property name="loginUrl" value="${tigon.shiro.login-url:${tigon.shiro.cas.server.login-url:${tigon.shiro.cas.server.addr}/login}}?service=${tigon.shiro.cas.client.addr}${tigon.shiro.cas.client.login.path:/cas/login}?client_name=${spring.application.name}}" />
<property name="successUrl" value="${cas.client.login.success-url:/login-success}" /> <property name="successUrl" value="${tigon.shiro.login-success-url:/login-success}" />
<property name="unauthorizedUrl" value="${cas.client.unauthorized-url:/403}" />
<property name="filters"> <property name="filters">
<map> <map>
<entry key="cas"> <entry key="${tigon.shiro.cas.login-callback-filter-name:cas}">
<bean class="io.buji.pac4j.filter.CallbackFilter"> <bean class="io.buji.pac4j.filter.CallbackFilter">
<property name="config" ref="casConfig" /> <property name="config" ref="casConfig" />
<property name="defaultUrl" value="${cas.client.login.success-url:/login-success}" />
</bean> </bean>
</entry> </entry>
<entry key="user"> <entry key="${tigon.shiro.cas.security-filter-name:user}">
<bean class="io.buji.pac4j.filter.SecurityFilter"> <bean class="io.buji.pac4j.filter.SecurityFilter">
<property name="config" ref="casConfig" /> <property name="config" ref="casConfig" />
<property name="clients" value="${spring.application.name}" /> <property name="clients" value="${spring.application.name}" />
</bean> </bean>
</entry> </entry>
<entry key="logout"> <entry key="${tigon.shiro.cas.logout-filter-name:logout}">
<bean class="io.buji.pac4j.filter.LogoutFilter"> <bean class="io.buji.pac4j.filter.LogoutFilter">
<property name="config" ref="casConfig" /> <property name="config" ref="casConfig" />
<property name="localLogout" value="${cas.client.logout.local:true}" /> <property name="localLogout" value="${tigon.shiro.cas.local-logout:true}" />
<property name="centralLogout" value="${cas.client.logout.central:true}" /> <property name="centralLogout" value="${tigon.shiro.cas.central-logout:true}" />
<property name="logoutUrlPattern" value="${cas.client.logout.path:/logout}" /> <property name="logoutUrlPattern" value="${tigon.shiro.logout-path:/logout}" />
<property name="defaultUrl" value="${cas.client.logout.success-url:/logout-success}" /> <property name="defaultUrl" value="${tigon.shiro.logout-success-url:/logout-success}" />
</bean> </bean>
</entry> </entry>
</map> </map>
</property> </property>
<property name="filterChainDefinitionMap">
<bean class="me.chyxion.tigon.shiro.FilterChainDefinitionMap">
<constructor-arg value="${tigon.shiro.filter-chain-definition.config-location:classpath:shiro/auth.properties}" />
<constructor-arg>
<map>
<entry key="${tigon.shiro.cas.login-callback-path:/cas/login}" value="${tigon.shiro.cas.login-callback-filter-name:cas}" />
<entry key="${tigon.shiro.cas.logout-path:/logout}" value="${tigon.shiro.cas.logout-filter-name:logout}" />
<entry key="${tigon.shiro.cas.logout-success-url:/logout-success}" value="anon" />
</map>
</constructor-arg>
</bean>
</property>
</bean> </bean>
</beans> </beans>

View File

@ -21,6 +21,10 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId> <artifactId>spring-boot</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency> <dependency>
<groupId>me.chyxion.tigon</groupId> <groupId>me.chyxion.tigon</groupId>
<artifactId>tigon-sequence</artifactId> <artifactId>tigon-sequence</artifactId>

View File

@ -1,13 +1,9 @@
package me.chyxion.tigon.shiro; package me.chyxion.tigon.shiro;
import java.util.*;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
import java.util.Set;
import java.util.Properties;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
@ -19,43 +15,57 @@ import org.springframework.core.io.Resource;
*/ */
@Slf4j @Slf4j
@Getter @Getter
@Setter public class FilterChainDefinitionMap extends LinkedHashMap<String, String> {
public class FilterChainDefinitionMap extends LinkedHashMap { private final Resource configLocation;
private Resource configLocation;
@PostConstruct public FilterChainDefinitionMap(final Resource configLocation) {
void init() throws IOException { this.configLocation = configLocation;
}
public FilterChainDefinitionMap(final Resource configLocation, final Map<String, String> map) {
super(map);
this.configLocation = configLocation;
}
@PostConstruct
void init() throws IOException {
log.info("Load shiro filter chain definition from config location [{}].", configLocation); log.info("Load shiro filter chain definition from config location [{}].", configLocation);
final InputStream authIn = configLocation != null && configLocation.exists() ? if (configLocation != null && configLocation.exists()) {
configLocation.getInputStream() : final InputStream authIn = configLocation.getInputStream();
FilterChainDefinitionMap.class if (authIn != null) {
.getResourceAsStream("/shiro/auth.properties"); final Properties props = new OrderedProperties();
try {
if (authIn != null) { props.load(authIn);
final Properties props = new OrderedProperties(); }
try { catch (final IOException e) {
props.load(authIn); throw new IllegalStateException(
} "Load shiro filter chain definition config error caused", e);
catch (IOException e) { }
throw new IllegalStateException( finally {
"Load shiro filter chain definition config error caused", e); if (authIn != null) {
} try {
finally { authIn.close();
if (authIn != null) { }
try { catch (IOException e) {
authIn.close(); // ignore
} }
catch (IOException e) {
// ignore
} }
} }
}
for (String name : props.stringPropertyNames()) { for (final String path : props.stringPropertyNames()) {
put(name, props.getProperty(name)); final String auth = props.getProperty(path);
log.info("Shiro filter chain definition [{}] -> [{}] added.", path, auth);
put(path, auth);
}
} }
} else {
log.info("No input stream load from shiro filter chain definition config location [{}], ignore.", configLocation);
}
}
else {
log.info("Shiro filter chain definition config location [{}] does not exist, ignore.", configLocation);
}
} }
@Slf4j @Slf4j

View File

@ -17,26 +17,26 @@
<property name="sessionManager"> <property name="sessionManager">
<bean class="me.chyxion.tigon.shiro.TigonWebSessionManager"> <bean class="me.chyxion.tigon.shiro.TigonWebSessionManager">
<property name="globalSessionTimeout" <property name="globalSessionTimeout"
value="${shiro.session.timeout:1800000}"/> value="${tigon.shiro.session.timeout:1800000}"/>
<property name="sessionValidationSchedulerEnabled" <property name="sessionValidationSchedulerEnabled"
value="${shiro.session.validation.scheduler.enabled:false}" /> value="${tigon.shiro.session.validation.scheduler.enabled:false}" />
<property name="sessionValidationInterval" <property name="sessionValidationInterval"
value="${shiro.session.validation.interval:3600000}" /> value="${tigon.shiro.session.validation.interval:3600000}" />
<property name="sessionDAO"> <property name="sessionDAO">
<bean class="me.chyxion.tigon.shiro.TigonSessionDAO" /> <bean class="me.chyxion.tigon.shiro.TigonSessionDAO" />
</property> </property>
<property name="sessionIdCookieEnabled" value="${shiro.session.id.cookie.enabled:true}" /> <property name="sessionIdCookieEnabled" value="${tigon.shiro.session.id.cookie.enabled:true}" />
<property name="sessionIdUrlRewritingEnabled" value="${shiro.session.id.url.rewriting.enabled:true}" /> <property name="sessionIdUrlRewritingEnabled" value="${tigon.shiro.session.id.url.rewriting.enabled:true}" />
<property name="sessionIdCookie"> <property name="sessionIdCookie">
<bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie"> <bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
<constructor-arg value="${shiro.session.id.cookie.name:SID}" /> <constructor-arg value="${tigon.shiro.session.id.cookie.name:SID}" />
<property name="domain" value="${shiro.cookie.domain:}" /> <property name="domain" value="${tigon.shiro.cookie.domain:}" />
<property name="path" value="${shiro.cookie.path:/}" /> <property name="path" value="${tigon.shiro.cookie.path:/}" />
<property name="maxAge" value="${shiro.cookie.max.age:-1}" /> <property name="maxAge" value="${tigon.shiro.cookie.max.age:-1}" />
<property name="version" value="${shiro.cookie.version:-1}" /> <property name="version" value="${tigon.shiro.cookie.version:-1}" />
<property name="secure" value="${shiro.cookie.secure:false}" /> <property name="secure" value="${tigon.shiro.cookie.secure:false}" />
<property name="httpOnly" value="${shiro.cookie.http.only:true}" /> <property name="httpOnly" value="${tigon.shiro.cookie.http.only:true}" />
<property name="comment" value="${shiro.cookie.comment:}" /> <property name="comment" value="${tigon.shiro.cookie.comment:}" />
</bean> </bean>
</property> </property>
</bean> </bean>
@ -45,14 +45,13 @@
<bean id="shiroFilterParent" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean" abstract="true"> <bean id="shiroFilterParent" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean" abstract="true">
<property name="securityManager" ref="securityManager" /> <property name="securityManager" ref="securityManager" />
<property name="loginUrl" value="${cas.login-url:${cas.server.login-url:${cas.server.addr}/login}}?service=${cas.client.addr}${cas.client.login.path:/cas/login}?client_name=${spring.application.name}}" /> <property name="loginUrl" value="${tigon.shiro.login-url:/login}" />
<property name="successUrl" value="${cas.client.login.success-url:/login-success}" /> <property name="successUrl" value="${tigon.shiro.login-success-url:/}" />
<property name="unauthorizedUrl" value="${cas.client.unauthorized-url:/403}" /> <property name="unauthorizedUrl" value="${tigon.shiro.unauthorized-url:/403}" />
<property name="filterChainDefinitionMap"> <property name="filterChainDefinitionMap">
<bean class="me.chyxion.tigon.shiro.FilterChainDefinitionMap"> <bean class="me.chyxion.tigon.shiro.FilterChainDefinitionMap">
<property name="configLocation" <constructor-arg value="${tigon.shiro.filter-chain-definition.config-location:classpath:shiro/auth.properties}" />
value="${shiro.filter-chain-definition.config-location:classpath*:shiro/auth.properties}" />
</bean> </bean>
</property> </property>
</bean> </bean>
@ -63,13 +62,13 @@
<constructor-arg value="shiroFilter" /> <constructor-arg value="shiroFilter" />
</bean> </bean>
</property> </property>
<property name="enabled" value="${shiro.fitler.enabled:true}" /> <property name="enabled" value="${tigon.shiro.fitler.enabled:true}" />
<property name="initParameters"> <property name="initParameters">
<map> <map>
<entry key="targetFilterLifecycle" value="true" /> <entry key="targetFilterLifecycle" value="true" />
</map> </map>
</property> </property>
<property name="urlPatterns" value="${shiro.fitler.url-patterns:/*}" /> <property name="urlPatterns" value="${tigon.shiro.fitler.url-patterns:/*}" />
</bean> </bean>
</beans> </beans>