mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 04:39:00 +08:00
✨ 添加新特性。 ignore-urls 直接通过Inner 注解同步
This commit is contained in:
1 parent
53a9803c7e
commit
5cb1a24ea8
19 files changed
+73
-43
No files matched your search
+3
-3
@@ -21,11 +21,11 @@ import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/11/26
|
||||
* @date 2019/4/13
|
||||
* <p>
|
||||
* 服务调用不鉴权注解
|
||||
* 服务调用鉴权注解
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface Inner {
|
||||
|
||||
+49
-7
@@ -17,26 +17,68 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.component;
|
||||
|
||||
import lombok.Data;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/11/10
|
||||
* @date 2019/4/13
|
||||
* <p>
|
||||
* 资源服务器对外直接暴露URL
|
||||
* 资源服务器对外直接暴露URL,如果设置contex-path 要特殊处理
|
||||
*/
|
||||
@Data
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@RefreshScope
|
||||
@ConditionalOnExpression("!'${security.oauth2.client.ignore-urls}'.isEmpty()")
|
||||
@ConfigurationProperties(prefix = "security.oauth2.client")
|
||||
public class PermitAllUrlProperties {
|
||||
public class PermitAllUrlProperties implements InitializingBean {
|
||||
private static final Pattern PATTERN = Pattern.compile("\\{(.*?)\\}");
|
||||
@Autowired
|
||||
private WebApplicationContext applicationContext;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private List<String> ignoreUrls = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
|
||||
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
|
||||
|
||||
map.keySet().forEach(info -> {
|
||||
HandlerMethod handlerMethod = map.get(info);
|
||||
|
||||
// 获取方法上边的注解 替代path variable 为 *
|
||||
Inner method = AnnotationUtils.findAnnotation(handlerMethod.getMethod(), Inner.class);
|
||||
Optional.ofNullable(method)
|
||||
.ifPresent(inner -> info.getPatternsCondition().getPatterns()
|
||||
.forEach(url -> ignoreUrls.add(ReUtil.replaceAll(url, PATTERN, StringPool.ASTERISK))));
|
||||
|
||||
// 获取类上边的注解, 替代path variable 为 *
|
||||
Inner controller = AnnotationUtils.findAnnotation(handlerMethod.getBeanType(), Inner.class);
|
||||
Optional.ofNullable(controller)
|
||||
.ifPresent(inner -> info.getPatternsCondition().getPatterns()
|
||||
.forEach(url -> ignoreUrls.add(ReUtil.replaceAll(url, PATTERN, StringPool.ASTERISK))));
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,7 @@ security:
|
||||
ignore-urls:
|
||||
- '/actuator/**'
|
||||
- '/v2/api-docs'
|
||||
- '/service/**'
|
||||
- '/editor-app/**'
|
||||
- '/task/view/*'
|
||||
- '/process/resource/**'
|
||||
- '/modeler.html'
|
||||
- '/ws/**'
|
||||
spring:
|
||||
|
||||
@@ -5,11 +5,6 @@ security:
|
||||
client-id: ENC(tz2NM4GcmnE7sNJTYL8ZSg==)
|
||||
client-secret: ENC(tz2NM4GcmnE7sNJTYL8ZSg==)
|
||||
scope: server
|
||||
# 默认放行url,子模块重写时application-dev.yml中的公共配置会被覆盖,所以要把公共配置中的放行url再写一次
|
||||
ignore-urls:
|
||||
- /actuator/**
|
||||
- /v2/api-docs
|
||||
- /inner-job/**
|
||||
|
||||
# 数据源配置
|
||||
spring:
|
||||
|
||||
@@ -5,10 +5,6 @@ security:
|
||||
client-id: ENC(gPFcUOmJm8WqM3k3eSqS0Q==)
|
||||
client-secret: ENC(gPFcUOmJm8WqM3k3eSqS0Q==)
|
||||
scope: server
|
||||
ignore-urls:
|
||||
- /actuator/**
|
||||
- /v2/api-docs
|
||||
- /*/portal
|
||||
|
||||
# 数据源配置
|
||||
spring:
|
||||
|
||||
@@ -5,14 +5,6 @@ security:
|
||||
client-id: ENC(ltJPpR50wT0oIY9kfOe1Iw==)
|
||||
client-secret: ENC(ltJPpR50wT0oIY9kfOe1Iw==)
|
||||
scope: server
|
||||
# 默认放行url,子模块重写时application-dev.yml中的公共配置会被覆盖,所以要把公共配置中的放行url再写一次
|
||||
ignore-urls:
|
||||
- /actuator/**
|
||||
- /v2/api-docs
|
||||
- /user/info/*
|
||||
- /social/info/*
|
||||
- /mobile/*
|
||||
- /log/save
|
||||
|
||||
# 数据源
|
||||
spring:
|
||||
|
||||
+2
@@ -19,6 +19,7 @@ package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import com.pig4cloud.pigx.admin.service.MobileService;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -39,6 +40,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class MobileController {
|
||||
private final MobileService mobileService;
|
||||
|
||||
@Inner(value = false)
|
||||
@GetMapping("/{mobile}")
|
||||
public R sendSmsCode(@PathVariable String mobile) {
|
||||
return mobileService.sendSmsCode(mobile);
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysSocialDetails;
|
||||
@@ -80,7 +81,7 @@ public class SysSocialDetailsServiceImpl extends ServiceImpl<SysSocialDetailsMap
|
||||
*/
|
||||
@Override
|
||||
public UserInfo getUserInfo(String inStr) {
|
||||
String[] inStrs = inStr.split("@");
|
||||
String[] inStrs = inStr.split(StringPool.AT);
|
||||
String type = inStrs[0];
|
||||
String loginStr = inStrs[1];
|
||||
return loginHandlerMap.get(type).handle(loginStr);
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ public class PigxAdminApplicationTest {
|
||||
StringEncryptor stringEncryptor = new DefaultLazyEncryptor(new StandardEnvironment());
|
||||
|
||||
//加密方法
|
||||
System.out.println(stringEncryptor.encrypt("pigx"));
|
||||
System.out.println(stringEncryptor.encrypt("root"));
|
||||
|
||||
//解密方法
|
||||
System.out.println(stringEncryptor.decrypt("ltJPpR50wT0oIY9kfOe1Iw==="));
|
||||
|
||||
+2
-2
@@ -59,11 +59,11 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
|
||||
}
|
||||
// 验证令牌信息
|
||||
OAuth2Authentication auth2Authentication = tokenService.loadAuthentication(tokens.split(" ")[1]);
|
||||
if(ObjectUtil.isNotNull(auth2Authentication)) {
|
||||
if (ObjectUtil.isNotNull(auth2Authentication)) {
|
||||
SecurityContextHolder.getContext().setAuthentication(auth2Authentication);
|
||||
accessor.setUser(() -> (String) auth2Authentication.getPrincipal());
|
||||
return message;
|
||||
}else{
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -18,16 +18,18 @@
|
||||
package com.pig4cloud.pigx.act.controller;
|
||||
|
||||
import com.pig4cloud.pigx.act.service.EditorService;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/9/25
|
||||
* @date 2018/4/13
|
||||
*/
|
||||
@Inner(value = false)
|
||||
@RestController
|
||||
@RequestMapping("/service")
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/service")
|
||||
public class EditorController {
|
||||
private final EditorService editorService;
|
||||
|
||||
|
||||
+2
@@ -21,6 +21,7 @@ import cn.hutool.core.io.IoUtil;
|
||||
import com.pig4cloud.pigx.act.service.ProcessService;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.ResourceTypeEnum;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -46,6 +47,7 @@ public class ProcessController {
|
||||
return new R<>(processService.getProcessByPage(params));
|
||||
}
|
||||
|
||||
@Inner(value = false)
|
||||
@GetMapping(value = "/resource/{proInsId}/{procDefId}/{resType}")
|
||||
public ResponseEntity resourceRead(@PathVariable String procDefId, @PathVariable String proInsId, @PathVariable String resType) {
|
||||
|
||||
|
||||
+2
@@ -21,6 +21,7 @@ import cn.hutool.core.io.IoUtil;
|
||||
import com.pig4cloud.pigx.act.dto.LeaveBillDto;
|
||||
import com.pig4cloud.pigx.act.service.ActTaskService;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -57,6 +58,7 @@ public class TaskController {
|
||||
return new R(actTaskService.submitTask(leaveBillDto));
|
||||
}
|
||||
|
||||
@Inner(value = false)
|
||||
@GetMapping("/view/{id}")
|
||||
public ResponseEntity viewCurrentImage(@PathVariable String id) {
|
||||
InputStream imageStream = actTaskService.viewByTaskId(id);
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ public class DynamicDataSourceConfig implements TransactionManagementConfigurer
|
||||
HikariDataSource ds = new HikariDataSource();
|
||||
ds.setJdbcUrl(String.valueOf(db.get(DataSourceConstant.DS_JDBC_URL)));
|
||||
ds.setDriverClassName(Driver.class.getName());
|
||||
ds.setUsername((String) db.get(DataSourceConstant.DS_NAME));
|
||||
ds.setUsername((String) db.get(DataSourceConstant.DS_USER_NAME));
|
||||
|
||||
String decPwd = stringEncryptor.decrypt((String) db.get(DataSourceConstant.DS_USER_PWD));
|
||||
ds.setPassword(decPwd);
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ class AutowireCapableBeanJobFactory extends SpringBeanJobFactory {
|
||||
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
|
||||
Object jobInstance = super.createJobInstance(bundle);
|
||||
this.beanFactory.autowireBean(jobInstance);
|
||||
this.beanFactory.initializeBean(jobInstance, (String) null);
|
||||
this.beanFactory.initializeBean(jobInstance, null);
|
||||
return jobInstance;
|
||||
}
|
||||
}
|
||||
-3
@@ -23,7 +23,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
|
||||
import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
import com.pig4cloud.pigx.daemon.quartz.entity.SysJob;
|
||||
@@ -67,7 +66,6 @@ public class SysJobController {
|
||||
@GetMapping("/page")
|
||||
@ApiOperation(value = "分页定时业务查询")
|
||||
public R getSysJobPage(Page page, SysJob sysJob) {
|
||||
sysJob.setTenantId(TenantContextHolder.getTenantId());
|
||||
return R.builder().data(sysJobService.page(page, Wrappers.query(sysJob))).build();
|
||||
}
|
||||
|
||||
@@ -97,7 +95,6 @@ public class SysJobController {
|
||||
public R save(@RequestBody SysJob sysJob) {
|
||||
sysJob.setJobStatus(JOB_STATUS_RELEASE.getType());
|
||||
sysJob.setCreateBy(SecurityUtils.getUser().getUsername());
|
||||
sysJob.setTenantId(TenantContextHolder.getTenantId());
|
||||
return R.builder().data(sysJobService.save(sysJob)).build();
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -20,7 +20,6 @@ package com.pig4cloud.pigx.daemon.quartz.controller;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
|
||||
import com.pig4cloud.pigx.daemon.quartz.entity.SysJobLog;
|
||||
import com.pig4cloud.pigx.daemon.quartz.service.SysJobLogService;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -53,7 +52,6 @@ public class SysJobLogController {
|
||||
@GetMapping("/page")
|
||||
@ApiOperation(value = "分页定时任务日志查询")
|
||||
public R getSysJobLogPage(Page page, SysJobLog sysJobLog) {
|
||||
sysJobLog.setTenantId(TenantContextHolder.getTenantId());
|
||||
return R.builder().data(sysJobLogService.page(page, Wrappers.query(sysJobLog))).build();
|
||||
}
|
||||
}
|
||||
+2
@@ -1,6 +1,7 @@
|
||||
package com.pig4cloud.pigx.daemon.quartz.task;
|
||||
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -22,6 +23,7 @@ public class RestTaskDemo {
|
||||
/**
|
||||
* 测试REST风格调用定时任务的演示方法
|
||||
*/
|
||||
@Inner(value = false)
|
||||
@GetMapping("/{param}")
|
||||
public R demoMethod(@PathVariable("param") String param) {
|
||||
log.info("测试于:{},传入参数{}", LocalDateTime.now(), param);
|
||||
|
||||
+2
@@ -2,6 +2,7 @@ package com.pig4cloud.pigx.mp.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import com.pig4cloud.pigx.mp.config.WxMpConfiguration;
|
||||
import com.pig4cloud.pigx.mp.config.WxMpContextHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -18,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
* 微信接入入口
|
||||
*/
|
||||
@Slf4j
|
||||
@Inner(value = false)
|
||||
@RestController
|
||||
@RequestMapping("/{appId}/portal")
|
||||
public class WxPortalController {
|
||||
|
||||
Reference in new issue
Block a user