From 299a9f1f095a72535ae0ea85c56203f470126c3a Mon Sep 17 00:00:00 2001 From: zhaowy <568452976@qq.com> Date: Thu, 5 Jan 2023 17:36:04 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=AE=A4=E8=AF=81=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95&=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E7=9A=84=E5=BC=82=E5=B8=B8=E6=8A=9B=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/handle/AuthenticationEntryPointImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java index 9d86feab2..db2c077b3 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java @@ -4,6 +4,9 @@ import java.io.IOException; import java.io.Serializable; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; @@ -15,20 +18,21 @@ import com.ruoyi.common.utils.StringUtils; /** * 认证失败处理类 返回未授权 - * + * * @author ruoyi */ @Component public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, Serializable { private static final long serialVersionUID = -8970718410437077606L; + private Logger logger = LoggerFactory.getLogger(getClass()); @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) - throws IOException { int code = HttpStatus.UNAUTHORIZED; String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI()); + logger.info(msg); ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg))); } } -- Gitee From cf03fd16c2597a47e8b504194a6ce5429109af8d Mon Sep 17 00:00:00 2001 From: zhaowy <568452976@qq.com> Date: Thu, 5 Jan 2023 17:37:23 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=B9=B4=E6=9C=88=E6=97=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-admin/src/main/resources/logback.xml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ruoyi-admin/src/main/resources/logback.xml b/ruoyi-admin/src/main/resources/logback.xml index d69a57207..3174b21fb 100644 --- a/ruoyi-admin/src/main/resources/logback.xml +++ b/ruoyi-admin/src/main/resources/logback.xml @@ -3,7 +3,7 @@ - + @@ -11,7 +11,7 @@ ${log.pattern} - + ${log.path}/sys-info.log @@ -34,7 +34,7 @@ DENY - + ${log.path}/sys-error.log @@ -56,7 +56,7 @@ DENY - + ${log.path}/sys-user.log @@ -70,7 +70,7 @@ ${log.pattern} - + @@ -79,15 +79,15 @@ - + - + - \ No newline at end of file + -- Gitee From af585e14d8752333a6337fe36a684c988797681a Mon Sep 17 00:00:00 2001 From: zhaowy <568452976@qq.com> Date: Thu, 5 Jan 2023 18:37:34 +0800 Subject: [PATCH 3/3] =?UTF-8?q?knife4j=20=E9=9B=86=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-admin/pom.xml | 20 ++++++++----- .../src/main/resources/application.yml | 18 +++++++---- .../framework/config/SecurityConfig.java | 8 ++--- .../framework/web/service/TokenService.java | 7 +++++ ruoyi-ui/src/views/tool/swagger/index.vue | 30 +++++++++---------- 5 files changed, 51 insertions(+), 32 deletions(-) diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index 9a4cde8fb..4546b7389 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -37,6 +37,12 @@ 1.6.2 + + com.github.xiaoymin + knife4j-spring-boot-starter + 2.0.9 + + mysql @@ -80,17 +86,17 @@ - - org.apache.maven.plugins - maven-war-plugin - 3.1.0 + + org.apache.maven.plugins + maven-war-plugin + 3.1.0 false ${project.artifactId} - - + + ${project.artifactId} - \ No newline at end of file + diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index acb28b421..0c5b6cfba 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -53,7 +53,7 @@ spring: messages: # 国际化资源文件路径 basename: i18n/messages - profiles: + profiles: active: druid # 文件上传 servlet: @@ -76,7 +76,7 @@ spring: # 数据库索引 database: 0 # 密码 - password: + password: # 连接超时时间 timeout: 10s lettuce: @@ -98,7 +98,7 @@ token: secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 30 - + # MyBatis配置 mybatis: # 搜索指定包别名 @@ -109,10 +109,16 @@ mybatis: configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 -pagehelper: +pagehelper: helperDialect: mysql supportMethodsArguments: true - params: count=countSql + params: count=countSql + +# knife4j的增强配置 +knife4j: + enable: true + setting: + language: zh_cn # Swagger配置 swagger: @@ -122,7 +128,7 @@ swagger: pathMapping: /dev-api # 防止XSS攻击 -xss: +xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index bdb7199fe..5557e560d 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -22,7 +22,7 @@ import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl; /** * spring security配置 - * + * * @author ruoyi */ @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) @@ -33,7 +33,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter */ @Autowired private UserDetailsService userDetailsService; - + /** * 认证失败处理类 */ @@ -51,7 +51,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter */ @Autowired private JwtAuthenticationTokenFilter authenticationTokenFilter; - + /** * 跨域过滤器 */ @@ -114,7 +114,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter .antMatchers("/login", "/register", "/captchaImage").permitAll() // 静态资源,可匿名访问 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() - .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() + .antMatchers("/doc.html", "/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated() .and() diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java index cadeb4e37..4c499188c 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java @@ -4,6 +4,9 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpServletRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -50,6 +53,8 @@ public class TokenService @Autowired private RedisCache redisCache; + private Logger logger = LoggerFactory.getLogger(getClass()); + /** * 获取用户身份信息 * @@ -72,8 +77,10 @@ public class TokenService } catch (Exception e) { + logger.info("token:{}已过期或不合法", token); } } + logger.info("token:{} 为空", token); return null; } diff --git a/ruoyi-ui/src/views/tool/swagger/index.vue b/ruoyi-ui/src/views/tool/swagger/index.vue index 750189115..b78296878 100644 --- a/ruoyi-ui/src/views/tool/swagger/index.vue +++ b/ruoyi-ui/src/views/tool/swagger/index.vue @@ -1,15 +1,15 @@ - - + + -- Gitee