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

@@ -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);
}
}