格式修改
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.baiyue.auth.client;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
import com.baiyue.auth.entity.AuthAccount;
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
@@ -12,16 +15,16 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
public class AuthorizationLoader {
|
||||
private final IamAuthorizationClient client;
|
||||
private final String internalToken;
|
||||
@Resource
|
||||
private IamAuthorizationClient client;
|
||||
@Value("${baiyue.security.internal-service-token}")
|
||||
private String internalToken;
|
||||
|
||||
public AuthorizationLoader(IamAuthorizationClient client,
|
||||
@Value("${baiyue.security.internal-service-token}") String internalToken) {
|
||||
@PostConstruct
|
||||
void validateConfiguration() {
|
||||
if (internalToken == null || internalToken.getBytes(java.nio.charset.StandardCharsets.UTF_8).length < 32) {
|
||||
throw new IllegalStateException("INTERNAL_SERVICE_TOKEN 至少需要 32 字节");
|
||||
}
|
||||
this.client = client;
|
||||
this.internalToken = internalToken;
|
||||
}
|
||||
|
||||
public AuthorizationSnapshot load(AuthAccount account) {
|
||||
|
||||
@@ -21,14 +21,10 @@ public class InternalAccountController {
|
||||
@Resource
|
||||
private AccountManagementService service;
|
||||
|
||||
private final String configuredToken;
|
||||
@Value("${baiyue.security.internal-service-token}")
|
||||
private String configuredToken;
|
||||
private byte[] tokenBytes;
|
||||
|
||||
public InternalAccountController(
|
||||
@Value("${baiyue.security.internal-service-token}") String configuredToken) {
|
||||
this.configuredToken = configuredToken;
|
||||
}
|
||||
|
||||
@PostConstruct void init() { tokenBytes = configuredToken.getBytes(StandardCharsets.UTF_8); }
|
||||
|
||||
@PostMapping
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.baiyue.auth.repository;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import com.baiyue.auth.entity.AuthAccount;
|
||||
import com.baiyue.auth.mapper.AuthAccountMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -10,11 +12,8 @@ import org.springframework.stereotype.Repository;
|
||||
*/
|
||||
@Repository
|
||||
public class AuthAccountRepository {
|
||||
private final AuthAccountMapper mapper;
|
||||
|
||||
public AuthAccountRepository(AuthAccountMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
@Resource
|
||||
private AuthAccountMapper mapper;
|
||||
|
||||
public AuthAccount findByUsername(String username) {
|
||||
return mapper.selectOne(new LambdaQueryWrapper<AuthAccount>()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.baiyue.auth.repository;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import com.baiyue.auth.entity.AuthRefreshToken;
|
||||
import com.baiyue.auth.mapper.AuthRefreshTokenMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -10,11 +12,8 @@ import org.springframework.stereotype.Repository;
|
||||
*/
|
||||
@Repository
|
||||
public class AuthRefreshTokenRepository {
|
||||
private final AuthRefreshTokenMapper mapper;
|
||||
|
||||
public AuthRefreshTokenRepository(AuthRefreshTokenMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
@Resource
|
||||
private AuthRefreshTokenMapper mapper;
|
||||
|
||||
public AuthRefreshToken findByHash(String tokenHash, boolean forUpdate) {
|
||||
String limit = forUpdate ? "LIMIT 1 FOR UPDATE" : "LIMIT 1";
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.baiyue.auth.service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.common.security.RedisTokenKeys;
|
||||
@@ -25,15 +28,16 @@ import java.util.List;
|
||||
*/
|
||||
@Component
|
||||
public class TokenSessionStore {
|
||||
private final StringRedisTemplate redisTemplate;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final String keyPrefix;
|
||||
@Resource
|
||||
private StringRedisTemplate redisTemplate;
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
@Value("${baiyue.security.token-key-prefix:baiyue:auth}")
|
||||
private String keyPrefix;
|
||||
|
||||
public TokenSessionStore(StringRedisTemplate redisTemplate, ObjectMapper objectMapper,
|
||||
@Value("${baiyue.security.token-key-prefix:baiyue:auth}") String keyPrefix) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.objectMapper = objectMapper;
|
||||
this.keyPrefix = RedisTokenKeys.normalize(keyPrefix);
|
||||
@PostConstruct
|
||||
void normalizeKeyPrefix() {
|
||||
keyPrefix = RedisTokenKeys.normalize(keyPrefix);
|
||||
}
|
||||
|
||||
public void store(String jwtId, Long userId, String rawRefreshToken,
|
||||
|
||||
Reference in New Issue
Block a user