From ce121a0b22946cec7402e96ca12f3f1f33427f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=80=A1?= Date: Wed, 30 Apr 2025 16:39:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E5=8E=BB=E9=99=A4apollo=E3=80=81security=E5=92=8Cseata?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=9B=BF=E6=8D=A2=E4=B8=BAnacos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 99 ++++++++++--------- .../BizServiceEbtpExtendApplication.java | 3 - .../controller/BizBidNoticeController.java | 9 -- .../controller/BizBidSharedController.java | 4 - .../BizBidSharedRecordController.java | 3 - .../controller/AuthorizeController.java | 12 +-- .../extend/config/SeataInterceptorConfig.java | 36 ------- .../crypconfigure/crypto/helper/Utils.java | 21 ---- .../export/controller/ExportController.java | 6 +- .../extend/iam/client/BidRatioClient.java | 18 ++++ .../ebtp/extend/iam/client/IamClient.java | 15 +++ .../iam/controller/IamAuthController.java | 38 +++++++ .../extend/iam/entity/AuthRequestDTO.java | 9 ++ .../extend/iam/entity/AuthResponseDTO.java | 10 ++ .../extend/iam/service/IamAuthService.java | 27 +++++ .../controller/ExpertSignatureController.java | 2 - .../controller/SinglePointController.java | 11 +-- .../controller/TimeServiceController.java | 2 - src/main/resources/application-dev.yml | 48 ++------- src/main/resources/application.yml | 4 + 20 files changed, 192 insertions(+), 185 deletions(-) delete mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/config/SeataInterceptorConfig.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/iam/client/BidRatioClient.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/iam/client/IamClient.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/iam/controller/IamAuthController.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/iam/entity/AuthRequestDTO.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/iam/entity/AuthResponseDTO.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/iam/service/IamAuthService.java diff --git a/pom.xml b/pom.xml index b9f0cc7..edecd81 100644 --- a/pom.xml +++ b/pom.xml @@ -4,11 +4,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - com.chinaunicom.ebtp - mall-ebtp-cloud-parent - 2.4.1-zyhy-SNAPSHOT - + + com.chinaunicom.ebtp + mall-ebtp-cloud-parent + 2.4.1-zyhy-SNAPSHOT + com.chinaunicom.mall.ebtp biz_service_ebtp_extend @@ -17,23 +17,23 @@ - - com.chinaunicom.mall.ebtp - uboot-core - 2.4.1-zyhy-SNAPSHOT - + + com.chinaunicom.mall.ebtp + uboot-core + 2.4.1-zyhy-SNAPSHOT + - - - - - - - + + + + + + + - + com.deepoove poi-tl 1.9.1 @@ -75,11 +75,11 @@ ${basedir}/lib/access_token1.3.jar - - - - - + + + + + org.apache.velocity velocity-tools @@ -91,11 +91,11 @@ - - - - - + + + + + org @@ -109,21 +109,24 @@ aliyun-sdk-oss 3.10.2 + + + - - - maven-snapshot-local - maven-snapshot-local - http://ccp.tianti.tg.unicom.local/artifactory/tianti-maven-snapshot-local/ - - false - - - true - always - - + + + maven-snapshot-local + maven-snapshot-local + http://ccp.tianti.tg.unicom.local/artifactory/tianti-maven-snapshot-local/ + + false + + + true + always + + com.e-iceblue @@ -133,7 +136,7 @@ maven-virtual http://ccp.tianti.tg.unicom.local/artifactory/maven-virtual - + @@ -155,12 +158,12 @@ - - - - - - + + + + + + diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/BizServiceEbtpExtendApplication.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/BizServiceEbtpExtendApplication.java index e799bce..0b98460 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/BizServiceEbtpExtendApplication.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/BizServiceEbtpExtendApplication.java @@ -3,7 +3,6 @@ package com.chinaunicom.mall.ebtp.extend; import cn.hutool.core.lang.Snowflake; import cn.hutool.core.util.IdUtil; import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; -import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig; import io.micrometer.core.instrument.MeterRegistry; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Value; @@ -12,7 +11,6 @@ import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCusto import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -20,7 +18,6 @@ import org.springframework.scheduling.annotation.EnableAsync; @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class}) @EnableFeignClients -@EnableEurekaClient @MapperScan({"com.chinaunicom.mall.ebtp.extend.**.dao"}) @ComponentScan("com.chinaunicom.mall.ebtp.*") @EnableAsync diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/bizbidnotice/controller/BizBidNoticeController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/bizbidnotice/controller/BizBidNoticeController.java index b17fb7d..a7563a2 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/bizbidnotice/controller/BizBidNoticeController.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/bizbidnotice/controller/BizBidNoticeController.java @@ -13,7 +13,6 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -64,7 +63,6 @@ public class BizBidNoticeController { * @return */ @ApiOperation("查询所有列表") - @PreAuthorize("hasAnyAuthority('ebtp-system-admin')") @PostMapping("/allList") public BaseResponse> getAll(@RequestBody BizBidNoticeVO bizBidNotice) { @@ -85,7 +83,6 @@ public class BizBidNoticeController { * @return */ @ApiOperation("插入新数据") - @PreAuthorize("hasAnyAuthority('ebtp-system-admin')") @PostMapping("/add") public BaseResponse insert( @ApiParam(value = "对象数据", required = true) @RequestBody @Valid BizBidNotice bizBidNotice) { @@ -103,7 +100,6 @@ public class BizBidNoticeController { * @return */ @ApiOperation("修改数据") - @PreAuthorize("hasAnyAuthority('ebtp-system-admin')") @PostMapping("/update") public BaseResponse update( @ApiParam(value = "对象数据", required = true) @RequestBody BizBidNotice bizBidNotice) { @@ -118,7 +114,6 @@ public class BizBidNoticeController { * @return */ @ApiOperation("发布数据") - @PreAuthorize("hasAnyAuthority('ebtp-system-admin')") @PostMapping("/fabu/{id}") public BaseResponse fabu(@ApiParam(value = "主键id", required = true) @PathVariable String id) { BizBidNotice notice = new BizBidNotice(); @@ -134,7 +129,6 @@ public class BizBidNoticeController { * @return */ @ApiOperation("发布数据") - @PreAuthorize("hasAnyAuthority('ebtp-system-admin')") @PostMapping("/qxfabu/{id}") public BaseResponse qxfabu(@ApiParam(value = "主键id", required = true) @PathVariable String id) { @@ -151,7 +145,6 @@ public class BizBidNoticeController { * @return */ @ApiOperation("置顶数据") - @PreAuthorize("hasAnyAuthority('ebtp-system-admin')") @PostMapping("/top/{id}") public BaseResponse top(@ApiParam(value = "主键id", required = true) @PathVariable String id) { @@ -169,7 +162,6 @@ public class BizBidNoticeController { * @return */ @ApiOperation("取消置顶数据") - @PreAuthorize("hasAnyAuthority('ebtp-system-admin')") @PostMapping("/qxtop/{id}") public BaseResponse qxtop(@ApiParam(value = "主键id", required = true) @PathVariable String id) { @@ -198,7 +190,6 @@ public class BizBidNoticeController { * @return */ @ApiOperation("删除数据") - @PreAuthorize("hasAnyAuthority('ebtp-system-admin')") @PostMapping("/delete/{id}") public BaseResponse delete(@ApiParam(value = "主键id", required = true) @PathVariable String id) { return BaseResponse.success(ibizBidNoticeService.removeById(id)); diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/bizbidshared/controller/BizBidSharedController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/bizbidshared/controller/BizBidSharedController.java index 4a166c6..29be20c 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/bizbidshared/controller/BizBidSharedController.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/bizbidshared/controller/BizBidSharedController.java @@ -12,7 +12,6 @@ import com.chinaunicom.mall.ebtp.extend.bizbidshared.service.IBizBidSharedServic import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; @@ -47,7 +46,6 @@ public class BizBidSharedController { * @return */ @ApiOperation("插入新数据") - @PreAuthorize("hasAnyAuthority('ebtp-system-admin')") @PostMapping("/add") public BaseResponse insert(@ApiParam(value = "对象数据", required = true) @RequestBody @Valid BizBidShared bizBidShared) { if (StringUtils.isEmpty(bizBidShared.getId())) { @@ -67,7 +65,6 @@ public class BizBidSharedController { * @return */ @ApiOperation("修改数据") - @PreAuthorize("hasAnyAuthority('ebtp-system-admin')") @PostMapping("") public BaseResponse update(@ApiParam(value = "对象数据", required = true) @RequestBody BizBidShared bizBidShared) { return BaseResponse.success(ibizBidSharedService.updateById(bizBidShared)); @@ -92,7 +89,6 @@ public class BizBidSharedController { * @return */ @ApiOperation("删除数据") - @PreAuthorize("hasAnyAuthority('ebtp-system-admin')") @PostMapping("/delete/{id}") public BaseResponse delete(@ApiParam(value = "主键id", required = true) @PathVariable String id) { return BaseResponse.success(ibizBidSharedService.removeById(id)); diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/bizbidsharedrecord/controller/BizBidSharedRecordController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/bizbidsharedrecord/controller/BizBidSharedRecordController.java index 10f090b..9706e08 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/bizbidsharedrecord/controller/BizBidSharedRecordController.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/bizbidsharedrecord/controller/BizBidSharedRecordController.java @@ -12,7 +12,6 @@ import com.chinaunicom.mall.ebtp.extend.bizbidsharedrecord.service.IBizBidShared import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -35,7 +34,6 @@ public class BizBidSharedRecordController { * @return */ @ApiOperation("查询数据列表") - @PreAuthorize("hasAnyAuthority('ebtp-system-admin')") @PostMapping("/list/{id}") public BasePageResponse getList(@PathVariable("id") String id, @ApiParam(value = "对象数据", required = true) @RequestBody @Valid BizBidSharedRecordVO bizBidShared) { @@ -75,7 +73,6 @@ public class BizBidSharedRecordController { * @return */ @ApiOperation("修改数据") - @PreAuthorize("hasAnyAuthority('ebtp-system-admin')") @PostMapping("/update") public BaseResponse update( @ApiParam(value = "对象数据", required = true) @RequestBody BizBidSharedRecord bizBidSharedRecord) { diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/bizmessage/controller/AuthorizeController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/bizmessage/controller/AuthorizeController.java index e0e5958..23066f6 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/bizmessage/controller/AuthorizeController.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/bizmessage/controller/AuthorizeController.java @@ -4,8 +4,6 @@ import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser; import com.chinaunicom.mall.ebtp.common.base.service.IBaseCacheUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; @@ -24,11 +22,11 @@ public class AuthorizeController { @ResponseStatus(code = HttpStatus.OK) public Object user(Principal principal) { BaseCacheUser cacheUser = service.getCacheUser(); - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - - System.out.println(auth.getName()); - System.out.println(auth.getAuthorities()); - System.out.println(principal); +// Authentication auth = SecurityContextHolder.getContext().getAuthentication(); +// +// System.out.println(auth.getName()); +// System.out.println(auth.getAuthorities()); +// System.out.println(principal); return cacheUser; } diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/config/SeataInterceptorConfig.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/config/SeataInterceptorConfig.java deleted file mode 100644 index 1243f01..0000000 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/config/SeataInterceptorConfig.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.chinaunicom.mall.ebtp.extend.config; - -import io.seata.core.context.RootContext; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.HandlerInterceptor; -import org.springframework.web.servlet.config.annotation.InterceptorRegistration; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.Objects; - -/** - * seata拦截器配置类 解除seata绑定 - * - * @author fqj - * @date 2022-01-13 - */ -@Configuration -public class SeataInterceptorConfig implements WebMvcConfigurer { - - @Override - public void addInterceptors(InterceptorRegistry registry) { - InterceptorRegistration interceptor = registry.addInterceptor(new HandlerInterceptor() { - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - if (!Objects.isNull(RootContext.getXID())) { - RootContext.unbind(); - } - return true; - } - }); - interceptor.addPathPatterns("/**"); - } -} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/crypconfigure/crypto/helper/Utils.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/crypconfigure/crypto/helper/Utils.java index 9dd156d..e28df06 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/crypconfigure/crypto/helper/Utils.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/crypconfigure/crypto/helper/Utils.java @@ -14,8 +14,6 @@ package com.chinaunicom.mall.ebtp.extend.crypconfigure.crypto.helper; -import com.google.protobuf.ByteString; -import com.google.protobuf.Timestamp; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -221,16 +219,6 @@ public final class Utils { return UUID.randomUUID().toString(); } - /** - * Create a new {@link Timestamp} instance based on the current time - * - * @return timestamp - */ - public static Timestamp generateTimestamp() { - Instant time = Instant.now(); - return Timestamp.newBuilder().setSeconds(time.getEpochSecond()) - .setNanos(time.getNano()).build(); - } /** * Delete a file or directory @@ -378,15 +366,6 @@ public final class Utils { return values; } - public static String toHexString(ByteString byteString) { - if (byteString == null) { - return null; - } - - return encodeHexString(byteString.toByteArray()); - - } - public static String toHexString(byte[] bytes) { if (bytes == null) { return null; diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/export/controller/ExportController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/export/controller/ExportController.java index 7d3b597..d58a754 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/export/controller/ExportController.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/export/controller/ExportController.java @@ -7,7 +7,7 @@ import com.chinaunicom.mall.ebtp.extend.export.service.ExportServiceFactory; import com.chinaunicom.mall.ebtp.extend.export.service.dict.IBizExportDictService; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; +//import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -39,7 +39,7 @@ public class ExportController { * @param request * @param response */ - @PreAuthorize("hasAnyAuthority('ebtp-purchase','ebtp-agency-project-manager')") +// @PreAuthorize("hasAnyAuthority('ebtp-purchase','ebtp-agency-project-manager')") @GetMapping(value = "/{type}") public void export(@PathVariable String type, ExportParam param, HttpServletRequest request, HttpServletResponse response) { exportServiceFactory.getService(type).doExport(param, request, response); @@ -51,7 +51,7 @@ public class ExportController { * @param roomId * @return */ - @PreAuthorize("hasAnyAuthority('ebtp-purchase','ebtp-agency-project-manager')") +// @PreAuthorize("hasAnyAuthority('ebtp-purchase','ebtp-agency-project-manager')") @GetMapping("/list/{roomId}") public BaseResponse>> list(@PathVariable String roomId) { diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/client/BidRatioClient.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/client/BidRatioClient.java new file mode 100644 index 0000000..d8ab4cc --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/client/BidRatioClient.java @@ -0,0 +1,18 @@ +package com.chinaunicom.mall.ebtp.extend.iam.client; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +// 定义 Feign 客户端,服务名为 bid-ratio-service,请求地址为 http://localhost:18012 +@FeignClient(name = "bid-ratio-service", url = "http://localhost:18012") +public interface BidRatioClient { + + /** + * 根据 ID 获取投标比率信息 + * @param id 用于查询的 ID + * @return 响应体,这里使用 String 类型示例,实际可替换为具体的 DTO 类 + */ + @GetMapping("/v1/bidratio/{id}") + String getBidRatio(@PathVariable("id") String id); +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/client/IamClient.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/client/IamClient.java new file mode 100644 index 0000000..77559ee --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/client/IamClient.java @@ -0,0 +1,15 @@ +package com.chinaunicom.mall.ebtp.extend.iam.client; + +import com.chinaunicom.mall.ebtp.extend.iam.entity.AuthRequestDTO; +import com.chinaunicom.mall.ebtp.extend.iam.entity.AuthResponseDTO; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +@FeignClient(name = "iam-service", url = "${iam.service.url}") +public interface IamClient { + + + @PostMapping("/access_token") + AuthResponseDTO getAccessToken(@RequestBody AuthRequestDTO request); +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/controller/IamAuthController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/controller/IamAuthController.java new file mode 100644 index 0000000..0fb5f0e --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/controller/IamAuthController.java @@ -0,0 +1,38 @@ +package com.chinaunicom.mall.ebtp.extend.iam.controller; + +import com.chinaunicom.mall.ebtp.extend.iam.client.BidRatioClient; +import com.chinaunicom.mall.ebtp.extend.iam.service.IamAuthService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/iam/auth") +public class IamAuthController { + + private final IamAuthService iamAuthService; + private final BidRatioClient bidRatioClient; + + public IamAuthController(IamAuthService iamAuthService, BidRatioClient bidRatioClient) { + this.iamAuthService = iamAuthService; + this.bidRatioClient = bidRatioClient; + } + + @GetMapping("/token") + public String getToken() { + String appId = "ap_idsss"; + String appSecret = "abcss"; + return iamAuthService.getAccessToken(appId, appSecret); + } + + /** + * 调用 Feign 客户端获取投标比率信息 + * @param id 用于查询的 ID + * @return 投标比率信息 + */ + @GetMapping("/bidratio/{id}") + public String getBidRatio(@PathVariable("id") String id) { + return bidRatioClient.getBidRatio(id); + } +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/entity/AuthRequestDTO.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/entity/AuthRequestDTO.java new file mode 100644 index 0000000..31c2f9a --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/entity/AuthRequestDTO.java @@ -0,0 +1,9 @@ +package com.chinaunicom.mall.ebtp.extend.iam.entity; + +import lombok.Data; + +@Data +public class AuthRequestDTO { + private String appId; + private String appSecret; +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/entity/AuthResponseDTO.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/entity/AuthResponseDTO.java new file mode 100644 index 0000000..e638308 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/entity/AuthResponseDTO.java @@ -0,0 +1,10 @@ +package com.chinaunicom.mall.ebtp.extend.iam.entity; + +import lombok.Data; + +@Data +public class AuthResponseDTO { + private int errorCode; + private String accessToken; + private long expiresInMS; +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/service/IamAuthService.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/service/IamAuthService.java new file mode 100644 index 0000000..b8c3b16 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/iam/service/IamAuthService.java @@ -0,0 +1,27 @@ +package com.chinaunicom.mall.ebtp.extend.iam.service; + +import com.chinaunicom.mall.ebtp.extend.iam.client.IamClient; +import com.chinaunicom.mall.ebtp.extend.iam.entity.AuthRequestDTO; +import com.chinaunicom.mall.ebtp.extend.iam.entity.AuthResponseDTO; +import org.springframework.stereotype.Service; + +@Service +public class IamAuthService { + + private final IamClient iamClient; + + public IamAuthService(IamClient iamClient) { + this.iamClient = iamClient; + } + + public String getAccessToken(String appId, String appSecret) { + AuthRequestDTO request = new AuthRequestDTO(); + request.setAppId(appId); + request.setAppSecret(appSecret); + AuthResponseDTO response = iamClient.getAccessToken(request); + if (response.getErrorCode() == 0) { + return response.getAccessToken(); + } + throw new RuntimeException("Failed to get access token, error code: " + response.getErrorCode()); + } +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/signature/controller/ExpertSignatureController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/signature/controller/ExpertSignatureController.java index 35ae5d6..34012a5 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/signature/controller/ExpertSignatureController.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/signature/controller/ExpertSignatureController.java @@ -5,7 +5,6 @@ import com.chinaunicom.mall.ebtp.extend.signature.entity.ExpertSignature; import com.chinaunicom.mall.ebtp.extend.signature.service.ExpertSignatureService; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -31,7 +30,6 @@ public class ExpertSignatureController { * @param request * @param response */ - @PreAuthorize("hasAnyAuthority('ebtp-purchase','ebtp-agency-project-manager')") @PostMapping(value = "") public BaseResponse export(@RequestBody ExpertSignature signature, HttpServletRequest request, HttpServletResponse response) { return BaseResponse.success(expertSignatureService.addSignature(signature)); diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/singlePoint/controller/SinglePointController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/singlePoint/controller/SinglePointController.java index de35680..e5b6849 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/singlePoint/controller/SinglePointController.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/singlePoint/controller/SinglePointController.java @@ -2,18 +2,15 @@ package com.chinaunicom.mall.ebtp.extend.singlePoint.controller; import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse; import com.chinaunicom.mall.ebtp.common.base.service.impl.BaseCacheUserServiceImpl; -import com.chinaunicom.mall.ebtp.extend.signature.entity.ExpertSignature; -import com.chinaunicom.mall.ebtp.extend.signature.service.ExpertSignatureService; import com.chinaunicom.mall.ebtp.extend.singlePoint.service.SinglePointService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @RestController diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/controller/TimeServiceController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/controller/TimeServiceController.java index 1265a45..f725b91 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/controller/TimeServiceController.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/timeService/controller/TimeServiceController.java @@ -10,7 +10,6 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import java.text.ParseException; @@ -99,7 +98,6 @@ public class TimeServiceController { */ @ApiOperation("获取开标剩余时间倒数") @GetMapping("/getDescOpenRoomTime") - @PreAuthorize("hasAnyAuthority('ebtp-agency-project-manager','ebtp-purchase','ebtp-supplier')") public BaseResponse getDescOpenRoomTime(@RequestParam(name = "openTime", required = true) String openTime) { try { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 6d0517e..bbdc8a5 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -3,32 +3,11 @@ server: servlet: context-path: / -seata: - service: - vgroup-mapping: - biz-service-ebtp-extend-service-group: default - grouplist: - default: 10.242.37.148:18035 - - #registry: - # type: eureka - # eureka: - # serviceUrl: http://10.242.37.148:5001/eureka,http://10.242.37.148:5002/eureka,http://10.242.37.148:5003/eureka - -# 对应 apollo 配置中心的应用名 -app: - id: biz-service-ebtp-extend - -# Apollo 配置信息 -apollo: - meta: http://localhost:8070 - bootstrap: - namespace: application - enabled: true - eagerLoad: - enabled: true - spring: + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 aop: auto: true #开启spring的aop配置 proxy-target-class: true @@ -59,7 +38,7 @@ spring: testOnReturn: false poolPreparedStatements: true maxOpenPreparedStatements: 20 - connection-properties: druid.stat.merggSql=ture;druid.stat.slowSqlMillis=5000 + connection-properties: druid.stat.mergeSql=ture;druid.stat.slowSqlMillis=5000 props: sql: show: true @@ -96,26 +75,15 @@ spring: # 天宫 redis 需要使用哨兵进行访问 redis: sentinel: - master: eshop-redis + master: mymaster # nodes: 10.125.164.124:32718, 10.125.164.118:32716, 10.125.164.121:32716 - nodes: localhost:6379 -# password: Unicom#135 + nodes: localhost:26379, localhost:26380, localhost:26381 + password: pass database: idempotent: 1 sharding: 1 cache: 1 userinfo: 1 -# 天宫Eureka配置 -eureka: - client: - service-url: -# defaultZone: http://eureka-1-svc:8080/eureka, http://eureka-2-svc:8080/eureka, http://eureka-3-svc:8080/eureka - defaultZone: http://localhost:8080/eureka/ - instance: - prefer-ip-address: true - instance-id: http://10.242.37.148:${server.port} - # 这是客户端的注册地址, eureka 会通过这个地址建立管道 - ip-address: 10.242.37.148 mybatis-plus: configuration: diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 1eb5633..636375c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -91,6 +91,10 @@ mconfig: process: 1 notification: 1 documentcenter: 2 + +iam: + service: + url: https://iam.com/api #jasypt: # encryptor: # bean: stringEncryptor