This commit is contained in:
冷冷 committed 2018-12-15 21:55:17 +08:00
commit 5f2e9bf5cd
31 files changed
+79 -81

No files matched your search

@@ -23,7 +23,7 @@ package com.pig4cloud.pigx.common.core.constant;
* @author lengleng
* @date 2017/10/29
*/
public interface CommonConstant {
public interface CommonConstants {
/**
* header 中租户ID
*/
@@ -52,11 +52,6 @@ public interface CommonConstant {
*/
String UTF8 = "UTF-8";
/**
* JSON 资源
*/
String CONTENT_TYPE = "application/json; charset=utf-8";
/**
* 前端工程名
*/
@@ -5,7 +5,7 @@ package com.pig4cloud.pigx.common.core.constant;
* @author lishangbu
* @date 2018/11/22
*/
public interface PaginationConstant {
public interface PaginationConstants {
/**
* 当前页
*/
@@ -24,7 +24,7 @@ package com.pig4cloud.pigx.common.core.constant;
* @date 2018年06月22日16:41:01
* 服务名称
*/
public interface ServiceNameConstant {
public interface ServiceNameConstants {
/**
* 认证中心
*/
@@ -19,7 +19,7 @@
package com.pig4cloud.pigx.common.core.util;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import lombok.*;
import lombok.experimental.Accessors;
@@ -40,7 +40,7 @@ public class R<T> implements Serializable {
@Getter
@Setter
private int code = CommonConstant.SUCCESS;
private int code = CommonConstants.SUCCESS;
@Getter
@Setter
@@ -69,6 +69,6 @@ public class R<T> implements Serializable {
public R(Throwable e) {
super();
this.msg = e.getMessage();
this.code = CommonConstant.FAIL;
this.code = CommonConstants.FAIL;
}
}
@@ -17,7 +17,7 @@
package com.pig4cloud.pigx.common.gateway.support;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.gateway.vo.RouteDefinitionVo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -51,7 +51,7 @@ public class RedisRouteDefinitionWriter implements RouteDefinitionRepository {
RouteDefinitionVo vo = new RouteDefinitionVo();
BeanUtils.copyProperties(r, vo);
log.info("保存路由信息{}", vo);
redisTemplate.opsForHash().put(CommonConstant.ROUTE_KEY, r.getId(), vo);
redisTemplate.opsForHash().put(CommonConstants.ROUTE_KEY, r.getId(), vo);
return Mono.empty();
});
}
@@ -60,7 +60,7 @@ public class RedisRouteDefinitionWriter implements RouteDefinitionRepository {
public Mono<Void> delete(Mono<String> routeId) {
routeId.subscribe(id -> {
log.info("删除路由信息{}", id);
redisTemplate.opsForHash().delete(CommonConstant.ROUTE_KEY, id);
redisTemplate.opsForHash().delete(CommonConstants.ROUTE_KEY, id);
});
return Mono.empty();
}
@@ -74,7 +74,7 @@ public class RedisRouteDefinitionWriter implements RouteDefinitionRepository {
@Override
public Flux<RouteDefinition> getRouteDefinitions() {
redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(RouteDefinitionVo.class));
List<RouteDefinitionVo> values = redisTemplate.opsForHash().values(CommonConstant.ROUTE_KEY);
List<RouteDefinitionVo> values = redisTemplate.opsForHash().values(CommonConstants.ROUTE_KEY);
List<RouteDefinition> definitionList = new ArrayList<>();
values.forEach(vo -> {
RouteDefinition routeDefinition = new RouteDefinition();
@@ -19,6 +19,7 @@ package com.pig4cloud.pigx.common.gateway.vo
;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.cloud.gateway.route.RouteDefinition;
import java.io.Serializable;
@@ -31,6 +32,7 @@ import java.io.Serializable;
* See RouteDefinition.class
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class RouteDefinitionVo extends RouteDefinition implements Serializable {
/**
* 路由名称
@@ -22,7 +22,7 @@ package com.pig4cloud.pigx.common.log.util;
import cn.hutool.core.util.URLUtil;
import cn.hutool.http.HttpUtil;
import com.pig4cloud.pigx.admin.api.entity.SysLog;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import lombok.experimental.UtilityClass;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
@@ -45,7 +45,7 @@ public class SysLogUtils {
.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
SysLog sysLog = new SysLog();
sysLog.setCreateBy(Objects.requireNonNull(getUsername()));
sysLog.setType(CommonConstant.STATUS_NORMAL);
sysLog.setType(CommonConstants.STATUS_NORMAL);
sysLog.setRemoteAddr(HttpUtil.getClientIP(request));
sysLog.setRequestUri(URLUtil.getPath(request.getRequestURI()));
sysLog.setMethod(request.getMethod());
@@ -17,7 +17,7 @@
package com.pig4cloud.pigx.common.security.component;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.core.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
@@ -53,7 +53,7 @@ public class GlobalExceptionHandlerResolver {
log.error("全局异常信息 ex={}", e.getMessage(), e);
return R.builder()
.msg(e.getLocalizedMessage())
.code(CommonConstant.FAIL)
.code(CommonConstants.FAIL)
.build();
}
@@ -72,7 +72,7 @@ public class GlobalExceptionHandlerResolver {
log.error("拒绝授权异常信息 ex={}", msg, e);
return R.builder()
.msg(msg)
.code(CommonConstant.FAIL)
.code(CommonConstants.FAIL)
.build();
}
@@ -89,7 +89,7 @@ public class GlobalExceptionHandlerResolver {
log.error("参数绑定异常,ex = {}", fieldErrors.get(0).getDefaultMessage());
return R.builder()
.msg(fieldErrors.get(0).getDefaultMessage())
.code(CommonConstant.FAIL)
.code(CommonConstants.FAIL)
.build();
}
}
@@ -19,10 +19,11 @@ package com.pig4cloud.pigx.common.security.component;
import cn.hutool.http.HttpStatus;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.core.util.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
@@ -47,8 +48,8 @@ public class ResourceAuthExceptionEntryPoint implements AuthenticationEntryPoint
@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws IOException {
response.setCharacterEncoding(CommonConstant.UTF8);
response.setContentType(CommonConstant.CONTENT_TYPE);
response.setCharacterEncoding(CommonConstants.UTF8);
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
R<String> result = new R<>();
result.setCode(HttpStatus.HTTP_UNAUTHORIZED);
if (authException != null) {
@@ -17,7 +17,7 @@
package com.pig4cloud.pigx.common.security.feign;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.core.util.TenantContextHolder;
import feign.RequestInterceptor;
import feign.RequestTemplate;
@@ -35,6 +35,6 @@ public class PigxFeignTenantInterceptor implements RequestInterceptor {
log.error("TTL 中的 租户ID为空,feign拦截器 >> 增强失败");
return;
}
requestTemplate.header(CommonConstant.TENANT_ID, TenantContextHolder.getTenantId().toString());
requestTemplate.header(CommonConstants.TENANT_ID, TenantContextHolder.getTenantId().toString());
}
}
@@ -18,7 +18,7 @@
package com.pig4cloud.pigx.common.security.filter;
import cn.hutool.core.util.StrUtil;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.core.util.TenantContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
@@ -48,7 +48,7 @@ public class TenantContextHolderFilter extends GenericFilterBean {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
String tenantId = request.getHeader(CommonConstant.TENANT_ID);
String tenantId = request.getHeader(CommonConstants.TENANT_ID);
log.debug("获取header中的租户ID为:{}", tenantId);
if (StrUtil.isNotBlank(tenantId)) {
@@ -19,11 +19,11 @@ package com.pig4cloud.pigx.common.security.handler;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.CharsetUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.common.security.util.AuthUtils;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.Authentication;
import org.springframework.security.crypto.password.PasswordEncoder;
@@ -93,7 +93,7 @@ public class MobileLoginSuccessHandler implements AuthenticationSuccessHandler {
log.info("获取token 成功:{}", oAuth2AccessToken.getValue());
response.setCharacterEncoding(CharsetUtil.UTF_8);
response.setContentType(CommonConstant.CONTENT_TYPE);
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
PrintWriter printWriter = response.getWriter();
printWriter.append(objectMapper.writeValueAsString(oAuth2AccessToken));
} catch (IOException e) {
@@ -22,7 +22,7 @@ import cn.hutool.core.util.StrUtil;
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
import com.pig4cloud.pigx.admin.api.entity.SysUser;
import com.pig4cloud.pigx.admin.api.feign.RemoteUserService;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
import com.pig4cloud.pigx.common.core.util.R;
import lombok.AllArgsConstructor;
@@ -98,10 +98,10 @@ public class PigxUserDetailsServiceImpl implements PigxUserDetailsService {
Collection<? extends GrantedAuthority> authorities
= AuthorityUtils.createAuthorityList(dbAuthsSet.toArray(new String[0]));
SysUser user = info.getSysUser();
boolean enabled = StrUtil.equals(user.getDelFlag(), CommonConstant.STATUS_NORMAL);
boolean enabled = StrUtil.equals(user.getDelFlag(), CommonConstants.STATUS_NORMAL);
// 构造security用户
return new PigxUser(user.getUserId(), user.getDeptId(), user.getTenantId(), user.getUsername(), SecurityConstants.BCRYPT + user.getPassword(), enabled,
true, true, !CommonConstant.STATUS_LOCK.equals(user.getLockFlag()), authorities);
true, true, !CommonConstants.STATUS_LOCK.equals(user.getLockFlag()), authorities);
}
}
@@ -18,7 +18,7 @@
package com.pig4cloud.pigx.common.transaction.rewrite;
import com.codingapi.tx.config.service.TxManagerTxUrlService;
import com.pig4cloud.pigx.common.core.constant.ServiceNameConstant;
import com.pig4cloud.pigx.common.core.constant.ServiceNameConstants;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.ServiceInstance;
@@ -38,7 +38,7 @@ public class TxManagerTxUrlServiceImpl implements TxManagerTxUrlService {
@Override
public String getTxUrl() {
ServiceInstance serviceInstance = loadBalancerClient.choose(ServiceNameConstant.TX_MANAGER);
ServiceInstance serviceInstance = loadBalancerClient.choose(ServiceNameConstants.TX_MANAGER);
String host = serviceInstance.getHost();
Integer port = serviceInstance.getPort();
String url = String.format("http://%s:%s/tx/manager/", host, port);