mirror of
https://gitee.com/log4j/pig.git
synced 2024-12-22 20:54:25 +08:00
!274 ♻️ Refactoring code. 是使用 @RequestMapping Headers属性替代 代码中指定header 参数
Merge pull request !274 from lbw/auto-441246-dev-bc4fb4a1
This commit is contained in:
commit
e74bc1a04b
@ -27,7 +27,6 @@ import com.pig4cloud.pig.admin.api.vo.TokenVo;
|
||||
import com.pig4cloud.pig.auth.support.handler.PigAuthenticationFailureEventHandler;
|
||||
import com.pig4cloud.pig.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pig.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pig.common.core.util.R;
|
||||
import com.pig4cloud.pig.common.core.util.RetOps;
|
||||
import com.pig4cloud.pig.common.core.util.SpringContextHolder;
|
||||
@ -108,8 +107,7 @@ public class PigTokenEndpoint {
|
||||
@RequestParam(OAuth2ParameterNames.CLIENT_ID) String clientId,
|
||||
@RequestParam(OAuth2ParameterNames.SCOPE) String scope,
|
||||
@RequestParam(OAuth2ParameterNames.STATE) String state) {
|
||||
SysOauthClientDetails clientDetails = RetOps
|
||||
.of(clientDetailsService.getClientDetailsById(clientId, SecurityConstants.FROM_IN)).getData()
|
||||
SysOauthClientDetails clientDetails = RetOps.of(clientDetailsService.getClientDetailsById(clientId)).getData()
|
||||
.orElseThrow(() -> new OAuthClientException("clientId 不合法"));
|
||||
|
||||
Set<String> authorizedScopes = StringUtils.commaDelimitedListToSet(clientDetails.getScope());
|
||||
|
@ -47,6 +47,11 @@ public interface SecurityConstants {
|
||||
*/
|
||||
String FROM = "from";
|
||||
|
||||
/**
|
||||
* 请求header
|
||||
*/
|
||||
String HEADER_FROM_IN = FROM + ":" + FROM_IN;
|
||||
|
||||
/**
|
||||
* 默认登录URL
|
||||
*/
|
||||
|
@ -18,7 +18,6 @@ package com.pig4cloud.pig.common.log.event;
|
||||
|
||||
import com.pig4cloud.pig.admin.api.entity.SysLog;
|
||||
import com.pig4cloud.pig.admin.api.feign.RemoteLogService;
|
||||
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
@ -39,7 +38,7 @@ public class SysLogListener {
|
||||
@EventListener(SysLogEvent.class)
|
||||
public void saveSysLog(SysLogEvent event) {
|
||||
SysLog sysLog = (SysLog) event.getSource();
|
||||
remoteLogService.saveLog(sysLog, SecurityConstants.FROM_IN);
|
||||
remoteLogService.saveLog(sysLog);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class PigAppUserDetailsServiceImpl implements PigUserDetailsService {
|
||||
return (PigUser) cache.get(phone).get();
|
||||
}
|
||||
|
||||
R<UserInfo> result = remoteUserService.infoByMobile(phone, SecurityConstants.FROM_IN);
|
||||
R<UserInfo> result = remoteUserService.infoByMobile(phone);
|
||||
|
||||
UserDetails userDetails = getUserDetails(result);
|
||||
if (cache != null) {
|
||||
|
@ -86,8 +86,7 @@ public class PigRemoteRegisteredClientRepository implements RegisteredClientRepo
|
||||
@Cacheable(value = CacheConstants.CLIENT_DETAILS_KEY, key = "#clientId", unless = "#result == null")
|
||||
public RegisteredClient findByClientId(String clientId) {
|
||||
|
||||
SysOauthClientDetails clientDetails = RetOps
|
||||
.of(clientDetailsService.getClientDetailsById(clientId, SecurityConstants.FROM_IN)).getData()
|
||||
SysOauthClientDetails clientDetails = RetOps.of(clientDetailsService.getClientDetailsById(clientId)).getData()
|
||||
.orElseThrow(() -> new OAuthClientException("客户端查询异常,请检查数据库链接"));
|
||||
|
||||
RegisteredClient.Builder builder = RegisteredClient.withId(clientDetails.getClientId())
|
||||
|
@ -19,7 +19,6 @@ package com.pig4cloud.pig.common.security.service;
|
||||
import com.pig4cloud.pig.admin.api.dto.UserInfo;
|
||||
import com.pig4cloud.pig.admin.api.feign.RemoteUserService;
|
||||
import com.pig4cloud.pig.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pig.common.core.util.R;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
@ -56,7 +55,7 @@ public class PigUserDetailsServiceImpl implements PigUserDetailsService {
|
||||
return (PigUser) cache.get(username).get();
|
||||
}
|
||||
|
||||
R<UserInfo> result = remoteUserService.info(username, SecurityConstants.FROM_IN);
|
||||
R<UserInfo> result = remoteUserService.info(username);
|
||||
UserDetails userDetails = getUserDetails(result);
|
||||
if (cache != null) {
|
||||
cache.put(username, userDetails);
|
||||
|
@ -26,7 +26,6 @@ import com.pig4cloud.pig.common.core.util.R;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -40,19 +39,16 @@ public interface RemoteClientDetailsService {
|
||||
/**
|
||||
* 通过clientId 查询客户端信息
|
||||
* @param clientId 用户名
|
||||
* @param from 调用标志
|
||||
* @return R
|
||||
*/
|
||||
@GetMapping("/client/getClientDetailsById/{clientId}")
|
||||
R<SysOauthClientDetails> getClientDetailsById(@PathVariable("clientId") String clientId,
|
||||
@RequestHeader(SecurityConstants.FROM) String from);
|
||||
@GetMapping(value = "/client/getClientDetailsById/{clientId}", headers = SecurityConstants.HEADER_FROM_IN)
|
||||
R<SysOauthClientDetails> getClientDetailsById(@PathVariable("clientId") String clientId);
|
||||
|
||||
/**
|
||||
* 查询全部客户端
|
||||
* @param from 调用标识
|
||||
* @return R
|
||||
*/
|
||||
@GetMapping("/client/list")
|
||||
R<List<SysOauthClientDetails>> listClientDetails(@RequestHeader(SecurityConstants.FROM) String from);
|
||||
@GetMapping(value = "/client/list", headers = SecurityConstants.HEADER_FROM_IN)
|
||||
R<List<SysOauthClientDetails>> listClientDetails();
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import com.pig4cloud.pig.common.core.util.R;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -36,8 +35,7 @@ public interface RemoteDeptService {
|
||||
* 查收子级id列表
|
||||
* @return 返回子级id列表
|
||||
*/
|
||||
@GetMapping("/dept/child-id/{deptId}")
|
||||
R<List<Long>> listChildDeptId(@PathVariable("deptId") Long deptId,
|
||||
@RequestHeader(SecurityConstants.FROM) String from);
|
||||
@GetMapping(value = "/dept/child-id/{deptId}", headers = SecurityConstants.HEADER_FROM_IN)
|
||||
R<List<Long>> listChildDeptId(@PathVariable("deptId") Long deptId);
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ import com.pig4cloud.pig.common.core.util.R;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
@ -35,10 +34,9 @@ public interface RemoteLogService {
|
||||
/**
|
||||
* 保存日志
|
||||
* @param sysLog 日志实体
|
||||
* @param from 内部调用标志
|
||||
* @return succes、false
|
||||
*/
|
||||
@PostMapping("/log")
|
||||
R<Boolean> saveLog(@RequestBody SysLog sysLog, @RequestHeader(SecurityConstants.FROM) String from);
|
||||
@PostMapping(value = "/log", headers = SecurityConstants.HEADER_FROM_IN)
|
||||
R<Boolean> saveLog(@RequestBody SysLog sysLog);
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import com.pig4cloud.pig.common.core.util.R;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
@ -20,10 +19,9 @@ public interface RemoteParamService {
|
||||
/**
|
||||
* 通过key 查询参数配置
|
||||
* @param key key
|
||||
* @param from 声明成内部调用,避免MQ 等无法调用
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/param/publicValue/{key}")
|
||||
R<String> getByKey(@PathVariable("key") String key, @RequestHeader(SecurityConstants.FROM) String from);
|
||||
@GetMapping(value = "/param/publicValue/{key}", headers = SecurityConstants.HEADER_FROM_IN)
|
||||
R<String> getByKey(@PathVariable("key") String key);
|
||||
|
||||
}
|
||||
|
@ -34,19 +34,17 @@ public interface RemoteTokenService {
|
||||
/**
|
||||
* 分页查询token 信息
|
||||
* @param params 分页参数
|
||||
* @param from 内部调用标志
|
||||
* @return page
|
||||
*/
|
||||
@PostMapping("/token/page")
|
||||
R getTokenPage(@RequestBody Map<String, Object> params, @RequestHeader(SecurityConstants.FROM) String from);
|
||||
@PostMapping(value = "/token/page", headers = SecurityConstants.HEADER_FROM_IN)
|
||||
R getTokenPage(@RequestBody Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 删除token
|
||||
* @param token token
|
||||
* @param from 调用标志
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping("/token/{token}")
|
||||
R<Boolean> removeToken(@PathVariable("token") String token, @RequestHeader(SecurityConstants.FROM) String from);
|
||||
@DeleteMapping(value = "/token/{token}", headers = SecurityConstants.HEADER_FROM_IN)
|
||||
R<Boolean> removeToken(@PathVariable("token") String token);
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ import com.pig4cloud.pig.common.core.util.R;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
@ -39,11 +38,10 @@ public interface RemoteUserService {
|
||||
/**
|
||||
* 通过用户名查询用户、角色信息
|
||||
* @param username 用户名
|
||||
* @param from 调用标志
|
||||
* @return R
|
||||
*/
|
||||
@GetMapping("/user/info/{username}")
|
||||
R<UserInfo> info(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM) String from);
|
||||
@GetMapping(value = "/user/info/{username}", headers = SecurityConstants.HEADER_FROM_IN)
|
||||
R<UserInfo> info(@PathVariable("username") String username);
|
||||
|
||||
/**
|
||||
* 通过手机号码查询用户、角色信息
|
||||
@ -51,8 +49,8 @@ public interface RemoteUserService {
|
||||
* @param from 调用标志
|
||||
* @return R
|
||||
*/
|
||||
@GetMapping("/app/info/{phone}")
|
||||
R<UserInfo> infoByMobile(@PathVariable("phone") String phone, @RequestHeader(SecurityConstants.FROM) String from);
|
||||
@GetMapping(value = "/app/info/{phone}", headers = SecurityConstants.HEADER_FROM_IN)
|
||||
R<UserInfo> infoByMobile(@PathVariable("phone") String phone);
|
||||
|
||||
/**
|
||||
* 根据部门id,查询对应的用户 id 集合
|
||||
@ -60,8 +58,7 @@ public interface RemoteUserService {
|
||||
* @param from 调用标志
|
||||
* @return 用户 id 集合
|
||||
*/
|
||||
@GetMapping("/user/ids")
|
||||
R<List<Long>> listUserIdByDeptIds(@RequestParam("deptIds") Set<Long> deptIds,
|
||||
@RequestHeader(SecurityConstants.FROM) String from);
|
||||
@GetMapping(value = "/user/ids", headers = SecurityConstants.HEADER_FROM_IN)
|
||||
R<List<Long>> listUserIdByDeptIds(@RequestParam("deptIds") Set<Long> deptIds);
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.pig4cloud.pig.admin.api.util;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.pig4cloud.pig.admin.api.feign.RemoteParamService;
|
||||
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pig.common.core.util.SpringContextHolder;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@ -44,7 +43,7 @@ public class ParamResolver {
|
||||
|
||||
RemoteParamService remoteParamService = SpringContextHolder.getBean(RemoteParamService.class);
|
||||
|
||||
String result = remoteParamService.getByKey(key, SecurityConstants.FROM_IN).getData();
|
||||
String result = remoteParamService.getByKey(key).getData();
|
||||
|
||||
if (StrUtil.isNotBlank(result)) {
|
||||
return Convert.convert(clazz, result);
|
||||
|
@ -17,7 +17,6 @@
|
||||
package com.pig4cloud.pig.admin.controller;
|
||||
|
||||
import com.pig4cloud.pig.admin.api.feign.RemoteTokenService;
|
||||
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pig.common.core.util.R;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -48,7 +47,7 @@ public class TokenController {
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public R token(@RequestParam Map<String, Object> params) {
|
||||
return remoteTokenService.getTokenPage(params, SecurityConstants.FROM_IN);
|
||||
return remoteTokenService.getTokenPage(params);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +58,7 @@ public class TokenController {
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('sys_token_del')")
|
||||
public R<Boolean> delete(@PathVariable String id) {
|
||||
return remoteTokenService.removeToken(id, SecurityConstants.FROM_IN);
|
||||
return remoteTokenService.removeToken(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user