Procházet zdrojové kódy

fix: 修复了日志中显示权限不正确的问题,优化了日志措辞,暂停了对非法访问的记录

刘一也 před 4 roky
rodič
revize
c134aedcf8

+ 2 - 2
src/main/java/cn/seecoder/devmanage/log/LocalLogger.java

@@ -55,9 +55,9 @@ public class LocalLogger {
             currentUser = (String) authentication.getPrincipal();
             Iterator<? extends GrantedAuthority> iterator = authentication.getAuthorities().iterator();
             if (iterator.hasNext()) {
-                authority = "Unauthorized";
-            } else {
                 authority = iterator.next().toString();
+            } else {
+                authority = "Unauthorized";
             }
         }
         LocalLog localLog = new LocalLog(currentUser, authority, message, System.currentTimeMillis(), success);

+ 2 - 2
src/main/java/cn/seecoder/devmanage/security/JwtAuthenticationFilter.java

@@ -68,7 +68,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
                 filterChain.doFilter(request, response);
             } catch (JWTDecodeException | SignatureVerificationException | TokenExpiredException e) {
                 log.error("Error JWT parsing: {}", e.getMessage());
-                localLogger.recordFailure(String.format("Invalid JWT from %s: %s (JWT: %s)", clientIpAddress, e.getMessage(), authorizationHeader));
+//                localLogger.recordFailure(String.format("Invalid JWT from %s: %s (JWT: %s)", clientIpAddress, e.getMessage(), authorizationHeader));
                 response.setStatus(FORBIDDEN.value());
                 response.setContentType(APPLICATION_JSON_VALUE);
                 new ObjectMapper().writeValue(response.getOutputStream(),
@@ -76,7 +76,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
             }
         } else {
             log.error("Request lacks Authorization header.");
-            localLogger.recordFailure(String.format("Request from %s lacks Authorization header.", clientIpAddress));
+//            localLogger.recordFailure(String.format("Request from %s lacks Authorization header.", clientIpAddress));
             response.setStatus(FORBIDDEN.value());
             response.setContentType(APPLICATION_JSON_VALUE);
             new ObjectMapper().writeValue(response.getOutputStream(),

+ 1 - 1
src/main/java/cn/seecoder/devmanage/service/impl/LimitRequestServiceImpl.java

@@ -144,7 +144,7 @@ public class LimitRequestServiceImpl implements LimitRequestService {
             String name = limitRequest.getName();
             List<LimitRange> limitRanges = limitRangeService.getLimitRanges(namespace, name);
             if (limitRanges == null || limitRanges.isEmpty()) {
-                localLogger.recordFailure(String.format("Targeted LimitRange of LimitRequest %s doest not exist, thus" +
+                localLogger.recordFailure(String.format("Targeted LimitRange of id %s doest not exist, thus" +
                         " did nothing.", limitRequestId));
                 return false;
             } else {