栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

带有错误Active Directory Ldap凭证的带有会话/ Redis序列化错误的Spring Boot

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

带有错误Active Directory Ldap凭证的带有会话/ Redis序列化错误的Spring Boot

我想出了解决这个问题的方法。我愿意提出任何改善答案的建议。

解决方案并不完整,因为

com.sun.jndi.ldap.LdapCtx
当序列化失败时,我需要专门寻找
类型,因此我可以处理该特定情况,并将
SerializationException
所有其他情况都扔掉。但是我认为总体思路可能对任何对此有所阻碍的人有用。

现在,当使用无效的凭据(例如,错误的用户名或错误的密码)时,应用程序将返回登录页面,而不是爆炸:)

我添加了一些

RedisConfiguration
替换
RedisTemplate
Spring Session正在使用的方法。

import com.gateway.utils.LdapFailAwareRedisObjectSerializer;@Configurationpublic class RedisConfiguration {  @Primary  @Bean  public RedisTemplate<String,ExpiringSession> redisTemplate(RedisConnectionFactory connectionFactory) {    RedisTemplate<String, ExpiringSession> template = new RedisTemplate<String, ExpiringSession>();    template.setKeySerializer(new StringRedisSerializer());    template.setHashKeySerializer(new StringRedisSerializer());    template.setHashValueSerializer(new LdapFailAwareRedisObjectSerializer());    template.setConnectionFactory(connectionFactory);    return template;  }}

这是我的实现

RedisSerializer<Object>
LdapFailAwareRedisObjectSerializer
从此处获得)

public class LdapFailAwareRedisObjectSerializer implements RedisSerializer<Object> {  private Converter<Object, byte[]> serializer = new SerializingConverter();  private Converter<byte[], Object> deserializer = new DeserializingConverter();  static final byte[] EMPTY_ARRAY = new byte[0];  public Object deserialize(byte[] bytes) {    if (isEmpty(bytes)) {      return null;    }    try {      return deserializer.convert(bytes);    } catch (Exception ex) {      throw new SerializationException("Cannot deserialize", ex);    }  }  public byte[] serialize(Object object) {    if (object == null) {      return EMPTY_ARRAY;    }    try {      return serializer.convert(object);    } catch (Exception ex) {      return EMPTY_ARRAY;      //TODO add logic here to only return EMPTY_ARRAY for known conditions      // else throw the SerializationException      // throw new SerializationException("Cannot serialize", ex);    }  }  private boolean isEmpty(byte[] data) {    return (data == null || data.length == 0);  }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/391924.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号