package com.culturalCenter.AuthorizationServer.Utils;
//import org.springframework.data.redis.connection.RedisServerCommands;
//import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
//import org.springframework.data.redis.core.HashOperations;
//import org.springframework.data.redis.core.ListOperations;
//import org.springframework.data.redis.core.RedisCallback;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.serializer.RedisSerializer;
//import org.springframework.data.redis.support.atomic.RedisAtomicLong;
import org.springframework.stereotype.Component;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
*
* @Description
*Redis工具类
*/
@Component
public class RedisUtil {
//
// /**
// * 默认编码
// */
// private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
//
// /**
// * Spring Redis Template
// */
// private RedisTemplate<String, String> redisTemplate;
//
// private JedisConnectionFactory jedisConnectionFactory;
//
// public RedisUtil(RedisTemplate<String, String> redisTemplate) {
// this.redisTemplate = redisTemplate;
// }
//
// /**
// * 添加到带有 过期时间的 缓存
// *
// * @param key redis主键
// * @param value 值
// * @param time 过期时间
// */
// public void setExpire(final byte[] key, final byte[] value, final long time) {
// redisTemplate.execute((RedisCallback<Long>) connection -> {
// connection.set(key, value);
// connection.expire(key, time);
// log.info("[redisTemplate redis]放入 缓存 url:{} ========缓存时间为{}秒", key, time);
// return 1L;
// });
// }
//
// /**
// * 添加到带有 过期时间的 缓存
// *
// * @param key redis主键
// * @param value 值
// * @param time 过期时间
// */
// public void setExpire(final String key, final String value, final long time) {
// redisTemplate.execute((RedisCallback<Long>) connection -> {
// RedisSerializer<String> serializer = getRedisSerializer();
// byte[] keys = serializer.serialize(key);
// byte[] values = serializer.serialize(value);
// connection.set(keys, values);
// connection.expire(keys, time);
// log.info("[redisTemplate redis]放入 缓存 url:{} ========缓存时间为{}秒", key, time);
// return 1L;
// });
// }
//
// /**
// * 一次性添加数组到 过期时间的 缓存,不用多次连接,节省开销
// *
// * @param keys redis主键数组
// * @param values 值数组
// * @param time 过期时间
// */
// public void setExpire(final String[] keys, final String[] values, final long time) {
// redisTemplate.execute((RedisCallback<Long>) connection -> {
// RedisSerializer<String> serializer = getRedisSerializer();
// for (int i = 0; i < keys.length; i++) {
// byte[] bKeys = serializer.serialize(keys[i]);
// byte[] bValues = serializer.serialize(values[i]);
// connection.set(bKeys, bValues);
// connection.expire(bKeys, time);
// log.info("[redisTemplate redis]放入 缓存 url:{} ========缓存时间为:{}秒", keys[i], time);
// }
// return 1L;
// });
// }
//
//
// /**
// * 一次性添加数组到 过期时间的 缓存,不用多次连接,节省开销
// *
// * @param keys the keys
// * @param values the values
// */
// public void set(final String[] keys, final String[] values) {
// redisTemplate.execute((RedisCallback<Long>) connection -> {
// RedisSerializer<String> serializer = getRedisSerializer();
// for (int i = 0; i < keys.length; i++) {
// byte[] bKeys = serializer.serialize(keys[i]);
// byte[] bValues = serializer.serialize(values[i]);
// connection.set(bKeys, bValues);
// log.info("[redisTemplate redis]放入 缓存 url:{}", keys[i]);
// }
// return 1L;
// });
// }
//
//
// /**
// * 添加到缓存
// *
// * @param key the key
// * @param value the value
// */
// public void set(final String key, final String value) {
// redisTemplate.execute((RedisCallback<Long>) connection -> {
// RedisSerializer<String> serializer = getRedisSerializer();
// byte[] keys = serializer.serialize(key);
// byte[] values = serializer.serialize(value);
// connection.set(keys, values);
// log.info("[redisTemplate redis]放入 缓存 url:{}", key);
// return 1L;
// });
// }
//
// /**
// * 查询在这个时间段内即将过期的key
// *
// * @param key the key
// * @param time the time
// * @return the list
// */
// public List<String> willExpire(final String key, final long time) {
// final List<String> keysList = new ArrayList<>();
// redisTemplate.execute((RedisCallback<List<String>>) connection -> {
// Set<String> keys = redisTemplate.keys(key + "*");
// for (String key1 : keys) {
// Long ttl = connection.ttl(key1.getBytes(DEFAULT_CHARSET));
// if (0 <= ttl && ttl <= 2 * time) {
// keysList.add(key1);
// }
// }
// return keysList;
// });
// return keysList;
// }
//
//
// /**
// * 查询在以keyPatten的所有 key
// *
// * @param keyPatten the key patten
// * @return the set
// */
// public Set<String> keys(final String keyPatten) {
// return redisTemplate.execute((RedisCallback<Set<String>>) connection -> redisTemplate.keys(keyPatten + "*"));
// }
//
// /**
// * 根据key获取对象
// *
// * @param key the key
// * @return the byte [ ]
// */
// public byte[] get(final byte[] key) {
// byte[] result = redisTemplate.execute((RedisCallback<byte[]>) connection -> connection.get(key));
// log.info("[redisTemplate redis]取出 缓存 url:{} ", key);
// return result;
// }
//
// /**
// * 根据key获取对象
// *
// * @param key the key
// * @return the string
// */
// public String get(final String key) {
// String resultStr = redisTemplate.execute((RedisCallback<String>) connection -> {
// RedisSerializer<String> serializer = getRedisSerializer();
// byte[] keys = serializer.serialize(key);
// byte[] values = connection.get(keys);
// return serializer.deserialize(values);
// });
// log.info("[redisTemplate redis]取出 缓存 url:{} ", key);
// return resultStr;
// }
//
//
// /**
// * 根据key获取对象
// *
// * @param keyPatten the key patten
// * @return the keys values
// */
// public Map<String, String> getKeysValues(final String keyPatten) {
// log.info("[redisTemplate redis] getValues() patten={} ", keyPatten);
// return redisTemplate.execute((RedisCallback<Map<String, String>>) connection -> {
// RedisSerializer<String> serializer = getRedisSerializer();
// Map<String, String> maps = new HashMap<>();
// Set<String> keys = redisTemplate.keys(keyPatten + "*");
// for (String key : keys) {
// byte[] bKeys = serializer.serialize(key)
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
spring boot +spring Security+ jwt+oauth2.rar (350个子文件)
OAuth2Config$OAuth2AuthorizationServerConfig.class 7KB
ResourceServerConfiguration.class 7KB
SecurityConfiguration.class 7KB
JwtTokenUtils.class 4KB
LoginAuthenticationFilter.class 4KB
LoginAuthenticationFilter.class 4KB
JwtTokenUtils.class 3KB
CustomAuthExceptionHandler.class 3KB
JwtUser.class 3KB
JwtUser.class 3KB
CustomerAccessTokenConverter$CustomerUserAuthenticationConverter.class 3KB
AuthErrorEnum.class 3KB
AuthErrorEnum.class 3KB
OAuth2Config$CustomerAccessTokenConverter$CustomerUserAuthenticationConverter.class 2KB
UserDetailsServiceImpl.class 2KB
UserDetailsServiceImpl.class 2KB
OAuth2Config$CustomTokenEnhancer.class 2KB
UsersServiceImpl.class 2KB
UsersServiceImpl.class 2KB
Users.class 2KB
Users.class 2KB
UsersController.class 2KB
UsersController.class 1KB
UsersMapper.class 1KB
UsersMapper.class 1KB
Role.class 1KB
Role.class 1KB
PathUtil.class 1KB
PathUtil.class 1KB
OAuth2Config$CustomerAccessTokenConverter.class 1KB
CustomerAccessTokenConverter.class 1KB
RoleMapper.class 986B
RoleMapper.class 986B
OAuth2Config.class 931B
AuthorServerApplication.class 914B
AuthorServerApplication.class 914B
UsersService.class 695B
UsersService.class 695B
AuthorizationServerApplicationTests.class 620B
AuthorizationServerApplicationTests.class 620B
RedisUtil.class 427B
RedisUtil.class 427B
CustomerAccessTokenConverter$1.class 324B
OAuth2Config$1.class 276B
mvnw.cmd 6KB
mvnw.cmd 6KB
问题记录及使用.docx 66KB
问题记录.docx 65KB
.gitignore 333B
.gitignore 333B
.gitignore 184B
.gitignore 184B
ResourcesServer.iml 11KB
AuthorizationServer.iml 11KB
maven-wrapper.jar 50KB
maven-wrapper.jar 50KB
RedisUtil.java 17KB
RedisUtil.java 17KB
OAuth2Config.java 9KB
SecurityConfiguration.java 8KB
ResourceServerConfiguration.java 6KB
MavenWrapperDownloader.java 5KB
MavenWrapperDownloader.java 5KB
SecurityConfiguration.java 5KB
LoginAuthenticationFilter.java 3KB
LoginAuthenticationFilter.java 3KB
CustomAuthExceptionHandler.java 3KB
JwtTokenUtils.java 3KB
JwtTokenUtils.java 3KB
CustomerAccessTokenConverter.java 2KB
JwtUser.java 2KB
JwtUser.java 2KB
UserDetailsServiceImpl.java 2KB
UsersServiceImpl.java 2KB
UsersServiceImpl.java 2KB
Users.java 2KB
Users.java 2KB
UserDetailsServiceImpl.java 2KB
PathUtil.java 2KB
PathUtil.java 2KB
UsersMapper.java 2KB
UsersMapper.java 2KB
RoleMapper.java 1KB
RoleMapper.java 1KB
UsersController.java 1KB
AuthErrorEnum.java 1KB
AuthErrorEnum.java 1KB
UsersController.java 1KB
UsersService.java 1KB
UsersService.java 1KB
Role.java 796B
Role.java 796B
AuthorServerApplication.java 745B
AuthorServerApplication.java 745B
AuthorizationServerApplicationTests.java 243B
AuthorizationServerApplicationTests.java 243B
mytest.jks 2KB
mytest.jks 2KB
oauthdb-credentials.json 1001B
oauthdb-credentials.json 1001B
共 350 条
- 1
- 2
- 3
- 4
资源评论
- 番皂泡2023-07-28这个文件的作者对于Spring Boot和Spring Security的特性和用法都有很好的把握,写的示例代码非常实用。
- 两斤香菜2023-07-28通过学习这个文件,我对Spring安全性机制有了更深入的了解,并成功使用JWT OAuth2保护我的应用程序。
- 易烫YCC2023-07-28这个文件的结构清晰,代码逻辑简洁明了,对于初学者来说非常友好。
- 八位数花园2023-07-28值得一提的是,该文件还提供了一些最佳实践和安全建议,帮助我在实际项目中更好地应用Spring Security和JWT OAuth2。
- 巧笑倩兮Evelina2023-07-28这个文件提供了丰富的示例代码,让我可以更轻松地理解和使用Spring Boot、Spring Security和JWT OAuth2。
qq_29793333
- 粉丝: 0
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功