diff --git a/pom.xml b/pom.xml
index 25988beb9..36ed6ed96 100644
--- a/pom.xml
+++ b/pom.xml
@@ -700,6 +700,11 @@
+
+ org.crazycake
+ shiro-redis
+ 3.2.1
+
org.glassfish.jersey.connectors
jersey-apache-connector
diff --git a/src/main/java/com/nis/util/AsnCacheUtils.java b/src/main/java/com/nis/util/AsnCacheUtils.java
index 6d0a239ce..bb4b8b547 100644
--- a/src/main/java/com/nis/util/AsnCacheUtils.java
+++ b/src/main/java/com/nis/util/AsnCacheUtils.java
@@ -5,6 +5,7 @@ import java.util.Map;
import java.util.Map.Entry;
import org.apache.log4j.Logger;
+import org.apache.shiro.cache.Cache;
import com.beust.jcommander.internal.Lists;
import com.nis.domain.specific.ConfigGroupInfo;
@@ -12,8 +13,6 @@ import com.nis.web.dao.specific.ConfigGroupInfoDao;
import com.nis.web.service.SpringContextHolder;
import jersey.repackaged.com.google.common.collect.Maps;
-import net.sf.ehcache.Cache;
-import net.sf.ehcache.Element;
/**
* asn no缓存工具类
@@ -35,9 +34,12 @@ public class AsnCacheUtils{
* @return
*/
public static ConfigGroupInfo get(Long key) {
- Element element = getCache(ASN_NO_CACHE).get(key/cache_rage);
+ Cache cache = getCache(ASN_NO_CACHE);
+ Object element = cache.get(key/cache_rage);
+
+// Element element = getCache(ASN_NO_CACHE).get(key/cache_rage);
if(element!=null) {
- Map map=(Map)element.getObjectValue();
+ Map map=(Map)element;
if(map.containsKey(key)) {
return map.get(key);
}
@@ -45,20 +47,19 @@ public class AsnCacheUtils{
return null;
}
public static Map getMap(Object key) {
- Element element = getCache(ASN_NO_CACHE).get(key);
- return (Map)element.getObjectValue();
+ Object element = getCache(ASN_NO_CACHE).get(key);
+ return (Map)element;
}
public static void clearCache() {
logger.warn("clear cache!");
- CacheUtils.getCacheManager().removeCache(ASN_NO_CACHE);
+ getCache(ASN_NO_CACHE).clear();
}
public static List getAllAsnGroup(){
List configGroupInfos=Lists.newArrayList();
Cache cache=getCache(ASN_NO_CACHE);
- for(Object key:cache.getKeys()) {
- Element element = getCache(ASN_NO_CACHE).get(key);
- if(element!=null) {
- Map map=(Map)element.getObjectValue();
+ for(Object val : cache.values()) {
+ if(val!=null) {
+ Map map=(Map)val;
configGroupInfos.addAll(map.values());
}
}
@@ -89,19 +90,21 @@ public class AsnCacheUtils{
}
}
for(Entry> e:groupMap.entrySet()) {
- Element element = new Element(e.getKey(), e.getValue());
- cache.put(element);
+ cache.put(e.getKey(),e.getValue());
}
}else {
//查询总量
Long count=configGroupInfoDao.getCountByType(4);
boolean loadDatabase=false;
- if(cache.getKeys().size()==0) {
+ if(cache.keys().size()==0) {
loadDatabase=true;
}else {
long c=0l;
- for(Object key:cache.getKeys()) {
- c+=getMap(key).size();
+ for(Object key:cache.keys()) {
+ Map map = getMap(key);
+ if(map != null) {
+ c+=getMap(key).size();
+ }
}
if(c!=count) {
loadDatabase=true;
@@ -121,8 +124,7 @@ public class AsnCacheUtils{
}
}
for(Entry> e:groupMap.entrySet()) {
- Element element = new Element(e.getKey(), e.getValue());
- cache.put(element);
+ cache.put(e.getKey(), e.getValue());
}
}
}
@@ -137,17 +139,16 @@ public class AsnCacheUtils{
*/
public static void put(Long key, ConfigGroupInfo value) {
Long _key=key/cache_rage;
- Element element = getCache(ASN_NO_CACHE).get(_key);
+ Object element = getCache(ASN_NO_CACHE).get(_key);
if(element==null) {
Map map=Maps.newHashMap();
map.put(key, value);
- element = new Element(_key, map);
+ getCache(ASN_NO_CACHE).put(_key,map);
}else {
- Map map=(Map)element.getObjectValue();
+ Map map=(Map)element;
map.put(key, value);
- element = new Element(_key, map);
+ getCache(ASN_NO_CACHE).put(_key,map);
}
- getCache(ASN_NO_CACHE).put(element);
}
/**
* 从缓存中移除
@@ -159,30 +160,25 @@ public class AsnCacheUtils{
}
public static void remove(Long key) {
Long _key=key/cache_rage;
- Element element = getCache(ASN_NO_CACHE).get(_key);
+ Object element = getCache(ASN_NO_CACHE).get(_key);
if(element!=null) {
- Map map=(Map)element.getObjectValue();
+ Map map=(Map)element;
if(map.containsKey(key)) {
map.remove(key);
}
if(map.isEmpty()) {
getCache(ASN_NO_CACHE).remove(_key);
}else {
- element=new Element(_key,map);
- getCache(ASN_NO_CACHE).put(element);
+ getCache(ASN_NO_CACHE).put(_key, map);
}
}
}
private static Cache getCache(String cacheName){
Cache cache = CacheUtils.getCacheManager().getCache(cacheName);
- if (cache == null){
- CacheUtils.getCacheManager().addCache(cacheName);
- cache = CacheUtils.getCacheManager().getCache(cacheName);
- cache.getCacheConfiguration().setEternal(true);
- }
return cache;
}
+
public static String getCacheName() {
return ASN_NO_CACHE;
}
diff --git a/src/main/java/com/nis/util/CacheUtils.java b/src/main/java/com/nis/util/CacheUtils.java
index ca8642d6f..e6119497d 100644
--- a/src/main/java/com/nis/util/CacheUtils.java
+++ b/src/main/java/com/nis/util/CacheUtils.java
@@ -1,10 +1,11 @@
package com.nis.util;
+
+import org.apache.shiro.cache.Cache;
+import org.crazycake.shiro.RedisCacheManager;
+
import com.nis.web.service.SpringContextHolder;
-import net.sf.ehcache.Cache;
-import net.sf.ehcache.CacheManager;
-import net.sf.ehcache.Element;
/**
* Cache工具类
@@ -13,7 +14,7 @@ import net.sf.ehcache.Element;
*/
public class CacheUtils {
- private static CacheManager cacheManager = ((CacheManager)SpringContextHolder.getBean("cacheManager"));
+ private static RedisCacheManager cacheManager = (RedisCacheManager)SpringContextHolder.getBean("shiroCacheManager");
private static final String SYS_CACHE = "sysCache";
@@ -51,8 +52,7 @@ public class CacheUtils {
* @return
*/
public static Object get(String cacheName, String key) {
- Element element = getCache(cacheName).get(key);
- return element==null?null:element.getObjectValue();
+ return getCache(cacheName).get(key);
}
/**
@@ -62,8 +62,8 @@ public class CacheUtils {
* @param value
*/
public static void put(String cacheName, String key, Object value) {
- Element element = new Element(key, value);
- getCache(cacheName).put(element);
+ Cache cache=cacheManager.getCache(cacheName);
+ cache.put(key, value);
}
/**
@@ -80,7 +80,7 @@ public class CacheUtils {
* @param cacheName
* @return
*/
- private static Cache getCache(String cacheName){
+ /*private static Cache getCache(String cacheName){
Cache cache = cacheManager.getCache(cacheName);
if (cache == null){
cacheManager.addCache(cacheName);
@@ -88,9 +88,13 @@ public class CacheUtils {
cache.getCacheConfiguration().setEternal(true);
}
return cache;
+ }*/
+ private static Cache getCache(String cacheName){
+ Cache cache = cacheManager.getCache(cacheName);
+ return cache;
}
- public static CacheManager getCacheManager() {
+ public static RedisCacheManager getCacheManager() {
return cacheManager;
}
diff --git a/src/main/java/com/nis/web/controller/sys/UserController.java b/src/main/java/com/nis/web/controller/sys/UserController.java
index a00dab025..a478ef14a 100644
--- a/src/main/java/com/nis/web/controller/sys/UserController.java
+++ b/src/main/java/com/nis/web/controller/sys/UserController.java
@@ -1,12 +1,26 @@
package com.nis.web.controller.sys;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.derby.tools.sysinfo;
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.authc.AuthenticationInfo;
+import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.apache.shiro.cache.Cache;
+import org.apache.shiro.mgt.RealmSecurityManager;
+import org.apache.shiro.realm.Realm;
+import org.apache.shiro.session.Session;
+import org.apache.shiro.subject.PrincipalCollection;
+import org.apache.shiro.subject.SimplePrincipalCollection;
+import org.apache.shiro.subject.support.DefaultSubjectContext;
+import org.crazycake.shiro.RedisCache;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
@@ -22,11 +36,15 @@ import com.nis.domain.Page;
import com.nis.domain.SysRole;
import com.nis.domain.SysUser;
import com.nis.util.DateUtils;
+import com.nis.util.IpUtil;
import com.nis.util.StringUtil;
import com.nis.util.StringUtils;
import com.nis.util.excel.ExportExcel;
import com.nis.web.controller.BaseController;
+import com.nis.web.security.SystemAuthorizingRealm;
+import com.nis.web.security.SystemAuthorizingRealm.Principal;
import com.nis.web.security.UserUtils;
+import com.nis.web.security.UsernamePasswordToken;
@Controller
@RequestMapping("${adminPath}/sys/user")
@@ -97,7 +115,7 @@ public class UserController extends BaseController{
return form(user, model);
}*/
if (!"true".equals(checkLoginName(user.getOldLoginId(), user.getLoginId()))){
- addMessage(redirectAttributes,"error", "save_failed");
+ addMessage(model,"error", "save_failed");
return form(user, model);
}
// 角色数据有效性验证,过滤不在授权内的角色
@@ -264,6 +282,7 @@ public class UserController extends BaseController{
/**
* 修改个人用户密码
+ *
* @param oldPassword
* @param newPassword
* @param model
@@ -273,20 +292,44 @@ public class UserController extends BaseController{
@RequestMapping(value = "modifyPwd")
public String modifyPwd(String oldPassword, String newPassword, Model model) {
SysUser user = UserUtils.getUser();
- if (StringUtils.isNotBlank(oldPassword) && StringUtils.isNotBlank(newPassword)){
-
- if (StringUtils.validatePassword(oldPassword, user.getPassword())){
+ if (StringUtils.isNotBlank(oldPassword) && StringUtils.isNotBlank(newPassword)) {
+ if (StringUtils.validatePassword(oldPassword, user.getPassword())) {
userService.updatePasswordById(user.getId(), user.getLoginId(), newPassword);
+ Session curSession = UserUtils.getSession();// 当前登录用户的session
+ Principal principal = UserUtils.getPrincipal();// 当前登录用户的鉴权信息
+ // 过滤 当前用户的 非此客户的其它登录信息
+ Collection allOtherSession = systemService.getActiveSessions(true, principal, curSession);
+ if (allOtherSession.size() > 0) {
+ // 如果是登录进来的,则踢出已在线用户
+ if (UserUtils.getSubject().isAuthenticated()) {
+ for (Session session : allOtherSession) {
+ systemService.deleteSession(session);
+ }
+ }
+ }
+
+ RealmSecurityManager securityManager = (RealmSecurityManager) SecurityUtils.getSecurityManager();
+ Collection realm = securityManager.getRealms();
+ for (Realm realm2 : realm) {
+ SystemAuthorizingRealm userRealm = (SystemAuthorizingRealm) realm2;
+ RedisCache