From 3b64204caa8960b18654c7de588bebfc59b030e0 Mon Sep 17 00:00:00 2001 From: wayn <1669738430@qq.com> Date: Sun, 2 Jul 2023 23:58:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=95=86=E5=9F=8E):=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wayn/common/constant/SysConstants.java | 2 +- .../api/service/impl/IHomeServiceImpl.java | 3 +- .../api/service/impl/OrderServiceImpl.java | 6 +-- .../framework/config/SecurityConfig.java | 53 ++++++++++--------- .../resources/mapper/SearchHistoryMapper.xml | 2 +- 5 files changed, 35 insertions(+), 31 deletions(-) diff --git a/waynboot-common/src/main/java/com/wayn/common/constant/SysConstants.java b/waynboot-common/src/main/java/com/wayn/common/constant/SysConstants.java index b838b13..4048a0f 100644 --- a/waynboot-common/src/main/java/com/wayn/common/constant/SysConstants.java +++ b/waynboot-common/src/main/java/com/wayn/common/constant/SysConstants.java @@ -10,7 +10,7 @@ public class SysConstants { /** - * 缓存前缀, todo 统一项目缓存前缀 + * 缓存前缀, 统一项目缓存前缀 */ public static final String CACHE_PREFIX = "waynboot-mall:"; diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/IHomeServiceImpl.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/IHomeServiceImpl.java index f6fbf28..3bab6f7 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/IHomeServiceImpl.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/IHomeServiceImpl.java @@ -22,7 +22,6 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Service; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -49,7 +48,7 @@ public class IHomeServiceImpl implements IHomeService { R success = R.success(); Map shopHomeIndexHash = redisCache.getCacheMap(SHOP_HOME_INDEX_HASH); // 当缓存中存在数据,并且过期时间不为空而且小于等于过期时间则直接从缓存中取出数据 - long nowTime = System.currentTimeMillis();; + long nowTime = System.currentTimeMillis(); if (MapUtils.isNotEmpty(shopHomeIndexHash) && shopHomeIndexHash.containsKey(SHOP_HOME_INDEX_HASH_EXPIRATION_FIELD)) { long time = (long) shopHomeIndexHash.get(SHOP_HOME_INDEX_HASH_EXPIRATION_FIELD); if ((nowTime - time) <= Constants.ONE_DAY) { diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/OrderServiceImpl.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/OrderServiceImpl.java index 702699b..131a3f1 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/OrderServiceImpl.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/OrderServiceImpl.java @@ -158,7 +158,7 @@ public class OrderServiceImpl extends ServiceImpl implements unrecv++; } else if (OrderUtil.isConfirmStatus(order) || OrderUtil.isAutoConfirmStatus(order)) { uncomment += order.getComments(); - } // todo + } } success.add("unpaid", unpaid); @@ -497,7 +497,7 @@ public class OrderServiceImpl extends ServiceImpl implements String form; try { // 需要自行申请支付宝的沙箱账号、申请appID,并在配置文件中依次配置AppID、密钥、公钥,否则这里会报错。 - form = alipayClient.pageExecute(alipayRequest).getBody();//调用SDK生成表单 + form = alipayClient.pageExecute(alipayRequest).getBody();// 调用SDK生成表单 return R.success().add("form", form); } catch (AlipayApiException e) { log.error(e.getMessage(), e); @@ -599,7 +599,7 @@ public class OrderServiceImpl extends ServiceImpl implements @Override public void aliPayNotify(HttpServletRequest request, HttpServletResponse response) throws AlipayApiException { - //将异步通知中收到的所有参数都存放到map中 + // 将异步通知中收到的所有参数都存放到map中 Map parameterMap = request.getParameterMap(); Map paramsMap = new HashMap<>(); parameterMap.forEach((s, strings) -> paramsMap.put(s, strings[0])); diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/SecurityConfig.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/SecurityConfig.java index 3b27959..3663e2c 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/SecurityConfig.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/SecurityConfig.java @@ -12,6 +12,8 @@ import org.springframework.security.config.annotation.authentication.configurati import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.web.SecurityFilterChain; @@ -38,34 +40,37 @@ public class SecurityConfig { public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception { httpSecurity // cors启用 - .cors().and() + .cors(httpSecurityCorsConfigurer -> { + }) // CSRF(跨站请求伪造)禁用,因为不使用session - .csrf().disable() + .csrf(AbstractHttpConfigurer::disable) // 认证失败处理类 - .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and() + .exceptionHandling(configurer -> configurer.authenticationEntryPoint(unauthorizedHandler)) // 基于token,所以不需要session - .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() + .sessionManagement(configurer -> configurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) // 过滤请求 - .authorizeHttpRequests() - // 对于登录login 验证码captchaImage 允许匿名访问 - .requestMatchers("favicon.ico", "/actuator/**", "/login", "/registry", "/sendEmailCode", "/test/**", "/seckill/**", "/captcha").anonymous() - .requestMatchers("/home/**", "/category/**", "/comment/**", "/goods/detail/**", "/cart/goodsCount", "/diamond/**").permitAll() - .requestMatchers("/upload/**").anonymous() - .requestMatchers("/common/download**").anonymous() - .requestMatchers("/doc.html").anonymous() - .requestMatchers("/swagger-ui/**").anonymous() - .requestMatchers("/swagger-resources/**").anonymous() - .requestMatchers("/webjars/**").anonymous() - .requestMatchers("/*/api-docs").anonymous() - .requestMatchers("/druid/**").anonymous() - .requestMatchers("/message/**").anonymous() - // 除上面外的所有请求全部需要鉴权认证 - .anyRequest().authenticated().and() - .headers().frameOptions().disable(); - httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler); - // 添加JWT filter - httpSecurity.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); - httpSecurity.userDetailsService(userDetailsService); + .authorizeHttpRequests( + registry -> { + registry + .requestMatchers("favicon.ico", "/actuator/**", "/login", "/registry", "/sendEmailCode", "/test/**", "/seckill/**", "/captcha").anonymous() + .requestMatchers("/home/**", "/category/**", "/comment/**", "/goods/detail/**", "/cart/goodsCount", "/diamond/**").permitAll() + .requestMatchers("/upload/**").anonymous() + .requestMatchers("/common/download**").anonymous() + .requestMatchers("/doc.html").anonymous() + .requestMatchers("/swagger-ui/**").anonymous() + .requestMatchers("/swagger-resources/**").anonymous() + .requestMatchers("/webjars/**").anonymous() + .requestMatchers("/*/api-docs").anonymous() + .requestMatchers("/druid/**").anonymous() + .requestMatchers("/message/**").anonymous() + // 除上面外的所有请求全部需要鉴权认证 + .anyRequest().authenticated(); + } + ) + .logout(configurer -> configurer.logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler)) + .headers(configurer -> configurer.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable)) + .addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class) + .userDetailsService(userDetailsService); return httpSecurity.build(); } diff --git a/waynboot-mobile-api/src/main/resources/mapper/SearchHistoryMapper.xml b/waynboot-mobile-api/src/main/resources/mapper/SearchHistoryMapper.xml index b6403d6..681156e 100644 --- a/waynboot-mobile-api/src/main/resources/mapper/SearchHistoryMapper.xml +++ b/waynboot-mobile-api/src/main/resources/mapper/SearchHistoryMapper.xml @@ -17,7 +17,7 @@ select id, - user_id, keyword, from, create_time, has_goods, update_time, del_flag + user_id, keyword from create_time, has_goods, update_time, del_flag from search_history s