add shiro cas
This commit is contained in:
parent
c45293cb20
commit
32c9a1c7ee
24
pom.xml
24
pom.xml
@ -42,8 +42,10 @@
|
||||
<module>tigon-mybatis-cache-redis</module>
|
||||
<module>tigon-shiro-cache</module>
|
||||
<module>tigon-shiro-cache-redis</module>
|
||||
<module>tigon-web</module>
|
||||
<module>tigon-shiro-core</module>
|
||||
<module>tigon-shiro-cas</module>
|
||||
<module>tigon-shiro</module>
|
||||
<module>tigon-web</module>
|
||||
<module>tigon-service-api</module>
|
||||
<module>tigon-service-support</module>
|
||||
<module>tigon-extjs</module>
|
||||
@ -82,21 +84,31 @@
|
||||
<artifactId>tigon-mybatis-cache-redis</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-cache-redis</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-cache</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-cache-redis</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-cas</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-service-api</artifactId>
|
||||
|
@ -35,10 +35,10 @@
|
||||
<artifactId>shiro-core</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.springframework.data</groupId>-->
|
||||
<!--<artifactId>spring-data-redis</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
@ -4,7 +4,7 @@ import java.io.Serializable;
|
||||
import org.apache.shiro.cache.Cache;
|
||||
import org.apache.shiro.session.Session;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
|
9
tigon-shiro-cas/.gitignore
vendored
Normal file
9
tigon-shiro-cas/.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
.*
|
||||
!.gitignore
|
||||
!.gitkeep
|
||||
*.iml
|
||||
**/src/main/resources/application.properties
|
||||
**/src/main/resources/log4j2.xml
|
||||
**/src/main/resources/logback.xml
|
||||
target/
|
||||
bin/
|
1
tigon-shiro-cas/README.md
Normal file
1
tigon-shiro-cas/README.md
Normal file
@ -0,0 +1 @@
|
||||
# CAS Client Shiro
|
50
tigon-shiro-cas/pom.xml
Normal file
50
tigon-shiro-cas/pom.xml
Normal file
@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>tigon-shiro-cas</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>CAS Client Shiro</name>
|
||||
<description>CAS Client Shiro</description>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.pac4j</groupId>
|
||||
<artifactId>pac4j-cas</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.buji</groupId>
|
||||
<artifactId>buji-pac4j</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,57 @@
|
||||
package me.chyxion.tigon.shiro.cas;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import java.util.function.Consumer;
|
||||
import org.pac4j.core.context.WebContext;
|
||||
import org.pac4j.core.profile.CommonProfile;
|
||||
import org.pac4j.core.credentials.TokenCredentials;
|
||||
import org.pac4j.core.profile.creator.ProfileCreator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Jun 23, 2018 16:17:53
|
||||
*/
|
||||
@Slf4j
|
||||
public class DefaultProfileCreator implements ProfileCreator<TokenCredentials, CommonProfile> {
|
||||
|
||||
@Autowired(required = false)
|
||||
private UserProfileProvider userProfileProvider;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CommonProfile create(final TokenCredentials credentials, final WebContext context) {
|
||||
log.debug("Create user profile from credentials [{}].", credentials);
|
||||
|
||||
final CommonProfile userProfile = credentials.getUserProfile();
|
||||
if (userProfileProvider != null) {
|
||||
log.debug("User profile provider [{}] found.", userProfileProvider);
|
||||
final UserProfileProvider.UserProfile userProfileResult =
|
||||
userProfileProvider.getUserProfile(userProfile.getId());
|
||||
if (userProfileResult != null) {
|
||||
applyIfNotEmpty(userProfileResult.getRoles(), userProfile::addRoles);
|
||||
applyIfNotEmpty(userProfileResult.getPermissions(), userProfile::addPermissions);
|
||||
applyIfNotEmpty(userProfileResult.getAttrs(), userProfile::addAttributes);
|
||||
applyIfNotEmpty(userProfileResult.getAuthAttrs(), userProfile::addAuthenticationAttributes);
|
||||
}
|
||||
}
|
||||
return userProfile;
|
||||
}
|
||||
|
||||
private <T> void applyIfNotEmpty(final Collection<T> data, final Consumer<Collection<T>> consumer) {
|
||||
if (data != null && !data.isEmpty()) {
|
||||
consumer.accept(data);
|
||||
}
|
||||
}
|
||||
|
||||
private <K, V> void applyIfNotEmpty(final Map<K, V> data, final Consumer<Map<K, V>> consumer) {
|
||||
if (data != null && !data.isEmpty()) {
|
||||
consumer.accept(data);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package me.chyxion.tigon.shiro.cas;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Jun 26, 2018 21:57:43
|
||||
*/
|
||||
@Validated
|
||||
public interface UserProfileProvider {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
class UserProfile {
|
||||
private Set<String> roles;
|
||||
private Set<String> permissions;
|
||||
private Map<String, Object> attrs;
|
||||
private Map<String, Object> authAttrs;
|
||||
}
|
||||
|
||||
UserProfile getUserProfile(@NotBlank String account);
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<description>Shiro CAS Configuration</description>
|
||||
|
||||
<bean id="securityManager" parent="securityManagerParent">
|
||||
<property name="subjectFactory">
|
||||
<bean class="io.buji.pac4j.subject.Pac4jSubjectFactory" />
|
||||
</property>
|
||||
<property name="realm">
|
||||
<bean class="io.buji.pac4j.realm.Pac4jRealm" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="casConfig" class="org.pac4j.core.config.Config">
|
||||
<constructor-arg>
|
||||
<bean class="org.pac4j.cas.client.CasClient">
|
||||
<constructor-arg>
|
||||
<bean class="org.pac4j.cas.config.CasConfiguration">
|
||||
<constructor-arg value="${cas.server.login-url:${cas.server.addr}/login}" />
|
||||
<property name="protocol" value="${cas.protocol:CAS20}" />
|
||||
<property name="acceptAnyProxy" value="true" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
<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="profileCreator">
|
||||
<bean class="me.chyxion.tigon.shiro.cas.DefaultProfileCreator" />
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="shiroFilter" parent="shiroFilterParent">
|
||||
<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="successUrl" value="${cas.client.login.success-url:/login-success}" />
|
||||
<property name="unauthorizedUrl" value="${cas.client.unauthorized-url:/403}" />
|
||||
|
||||
<property name="filters">
|
||||
<map>
|
||||
<entry key="cas">
|
||||
<bean class="io.buji.pac4j.filter.CallbackFilter">
|
||||
<property name="config" ref="casConfig" />
|
||||
<property name="defaultUrl" value="${cas.client.login.success-url:/login-success}" />
|
||||
</bean>
|
||||
</entry>
|
||||
<entry key="user">
|
||||
<bean class="io.buji.pac4j.filter.SecurityFilter">
|
||||
<property name="config" ref="casConfig" />
|
||||
<property name="clients" value="${spring.application.name}" />
|
||||
</bean>
|
||||
</entry>
|
||||
<entry key="logout">
|
||||
<bean class="io.buji.pac4j.filter.LogoutFilter">
|
||||
<property name="config" ref="casConfig" />
|
||||
<property name="localLogout" value="${cas.client.logout.local:true}" />
|
||||
<property name="centralLogout" value="${cas.client.logout.central:true}" />
|
||||
<property name="logoutUrlPattern" value="${cas.client.logout.path:/logout}" />
|
||||
<property name="defaultUrl" value="${cas.client.logout.success-url:/logout-success}" />
|
||||
</bean>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
@ -0,0 +1,20 @@
|
||||
package me.chyxion.tigon.shiro.cas;
|
||||
|
||||
import org.junit.Test;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Donghuang <br />
|
||||
* donghuang@wacai.com <br />
|
||||
* Sep 1, 2015 2:34:08 PM
|
||||
*/
|
||||
@Slf4j
|
||||
public class TestDriver {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<!-- Scan Controllers -->
|
||||
</beans>
|
@ -17,6 +17,10 @@
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-sequence</artifactId>
|
||||
@ -24,20 +28,12 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-cache</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
@ -1,115 +0,0 @@
|
||||
package me.chyxion.tigon.shiro;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.slf4j.Logger;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import javax.servlet.Filter;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import javax.annotation.PostConstruct;
|
||||
import me.chyxion.tigon.webmvc.JSONViewConfig;
|
||||
import me.chyxion.tigon.webmvc.util.ResponseTool;
|
||||
import me.chyxion.tigon.webmvc.exception.ExceptionMessage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Apr 7, 2015 4:44:04 PM
|
||||
*/
|
||||
public class AuthConfigFactory {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(AuthConfigFactory.class);
|
||||
@Autowired(required = false)
|
||||
private AuthConfig authConfig;
|
||||
@Autowired
|
||||
private ResponseTool responseTool;
|
||||
@Autowired
|
||||
private JSONViewConfig viewConfig;
|
||||
@Autowired(required = false)
|
||||
private ExceptionMessage exceptionMessage;
|
||||
|
||||
private UserFilterExt userFilter;
|
||||
|
||||
/**
|
||||
* @return filters
|
||||
*/
|
||||
public Map<String, Filter> filters() {
|
||||
Map<String, Filter> filters = new LinkedHashMap<String, Filter>();
|
||||
filters.put(AuthConfig.FILTER_USER, userFilter);
|
||||
if (authConfig != null) {
|
||||
authConfig.customizeFilters(filters);
|
||||
}
|
||||
log.info("Auth Filters [{}].", filters);
|
||||
return filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return filter routings
|
||||
*/
|
||||
public Map<String, String> filterRoutings() {
|
||||
Map<String, String> routings = new LinkedHashMap<String, String>();
|
||||
routings.put("/assets/**", AuthConfig.FILTER_ANON);
|
||||
InputStream authIn = AuthConfigFactory.class
|
||||
.getResourceAsStream("/shiro/auth.properties");
|
||||
if (authIn != null) {
|
||||
Properties props = new OrderedProperties();
|
||||
try {
|
||||
props.load(authIn);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException(
|
||||
"Load Auth Config Error Caused", e);
|
||||
}
|
||||
finally {
|
||||
if (authIn != null) {
|
||||
try {
|
||||
authIn.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String name : props.stringPropertyNames()) {
|
||||
routings.put(name, props.getProperty(name));
|
||||
}
|
||||
}
|
||||
log.info("Auth Filter Routings [{}].", routings);
|
||||
return routings;
|
||||
}
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
@PostConstruct
|
||||
void init() {
|
||||
userFilter = new UserFilterExt(
|
||||
responseTool, viewConfig, exceptionMessage);
|
||||
}
|
||||
|
||||
static class OrderedProperties extends Properties {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final Set<String> keys = new LinkedHashSet<String>();
|
||||
|
||||
public Object put(Object key, Object value) {
|
||||
keys.add((String) key);
|
||||
return super.put(key, value);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public Set keySet() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
public Set<String> stringPropertyNames() {
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package me.chyxion.tigon.shiro;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.util.Set;
|
||||
import java.util.Properties;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* @author Donghuang <br>
|
||||
* donghuang@wacai.com <br>
|
||||
* Jun 27, 2018 10:42
|
||||
*/
|
||||
@Slf4j
|
||||
@Getter
|
||||
@Setter
|
||||
public class FilterChainDefinitionMap extends LinkedHashMap {
|
||||
private Resource configLocation;
|
||||
|
||||
@PostConstruct
|
||||
void init() throws IOException {
|
||||
log.info("Load shiro filter chain definition from config location [{}].", configLocation);
|
||||
|
||||
final InputStream authIn = configLocation != null && configLocation.exists() ?
|
||||
configLocation.getInputStream() :
|
||||
FilterChainDefinitionMap.class
|
||||
.getResourceAsStream("/shiro/auth.properties");
|
||||
|
||||
if (authIn != null) {
|
||||
final Properties props = new OrderedProperties();
|
||||
try {
|
||||
props.load(authIn);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException(
|
||||
"Load shiro filter chain definition config error caused", e);
|
||||
}
|
||||
finally {
|
||||
if (authIn != null) {
|
||||
try {
|
||||
authIn.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String name : props.stringPropertyNames()) {
|
||||
put(name, props.getProperty(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Slf4j
|
||||
static class OrderedProperties extends Properties {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final Set<String> keys = new LinkedHashSet<>();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object put(Object key, Object value) {
|
||||
log.debug("Load shiro filter chain [{}] -> [{}].", key, value);
|
||||
keys.add((String) key);
|
||||
return super.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public Set keySet() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Set<String> stringPropertyNames() {
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package me.chyxion.tigon.shiro;
|
||||
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.session.SessionListener;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* May 14, 2016 2:09:26 PM
|
||||
*/
|
||||
public interface SessionListenerExt extends SessionListener {
|
||||
|
||||
/**
|
||||
* on session validation
|
||||
* @param session session
|
||||
* @return returns true if session has been changed
|
||||
*/
|
||||
boolean onValidation(Session session);
|
||||
}
|
@ -23,7 +23,7 @@ import org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO;
|
||||
* Sep 8, 2014 7:43:05 PM
|
||||
*/
|
||||
@Slf4j
|
||||
public class SessionDAOSupport extends EnterpriseCacheSessionDAO {
|
||||
public class TigonSessionDAO extends EnterpriseCacheSessionDAO {
|
||||
@Autowired(required = false)
|
||||
private Cache<Serializable, Session> sessionCache;
|
||||
@Autowired
|
||||
@ -36,9 +36,9 @@ public class SessionDAOSupport extends EnterpriseCacheSessionDAO {
|
||||
void init() {
|
||||
if (sessionCache == null) {
|
||||
log.info("No Custom Session Store Found, Use Map Cache.");
|
||||
sessionCache = new MapCache<Serializable, Session>(
|
||||
sessionCache = new MapCache<>(
|
||||
CachingSessionDAO.ACTIVE_SESSION_CACHE_NAME,
|
||||
new ConcurrentHashMap<Serializable, Session>());
|
||||
new ConcurrentHashMap<>(512));
|
||||
}
|
||||
else {
|
||||
log.info("Use Custom Session Cache [{}].", sessionCache);
|
@ -14,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* chyxion@163.com <br>
|
||||
* Mar 12, 2015 1:18:00 PM
|
||||
*/
|
||||
public class DefaultWebSecurityManagerExt extends DefaultWebSecurityManager {
|
||||
public class TigonWebSecurityManager extends DefaultWebSecurityManager {
|
||||
@Autowired(required = false)
|
||||
private AuthCallback authCallback;
|
||||
|
@ -1,6 +1,8 @@
|
||||
package me.chyxion.tigon.shiro;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedList;
|
||||
@ -28,8 +30,8 @@ import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
|
||||
* chyxion@163.com <br>
|
||||
* Apr 7, 2015 2:54:25 PM
|
||||
*/
|
||||
public class DefaultWebSessionManagerExt extends DefaultWebSessionManager {
|
||||
private static final Logger log = LoggerFactory.getLogger(DefaultWebSessionManagerExt.class);
|
||||
@Slf4j
|
||||
public class TigonWebSessionManager extends DefaultWebSessionManager {
|
||||
@Autowired(required = false)
|
||||
private SessionIdManager sessionIdManager;
|
||||
@Autowired(required = false)
|
||||
@ -41,7 +43,7 @@ public class DefaultWebSessionManagerExt extends DefaultWebSessionManager {
|
||||
@PostConstruct
|
||||
void init() {
|
||||
if (sessionListeners == null) {
|
||||
sessionListeners = new LinkedList<SessionListener>();
|
||||
sessionListeners = new LinkedList<>();
|
||||
}
|
||||
else {
|
||||
log.info("Session listeners [{}] found.", sessionListeners);
|
@ -4,20 +4,18 @@
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<description>Tigon Shiro Configuration</description>
|
||||
<description>Tigon Shiro Core Configuration</description>
|
||||
|
||||
<!-- shiro -->
|
||||
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
|
||||
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
|
||||
depends-on="lifecycleBeanPostProcessor"
|
||||
p:proxyTargetClass="true" />
|
||||
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"
|
||||
p:securityManager-ref="securityManager" />
|
||||
<!-- /shiro -->
|
||||
|
||||
<bean id="securityManager" class="me.chyxion.tigon.shiro.DefaultWebSecurityManagerExt">
|
||||
<bean id="securityManagerParent" class="me.chyxion.tigon.shiro.TigonWebSecurityManager" abstract="true">
|
||||
<property name="sessionManager">
|
||||
<bean class="me.chyxion.tigon.shiro.DefaultWebSessionManagerExt">
|
||||
<bean class="me.chyxion.tigon.shiro.TigonWebSessionManager">
|
||||
<property name="globalSessionTimeout"
|
||||
value="${shiro.session.timeout:1800000}"/>
|
||||
<property name="sessionValidationSchedulerEnabled"
|
||||
@ -25,7 +23,7 @@
|
||||
<property name="sessionValidationInterval"
|
||||
value="${shiro.session.validation.interval:3600000}" />
|
||||
<property name="sessionDAO">
|
||||
<bean class="me.chyxion.tigon.shiro.SessionDAOSupport" />
|
||||
<bean class="me.chyxion.tigon.shiro.TigonSessionDAO" />
|
||||
</property>
|
||||
<property name="sessionIdCookieEnabled" value="${shiro.session.id.cookie.enabled:true}" />
|
||||
<property name="sessionIdUrlRewritingEnabled" value="${shiro.session.id.url.rewriting.enabled:true}" />
|
||||
@ -43,19 +41,19 @@
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="realm">
|
||||
<bean class="me.chyxion.tigon.shiro.AuthorizingRealmSupport" />
|
||||
</property>
|
||||
</bean>
|
||||
<!-- Shiro Filter -->
|
||||
<bean id="authConfigFactory" class="me.chyxion.tigon.shiro.AuthConfigFactory" />
|
||||
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
|
||||
|
||||
<bean id="shiroFilterParent" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean" abstract="true">
|
||||
<property name="securityManager" ref="securityManager" />
|
||||
<property name="filters">
|
||||
<bean factory-bean="authConfigFactory" factory-method="filters" />
|
||||
</property>
|
||||
<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="successUrl" value="${cas.client.login.success-url:/login-success}" />
|
||||
<property name="unauthorizedUrl" value="${cas.client.unauthorized-url:/403}" />
|
||||
|
||||
<property name="filterChainDefinitionMap">
|
||||
<bean factory-bean="authConfigFactory" factory-method="filterRoutings" />
|
||||
<bean class="me.chyxion.tigon.shiro.FilterChainDefinitionMap">
|
||||
<property name="configLocation"
|
||||
value="${shiro.filter-chain-definition.config-location:classpath*:shiro/auth.properties}" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@ -74,6 +72,4 @@
|
||||
<property name="urlPatterns" value="${shiro.fitler.url-patterns:/*}" />
|
||||
</bean>
|
||||
|
||||
<bean class="me.chyxion.tigon.shiro.AuthExceptionResolver" />
|
||||
<bean class="me.chyxion.tigon.shiro.service.support.AuthServiceSupport" />
|
||||
</beans>
|
1
tigon-shiro/README.md
Normal file
1
tigon-shiro/README.md
Normal file
@ -0,0 +1 @@
|
||||
# tigon-shiro
|
54
tigon-shiro/pom.xml
Normal file
54
tigon-shiro/pom.xml
Normal file
@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>tigon-shiro</artifactId>
|
||||
<name>Tigon Shiro</name>
|
||||
<description>Tigon Shiro</description>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-shiro-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chyxion.tigon</groupId>
|
||||
<artifactId>tigon-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,56 @@
|
||||
package me.chyxion.tigon.shiro;
|
||||
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import javax.servlet.Filter;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.util.LinkedHashMap;
|
||||
import javax.annotation.PostConstruct;
|
||||
import me.chyxion.tigon.webmvc.JSONViewConfig;
|
||||
import me.chyxion.tigon.webmvc.util.ResponseTool;
|
||||
import me.chyxion.tigon.webmvc.exception.ExceptionMessage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Apr 7, 2015 4:44:04 PM
|
||||
*/
|
||||
public class AuthConfigFactory {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(AuthConfigFactory.class);
|
||||
@Autowired(required = false)
|
||||
private AuthConfig authConfig;
|
||||
@Autowired
|
||||
private ResponseTool responseTool;
|
||||
@Autowired
|
||||
private JSONViewConfig viewConfig;
|
||||
@Autowired(required = false)
|
||||
private ExceptionMessage exceptionMessage;
|
||||
|
||||
private UserFilterExt userFilter;
|
||||
|
||||
/**
|
||||
* @return filters
|
||||
*/
|
||||
public Map<String, Filter> filters() {
|
||||
Map<String, Filter> filters = new LinkedHashMap<String, Filter>();
|
||||
filters.put(AuthConfig.FILTER_USER, userFilter);
|
||||
if (authConfig != null) {
|
||||
authConfig.customizeFilters(filters);
|
||||
}
|
||||
log.info("Auth Filters [{}].", filters);
|
||||
return filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
@PostConstruct
|
||||
void init() {
|
||||
userFilter = new UserFilterExt(
|
||||
responseTool, viewConfig, exceptionMessage);
|
||||
}
|
||||
}
|
24
tigon-shiro/src/main/resources/spring/spring-tigon-shiro.xml
Normal file
24
tigon-shiro/src/main/resources/spring/spring-tigon-shiro.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<description>Tigon Shiro Configuration</description>
|
||||
|
||||
<bean id="securityManager" parent="securityManagerParent">
|
||||
<property name="realm">
|
||||
<bean class="me.chyxion.tigon.shiro.AuthorizingRealmSupport" />
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="authConfigFactory" class="me.chyxion.tigon.shiro.AuthConfigFactory" />
|
||||
|
||||
<!-- Shiro Filter -->
|
||||
<bean id="shiroFilter" parent="shiroFilterParent">
|
||||
<property name="filters">
|
||||
<bean factory-bean="authConfigFactory" factory-method="filters" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="me.chyxion.tigon.shiro.AuthExceptionResolver" />
|
||||
<bean class="me.chyxion.tigon.shiro.service.support.AuthServiceSupport" />
|
||||
</beans>
|
@ -0,0 +1,17 @@
|
||||
package me.chyxion.tigon.shiro;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Mar 14, 2015 3:03:57 PM
|
||||
*/
|
||||
public class TestDriver {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
}
|
||||
}
|
13
tigon-shiro/src/test/resources/log4j.properties
Normal file
13
tigon-shiro/src/test/resources/log4j.properties
Normal file
@ -0,0 +1,13 @@
|
||||
log4j.rootLogger=${log.root}
|
||||
|
||||
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.console.Encoding=utf-8
|
||||
log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n
|
||||
|
||||
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n
|
||||
log4j.appender.file.File=${log.dir}/${project.artifactId}-test.log
|
||||
log4j.appender.file.Encoding=utf-8
|
||||
|
Loading…
x
Reference in New Issue
Block a user