From 281a958d4a86731db52195bb5078fa072d09cd74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Miller=20=28=E9=94=BA=E4=BF=8A=29?= Date: Tue, 22 Dec 2020 11:43:30 +0800 Subject: [PATCH] perf($Gateway): refine access log --- .../JwtReactiveAuthenticationManager.java | 6 +++--- ...JwtReactiveServerSecurityContextRepository.java | 2 +- .../RbacReactiveAuthorizationManager.java | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/gateway/src/main/java/com/jmsoftware/maf/gateway/universal/configuration/JwtReactiveAuthenticationManager.java b/gateway/src/main/java/com/jmsoftware/maf/gateway/universal/configuration/JwtReactiveAuthenticationManager.java index 4424a6ce..899dba4a 100644 --- a/gateway/src/main/java/com/jmsoftware/maf/gateway/universal/configuration/JwtReactiveAuthenticationManager.java +++ b/gateway/src/main/java/com/jmsoftware/maf/gateway/universal/configuration/JwtReactiveAuthenticationManager.java @@ -38,16 +38,16 @@ public Mono authenticate(Authentication authentication) { try { username = jwtService.getUsernameFromJwt(jwt); } catch (Exception e) { - log.error("Authentication failed! Cause: {}", e.getMessage()); + log.error("Authentication failure! Cause: {}", e.getMessage()); return Mono.empty(); } if (StrUtil.isBlank(username)) { - log.warn("Authentication failed! Cause: the username mustn't be blank"); + log.warn("Authentication failure! Cause: the username mustn't be blank"); return Mono.empty(); } val response = authCenterRemoteApi.getUserByLoginToken(username); Mono responseMono = response.map(ResponseBodyBean::getData) - .switchIfEmpty(Mono.error(new BusinessException("Authentication failed! Cause: User not found"))); + .switchIfEmpty(Mono.error(new BusinessException("Authentication failure! Cause: User not found"))); return responseMono.map(getUserByLoginTokenResponse -> { log.info("Authentication success! Found username: {}", getUserByLoginTokenResponse.getUsername()); UserPrincipal userPrincipal = UserPrincipal.create(getUserByLoginTokenResponse, null, null); diff --git a/gateway/src/main/java/com/jmsoftware/maf/gateway/universal/configuration/JwtReactiveServerSecurityContextRepository.java b/gateway/src/main/java/com/jmsoftware/maf/gateway/universal/configuration/JwtReactiveServerSecurityContextRepository.java index eb84a410..77774a8d 100644 --- a/gateway/src/main/java/com/jmsoftware/maf/gateway/universal/configuration/JwtReactiveServerSecurityContextRepository.java +++ b/gateway/src/main/java/com/jmsoftware/maf/gateway/universal/configuration/JwtReactiveServerSecurityContextRepository.java @@ -45,7 +45,7 @@ public Mono load(ServerWebExchange exchange) { } String authorization = request.getHeaders().getFirst(HttpHeaders.AUTHORIZATION); if (StrUtil.isBlank(authorization) || !authorization.startsWith(JwtConfiguration.TOKEN_PREFIX)) { - log.warn("Authentication failed! Cause: `{}` in HTTP headers not found. Request URL: [{}] {}", + log.warn("Authentication failure! Cause: `{}` in HTTP headers not found. Request URL: [{}] {}", HttpHeaders.AUTHORIZATION, request.getMethod(), request.getURI()); return Mono.empty(); } diff --git a/gateway/src/main/java/com/jmsoftware/maf/gateway/universal/configuration/RbacReactiveAuthorizationManager.java b/gateway/src/main/java/com/jmsoftware/maf/gateway/universal/configuration/RbacReactiveAuthorizationManager.java index dbe578ac..9821d454 100644 --- a/gateway/src/main/java/com/jmsoftware/maf/gateway/universal/configuration/RbacReactiveAuthorizationManager.java +++ b/gateway/src/main/java/com/jmsoftware/maf/gateway/universal/configuration/RbacReactiveAuthorizationManager.java @@ -48,24 +48,24 @@ public Mono check(Mono authentication, Au .switchIfEmpty(Mono.error(new BusinessException("User not found!"))); }); val zip = Mono.zip(getPermissionListByUserIdResponseMono, userPrincipalMono); - return zip.map(objects -> { - val permissionList = objects.getT1().getPermissionList(); + return zip.map(mapper -> { + val permissionList = mapper.getT1().getPermissionList(); val buttonPermissionList = permissionList.stream() .filter(permission -> PermissionType.BUTTON.getType().equals(permission.getType())) .filter(permission -> StrUtil.isNotBlank(permission.getUrl())) .filter(permission -> StrUtil.isNotBlank(permission.getMethod())) .collect(Collectors.toList()); val path = request.getURI().getPath(); - val userPrincipal = objects.getT2(); + val userPrincipal = mapper.getT2(); for (val buttonPermission : buttonPermissionList) { if (antPathMatcher.match(buttonPermission.getUrl(), path)) { - log.info("Resource [{}] {} is accessible for user(username: {})", request.getMethod(), - request.getURI(), userPrincipal.getUsername()); + log.info("Authorization success! Resource [{}] {} is accessible for user(username: {})", + request.getMethod(), request.getURI(), userPrincipal.getUsername()); return new AuthorizationDecision(true); } } - log.warn("Resource [{}] {} is inaccessible for user(username: {})", request.getMethod(), - request.getURI(), userPrincipal.getUsername()); + log.warn("Authorization failure! Resource [{}] {} is inaccessible for user(username: {})", + request.getMethod(), request.getURI(), userPrincipal.getUsername()); return new AuthorizationDecision(false); }); }