Merge pull request !2 from liuwei/master

This commit is contained in:
liuwei 2017-05-05 10:59:08 +08:00 committed by smallchill
commit 70f36c03e1
2 changed files with 14 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import java.util.Random;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.crypto.hash.Md5Hash; import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.crypto.hash.SimpleHash; import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.mgt.RealmSecurityManager;
import org.apache.shiro.session.Session; import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject; import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.ByteSource; import org.apache.shiro.util.ByteSource;
@ -268,5 +269,16 @@ public class ShiroKit {
} }
return ""; return "";
} }
/**
* 清理AuthenticationInfo缓存
* 参考http://blog.csdn.net/win7system/article/details/51038131
* @param account
*/
public static void clearCachedAuthenticationInfo(String account) {
RealmSecurityManager securityManager =(RealmSecurityManager) SecurityUtils.getSecurityManager();
ShiroDbRealm userRealm = (ShiroDbRealm) securityManager.getRealms().iterator().next();
userRealm.getCacheManager().getCache(userRealm.getAuthenticationCacheName()).remove(account);
}
} }

View File

@ -127,6 +127,7 @@ public class UserController extends BaseController implements ConstShiro{
user.setVersion(user.getVersion() + 1); user.setVersion(user.getVersion() + 1);
boolean temp = blade.update(user); boolean temp = blade.update(user);
if (temp) { if (temp) {
ShiroKit.clearCachedAuthenticationInfo(user.getAccount());
return success(UPDATE_SUCCESS_MSG); return success(UPDATE_SUCCESS_MSG);
} else { } else {
return error(UPDATE_FAIL_MSG); return error(UPDATE_FAIL_MSG);