Shiro配置踩坑(序列化)

问题一:

1、在securitymanager配置 缓存管理类 cacheManager,这个cacheManager必须要在前面执行,因为setRealm 和 setSessionManage

2、源于:

将对象存入缓存中,

皆要将对象序列化

问题二:

     序列化问题:

    1、盐序列化:

我们在实现的realm类中,重写dogetAutenticationinfo:

需要将盐转换为ByteSource字节码对象:

但是该对象即实现类SimpleByteSource,没有实现serializable,导致不能序列化。

解决方法:

步骤1、继承SimpleByteSource类,实现serializable

步骤2、自定义ByteSourceUtils,加入生成SimpleByteSource静态方法

public class SimpleByteSource extends org.apache.shiro.util.SimpleByteSource

implements Serializable {

private static final long serialVersionUID = 5528101080905698238L;

public SimpleByteSource(byte[] bytes) {

super(bytes);

}

}

public class ByteSourceUtils {

public static ByteSource bytes(byte[] bytes) {

return new SimpleByteSource(bytes);

}

public static ByteSource bytes(String arg0) {

return new SimpleByteSource(arg0.getBytes());

}

}

 

 

 

你可能感兴趣的:(#,Shiro踩坑,shiro学习)