|
@@ -1,10 +1,16 @@
|
|
package com.ruoyi.framework.config;
|
|
package com.ruoyi.framework.config;
|
|
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import javax.servlet.Filter;
|
|
import javax.servlet.Filter;
|
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
import org.apache.shiro.cache.ehcache.EhCacheManager;
|
|
import org.apache.shiro.cache.ehcache.EhCacheManager;
|
|
import org.apache.shiro.codec.Base64;
|
|
import org.apache.shiro.codec.Base64;
|
|
|
|
+import org.apache.shiro.config.ConfigurationException;
|
|
|
|
+import org.apache.shiro.io.ResourceUtils;
|
|
import org.apache.shiro.mgt.SecurityManager;
|
|
import org.apache.shiro.mgt.SecurityManager;
|
|
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
|
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
|
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
|
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
|
@@ -87,7 +93,7 @@ public class ShiroConfig
|
|
EhCacheManager em = new EhCacheManager();
|
|
EhCacheManager em = new EhCacheManager();
|
|
if (StringUtils.isNull(cacheManager))
|
|
if (StringUtils.isNull(cacheManager))
|
|
{
|
|
{
|
|
- em.setCacheManagerConfigFile("classpath:ehcache/ehcache-shiro.xml");
|
|
|
|
|
|
+ em.setCacheManager(new net.sf.ehcache.CacheManager(getCacheManagerConfigFileInputStream()));
|
|
return em;
|
|
return em;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -97,6 +103,31 @@ public class ShiroConfig
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 返回配置文件流 避免ehcache配置文件一直被占用,无法完全销毁项目重新部署
|
|
|
|
+ */
|
|
|
|
+ protected InputStream getCacheManagerConfigFileInputStream()
|
|
|
|
+ {
|
|
|
|
+ String configFile = "classpath:ehcache/ehcache-shiro.xml";
|
|
|
|
+ InputStream inputStream = null;
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ inputStream = ResourceUtils.getInputStreamForPath(configFile);
|
|
|
|
+ byte[] b = IOUtils.toByteArray(inputStream);
|
|
|
|
+ InputStream in = new ByteArrayInputStream(b);
|
|
|
|
+ return in;
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e)
|
|
|
|
+ {
|
|
|
|
+ throw new ConfigurationException(
|
|
|
|
+ "Unable to obtain input stream for cacheManagerConfigFile [" + configFile + "]", e);
|
|
|
|
+ }
|
|
|
|
+ finally
|
|
|
|
+ {
|
|
|
|
+ IOUtils.closeQuietly(inputStream);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 自定义Realm
|
|
* 自定义Realm
|
|
*/
|
|
*/
|