mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 12:07:42 +00:00
(improvement)[build] Use Spotless to customize the code formatting (#1750)
This commit is contained in:
@@ -52,12 +52,10 @@ public class DefaultUserAdaptor implements UserAdaptor {
|
||||
new Organization("1", "0", "SuperSonic", "SuperSonic", Lists.newArrayList(), true);
|
||||
Organization hr =
|
||||
new Organization("2", "1", "Hr", "SuperSonic/Hr", Lists.newArrayList(), false);
|
||||
Organization sales =
|
||||
new Organization(
|
||||
"3", "1", "Sales", "SuperSonic/Sales", Lists.newArrayList(), false);
|
||||
Organization marketing =
|
||||
new Organization(
|
||||
"4", "1", "Marketing", "SuperSonic/Marketing", Lists.newArrayList(), false);
|
||||
Organization sales = new Organization("3", "1", "Sales", "SuperSonic/Sales",
|
||||
Lists.newArrayList(), false);
|
||||
Organization marketing = new Organization("4", "1", "Marketing", "SuperSonic/Marketing",
|
||||
Lists.newArrayList(), false);
|
||||
List<Organization> subOrganization = Lists.newArrayList(hr, sales, marketing);
|
||||
superSonic.setSubOrganizations(subOrganization);
|
||||
return Lists.newArrayList(superSonic);
|
||||
@@ -113,19 +111,12 @@ public class DefaultUserAdaptor implements UserAdaptor {
|
||||
throw new RuntimeException("user not exist,please register");
|
||||
}
|
||||
try {
|
||||
String password =
|
||||
AESEncryptionUtil.encrypt(
|
||||
userReq.getPassword(),
|
||||
AESEncryptionUtil.getBytesFromString(userDO.getSalt()));
|
||||
String password = AESEncryptionUtil.encrypt(userReq.getPassword(),
|
||||
AESEncryptionUtil.getBytesFromString(userDO.getSalt()));
|
||||
if (userDO.getPassword().equals(password)) {
|
||||
UserWithPassword user =
|
||||
UserWithPassword.get(
|
||||
userDO.getId(),
|
||||
userDO.getName(),
|
||||
userDO.getDisplayName(),
|
||||
userDO.getEmail(),
|
||||
userDO.getPassword(),
|
||||
userDO.getIsAdmin());
|
||||
UserWithPassword user = UserWithPassword.get(userDO.getId(), userDO.getName(),
|
||||
userDO.getDisplayName(), userDO.getEmail(), userDO.getPassword(),
|
||||
userDO.getIsAdmin());
|
||||
return user;
|
||||
} else {
|
||||
throw new RuntimeException("password not correct, please try again");
|
||||
|
||||
@@ -68,8 +68,8 @@ public abstract class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
try {
|
||||
if (request instanceof StandardMultipartHttpServletRequest) {
|
||||
RequestFacade servletRequest =
|
||||
(RequestFacade)
|
||||
((StandardMultipartHttpServletRequest) request).getRequest();
|
||||
(RequestFacade) ((StandardMultipartHttpServletRequest) request)
|
||||
.getRequest();
|
||||
Class<? extends HttpServletRequest> servletRequestClazz = servletRequest.getClass();
|
||||
Field request1 = servletRequestClazz.getDeclaredField("request");
|
||||
request1.setAccessible(true);
|
||||
|
||||
@@ -22,9 +22,8 @@ import java.lang.reflect.Method;
|
||||
public class DefaultAuthenticationInterceptor extends AuthenticationInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws AccessException {
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler) throws AccessException {
|
||||
authenticationConfig = ContextUtils.getBean(AuthenticationConfig.class);
|
||||
userServiceImpl = ContextUtils.getBean(UserServiceImpl.class);
|
||||
userTokenUtils = ContextUtils.getBean(UserTokenUtils.class);
|
||||
@@ -74,11 +73,9 @@ public class DefaultAuthenticationInterceptor extends AuthenticationInterceptor
|
||||
}
|
||||
|
||||
private void setContext(String userName, HttpServletRequest request) {
|
||||
ThreadContext threadContext =
|
||||
ThreadContext.builder()
|
||||
.token(request.getHeader(authenticationConfig.getTokenHttpHeaderKey()))
|
||||
.userName(userName)
|
||||
.build();
|
||||
ThreadContext threadContext = ThreadContext.builder()
|
||||
.token(request.getHeader(authenticationConfig.getTokenHttpHeaderKey()))
|
||||
.userName(userName).build();
|
||||
s2ThreadContext.set(threadContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,17 +13,14 @@ public class InterceptorFactory implements WebMvcConfigurer {
|
||||
private List<AuthenticationInterceptor> authenticationInterceptors;
|
||||
|
||||
public InterceptorFactory() {
|
||||
authenticationInterceptors =
|
||||
SpringFactoriesLoader.loadFactories(
|
||||
AuthenticationInterceptor.class,
|
||||
Thread.currentThread().getContextClassLoader());
|
||||
authenticationInterceptors = SpringFactoriesLoader.loadFactories(
|
||||
AuthenticationInterceptor.class, Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
for (AuthenticationInterceptor authenticationInterceptor : authenticationInterceptors) {
|
||||
registry.addInterceptor(authenticationInterceptor)
|
||||
.addPathPatterns("/**")
|
||||
registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**")
|
||||
.excludePathPatterns("/", "/webapp/**", "/error");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,8 +138,8 @@ public class UserDOExample {
|
||||
criteria.add(new Criterion(condition, value));
|
||||
}
|
||||
|
||||
protected void addCriterion(
|
||||
String condition, Object value1, Object value2, String property) {
|
||||
protected void addCriterion(String condition, Object value1, Object value2,
|
||||
String property) {
|
||||
if (value1 == null || value2 == null) {
|
||||
throw new RuntimeException("Between values for " + property + " cannot be null");
|
||||
}
|
||||
@@ -628,8 +628,8 @@ public class UserDOExample {
|
||||
this(condition, value, null);
|
||||
}
|
||||
|
||||
protected Criterion(
|
||||
String condition, Object value, Object secondValue, String typeHandler) {
|
||||
protected Criterion(String condition, Object value, Object secondValue,
|
||||
String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
|
||||
@@ -30,8 +30,8 @@ public class UserController {
|
||||
}
|
||||
|
||||
@GetMapping("/getCurrentUser")
|
||||
public User getCurrentUser(
|
||||
HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
|
||||
public User getCurrentUser(HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse) {
|
||||
return userService.getCurrentUser(httpServletRequest, httpServletResponse);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getCurrentUser(
|
||||
HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
|
||||
public User getCurrentUser(HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse) {
|
||||
User user = UserHolder.findUser(httpServletRequest, httpServletResponse);
|
||||
if (user != null) {
|
||||
SystemConfig systemConfig = sysParameterService.getSystemConfig();
|
||||
|
||||
@@ -18,8 +18,8 @@ public class UserStrategyFactory {
|
||||
|
||||
private AuthenticationConfig authenticationConfig;
|
||||
|
||||
public UserStrategyFactory(
|
||||
AuthenticationConfig authenticationConfig, List<UserStrategy> userStrategyList) {
|
||||
public UserStrategyFactory(AuthenticationConfig authenticationConfig,
|
||||
List<UserStrategy> userStrategyList) {
|
||||
this.authenticationConfig = authenticationConfig;
|
||||
this.userStrategyList = userStrategyList;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ public class ComponentFactory {
|
||||
}
|
||||
|
||||
private static <T> T init(Class<T> factoryType) {
|
||||
return SpringFactoriesLoader.loadFactories(
|
||||
factoryType, Thread.currentThread().getContextClassLoader())
|
||||
.get(0);
|
||||
return SpringFactoriesLoader
|
||||
.loadFactories(factoryType, Thread.currentThread().getContextClassLoader()).get(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,7 @@ public class UserTokenUtils {
|
||||
Map<String, Object> claims = new HashMap<>(5);
|
||||
claims.put(TOKEN_USER_ID, user.getId());
|
||||
claims.put(TOKEN_USER_NAME, StringUtils.isEmpty(user.getName()) ? "" : user.getName());
|
||||
claims.put(
|
||||
TOKEN_USER_PASSWORD,
|
||||
claims.put(TOKEN_USER_PASSWORD,
|
||||
StringUtils.isEmpty(user.getPassword()) ? "" : user.getPassword());
|
||||
claims.put(TOKEN_USER_DISPLAY_NAME, user.getDisplayName());
|
||||
claims.put(TOKEN_CREATE_TIME, System.currentTimeMillis());
|
||||
@@ -83,10 +82,8 @@ public class UserTokenUtils {
|
||||
String userName = String.valueOf(claims.get(TOKEN_USER_NAME));
|
||||
String email = String.valueOf(claims.get(TOKEN_USER_EMAIL));
|
||||
String displayName = String.valueOf(claims.get(TOKEN_USER_DISPLAY_NAME));
|
||||
Integer isAdmin =
|
||||
claims.get(TOKEN_IS_ADMIN) == null
|
||||
? 0
|
||||
: Integer.parseInt(claims.get(TOKEN_IS_ADMIN).toString());
|
||||
Integer isAdmin = claims.get(TOKEN_IS_ADMIN) == null ? 0
|
||||
: Integer.parseInt(claims.get(TOKEN_IS_ADMIN).toString());
|
||||
return User.get(userId, userName, displayName, email, isAdmin);
|
||||
}
|
||||
|
||||
@@ -105,10 +102,8 @@ public class UserTokenUtils {
|
||||
String email = String.valueOf(claims.get(TOKEN_USER_EMAIL));
|
||||
String displayName = String.valueOf(claims.get(TOKEN_USER_DISPLAY_NAME));
|
||||
String password = String.valueOf(claims.get(TOKEN_USER_PASSWORD));
|
||||
Integer isAdmin =
|
||||
claims.get(TOKEN_IS_ADMIN) == null
|
||||
? 0
|
||||
: Integer.parseInt(claims.get(TOKEN_IS_ADMIN).toString());
|
||||
Integer isAdmin = claims.get(TOKEN_IS_ADMIN) == null ? 0
|
||||
: Integer.parseInt(claims.get(TOKEN_IS_ADMIN).toString());
|
||||
return UserWithPassword.get(userId, userName, displayName, email, password, isAdmin);
|
||||
}
|
||||
|
||||
@@ -121,11 +116,8 @@ public class UserTokenUtils {
|
||||
try {
|
||||
String tokenSecret = getTokenSecret(appKey);
|
||||
Claims claims =
|
||||
Jwts.parser()
|
||||
.setSigningKey(tokenSecret.getBytes(StandardCharsets.UTF_8))
|
||||
.build()
|
||||
.parseClaimsJws(getTokenString(token))
|
||||
.getBody();
|
||||
Jwts.parser().setSigningKey(tokenSecret.getBytes(StandardCharsets.UTF_8))
|
||||
.build().parseClaimsJws(getTokenString(token)).getBody();
|
||||
return Optional.of(claims);
|
||||
} catch (Exception e) {
|
||||
log.info("can not getClaims from appKey:{} token:{}, please login", appKey, token);
|
||||
@@ -149,15 +141,10 @@ public class UserTokenUtils {
|
||||
Date expirationDate = new Date(expiration);
|
||||
String tokenSecret = getTokenSecret(appKey);
|
||||
|
||||
return Jwts.builder()
|
||||
.setClaims(claims)
|
||||
.setSubject(claims.get(TOKEN_USER_NAME).toString())
|
||||
return Jwts.builder().setClaims(claims).setSubject(claims.get(TOKEN_USER_NAME).toString())
|
||||
.setExpiration(expirationDate)
|
||||
.signWith(
|
||||
new SecretKeySpec(
|
||||
tokenSecret.getBytes(StandardCharsets.UTF_8),
|
||||
SignatureAlgorithm.HS512.getJcaName()),
|
||||
SignatureAlgorithm.HS512)
|
||||
.signWith(new SecretKeySpec(tokenSecret.getBytes(StandardCharsets.UTF_8),
|
||||
SignatureAlgorithm.HS512.getJcaName()), SignatureAlgorithm.HS512)
|
||||
.compact();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user