From 3fe6e8b267a5d79dec39642f9f5d0af7c482dd97 Mon Sep 17 00:00:00 2001 From: Andrew DeMaria Date: Tue, 8 Oct 2019 00:28:22 -0600 Subject: [PATCH] Add logger name checkstyle Signed-off-by: Andrew DeMaria --- .../player/controller/HelpController.java | 4 ++-- .../org/airsonic/player/dao/MediaFileDao.java | 6 +++--- .../CustomUserDetailsContextMapper.java | 6 +++--- .../player/security/GlobalSecurityConfig.java | 10 +++++----- .../security/JWTAuthenticationProvider.java | 16 +++++++-------- .../JWTRequestParameterProcessingFilter.java | 20 +++++++++---------- .../player/service/JWTSecurityService.java | 4 ++-- .../upnp/DispatchingContentDirectory.java | 2 +- .../RegisterPrecompiledJSPInitializer.java | 10 +++++----- .../player/spring/SpringLiquibase.java | 16 +++++++-------- checkstyle.xml | 1 + pom.xml | 7 +++++++ 12 files changed, 55 insertions(+), 47 deletions(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/controller/HelpController.java b/airsonic-main/src/main/java/org/airsonic/player/controller/HelpController.java index 784ed935..44d967cb 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/controller/HelpController.java +++ b/airsonic-main/src/main/java/org/airsonic/player/controller/HelpController.java @@ -50,7 +50,7 @@ import java.util.Map; @RequestMapping("/help") public class HelpController { - private static final Logger logger = LoggerFactory.getLogger(HelpController.class); + private static final Logger LOG = LoggerFactory.getLogger(HelpController.class); private static final int LOG_LINES_TO_SHOW = 50; @@ -109,7 +109,7 @@ public class HelpController { } return lines; } catch (Exception e) { - logger.warn("Could not open log file " + logFile, e); + LOG.warn("Could not open log file " + logFile, e); return null; } } diff --git a/airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java b/airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java index ec85de9a..ef2a6c6a 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java +++ b/airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java @@ -42,7 +42,7 @@ import java.util.*; */ @Repository public class MediaFileDao extends AbstractDao { - private static final Logger logger = LoggerFactory.getLogger(MediaFileDao.class); + private static final Logger LOG = LoggerFactory.getLogger(MediaFileDao.class); private static final String INSERT_COLUMNS = "path, folder, type, format, title, album, artist, album_artist, disc_number, " + "track_number, year, genre, bit_rate, variable_bit_rate, duration_seconds, file_size, width, height, cover_art_path, " + "parent_path, play_count, last_played, comment, created, changed, last_scanned, children_last_updated, present, " + @@ -133,7 +133,7 @@ public class MediaFileDao extends AbstractDao { */ @Transactional public void createOrUpdateMediaFile(MediaFile file) { - logger.trace("Creating/Updating new media file at {}", file.getPath()); + LOG.trace("Creating/Updating new media file at {}", file.getPath()); String sql = "update media_file set " + "folder=?," + "type=?," + @@ -165,7 +165,7 @@ public class MediaFileDao extends AbstractDao { "mb_release_id=? " + "where path=?"; - logger.trace("Updating media file {}", Util.debugObject(file)); + LOG.trace("Updating media file {}", Util.debugObject(file)); int n = update(sql, file.getFolder(), file.getMediaType().name(), file.getFormat(), file.getTitle(), file.getAlbumName(), file.getArtist(), diff --git a/airsonic-main/src/main/java/org/airsonic/player/security/CustomUserDetailsContextMapper.java b/airsonic-main/src/main/java/org/airsonic/player/security/CustomUserDetailsContextMapper.java index 6bfa0582..05d8482e 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/security/CustomUserDetailsContextMapper.java +++ b/airsonic-main/src/main/java/org/airsonic/player/security/CustomUserDetailsContextMapper.java @@ -40,7 +40,7 @@ public class CustomUserDetailsContextMapper implements UserDetailsContextMapper // ~ Instance fields // ================================================================================================ - private final Logger logger = LoggerFactory.getLogger(CustomUserDetailsContextMapper.class); + private static final Logger LOG = LoggerFactory.getLogger(CustomUserDetailsContextMapper.class); private String passwordAttributeName = "userPassword"; @Autowired @@ -56,7 +56,7 @@ public class CustomUserDetailsContextMapper implements UserDetailsContextMapper Collection authorities) { String dn = ctx.getNameInNamespace(); - logger.debug("Mapping user details from context with DN: " + dn); + LOG.debug("Mapping user details from context with DN: " + dn); // User must be defined in Airsonic, unless auto-shadowing is enabled. User user = securityService.getUserByName(username, false); @@ -69,7 +69,7 @@ public class CustomUserDetailsContextMapper implements UserDetailsContextMapper newUser.setStreamRole(true); newUser.setSettingsRole(true); securityService.createUser(newUser); - logger.info("Created local user '" + username + "' for DN " + dn); + LOG.info("Created local user '" + username + "' for DN " + dn); user = securityService.getUserByName(username, false); } diff --git a/airsonic-main/src/main/java/org/airsonic/player/security/GlobalSecurityConfig.java b/airsonic-main/src/main/java/org/airsonic/player/security/GlobalSecurityConfig.java index 5ff458a5..6d0cc3d6 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/security/GlobalSecurityConfig.java +++ b/airsonic-main/src/main/java/org/airsonic/player/security/GlobalSecurityConfig.java @@ -29,7 +29,7 @@ import java.security.SecureRandom; @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) public class GlobalSecurityConfig extends GlobalAuthenticationConfigurerAdapter { - private static Logger logger = LoggerFactory.getLogger(GlobalSecurityConfig.class); + private static final Logger LOG = LoggerFactory.getLogger(GlobalSecurityConfig.class); static final String FAILURE_URL = "/login?error=1"; @@ -65,7 +65,7 @@ public class GlobalSecurityConfig extends GlobalAuthenticationConfigurerAdapter auth.userDetailsService(securityService); String jwtKey = settingsService.getJWTKey(); if (StringUtils.isBlank(jwtKey)) { - logger.warn("Generating new jwt key"); + LOG.warn("Generating new jwt key"); jwtKey = JWTSecurityService.generateKey(); settingsService.setJWTKey(jwtKey); settingsService.save(); @@ -142,15 +142,15 @@ public class GlobalSecurityConfig extends GlobalAuthenticationConfigurerAdapter boolean development = SettingsService.isDevelopmentMode(); if (StringUtils.isBlank(rememberMeKey) && !development) { // ...if it is empty, generate a random key on startup (default). - logger.debug("Generating a new ephemeral 'remember me' key in a secure way."); + LOG.debug("Generating a new ephemeral 'remember me' key in a secure way."); rememberMeKey = generateRememberMeKey(); } else if (StringUtils.isBlank(rememberMeKey) && development) { // ...if we are in development mode, we can use a fixed key. - logger.warn("Using a fixed 'remember me' key because we're in development mode, this is INSECURE."); + LOG.warn("Using a fixed 'remember me' key because we're in development mode, this is INSECURE."); rememberMeKey = DEVELOPMENT_REMEMBER_ME_KEY; } else { // ...otherwise, use the custom key directly. - logger.info("Using a fixed 'remember me' key from system properties, this is insecure."); + LOG.info("Using a fixed 'remember me' key from system properties, this is insecure."); } http diff --git a/airsonic-main/src/main/java/org/airsonic/player/security/JWTAuthenticationProvider.java b/airsonic-main/src/main/java/org/airsonic/player/security/JWTAuthenticationProvider.java index 3240b6d1..1af12a7d 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/security/JWTAuthenticationProvider.java +++ b/airsonic-main/src/main/java/org/airsonic/player/security/JWTAuthenticationProvider.java @@ -23,7 +23,7 @@ import java.util.Objects; public class JWTAuthenticationProvider implements AuthenticationProvider { - private static final Logger logger = LoggerFactory.getLogger(JWTAuthenticationProvider.class); + private static final Logger LOG = LoggerFactory.getLogger(JWTAuthenticationProvider.class); private final String jwtKey; @@ -35,7 +35,7 @@ public class JWTAuthenticationProvider implements AuthenticationProvider { public Authentication authenticate(Authentication auth) throws AuthenticationException { JWTAuthenticationToken authentication = (JWTAuthenticationToken) auth; if (authentication.getCredentials() == null || !(authentication.getCredentials() instanceof String)) { - logger.error("Credentials not present"); + LOG.error("Credentials not present"); return null; } String rawToken = (String) auth.getCredentials(); @@ -45,7 +45,7 @@ public class JWTAuthenticationProvider implements AuthenticationProvider { // TODO:AD This is super unfortunate, but not sure there is a better way when using JSP if (StringUtils.contains(authentication.getRequestedPath(), "/WEB-INF/jsp/")) { - logger.warn("BYPASSING AUTH FOR WEB-INF page"); + LOG.warn("BYPASSING AUTH FOR WEB-INF page"); } else if (!roughlyEqual(path.asString(), authentication.getRequestedPath())) { throw new InsufficientAuthenticationException("Credentials not valid for path " + authentication .getRequestedPath() + ". They are valid for " + path.asString()); @@ -58,9 +58,9 @@ public class JWTAuthenticationProvider implements AuthenticationProvider { } private static boolean roughlyEqual(String expectedRaw, String requestedPathRaw) { - logger.debug("Comparing expected [{}] vs requested [{}]", expectedRaw, requestedPathRaw); + LOG.debug("Comparing expected [{}] vs requested [{}]", expectedRaw, requestedPathRaw); if (StringUtils.isEmpty(expectedRaw)) { - logger.debug("False: empty expected"); + LOG.debug("False: empty expected"); return false; } try { @@ -68,7 +68,7 @@ public class JWTAuthenticationProvider implements AuthenticationProvider { UriComponents requested = UriComponentsBuilder.fromUriString(requestedPathRaw).build(); if (!Objects.equals(expected.getPath(), requested.getPath())) { - logger.debug("False: expected path [{}] does not match requested path [{}]", + LOG.debug("False: expected path [{}] does not match requested path [{}]", expected.getPath(), requested.getPath()); return false; } @@ -80,12 +80,12 @@ public class JWTAuthenticationProvider implements AuthenticationProvider { !difference.entriesOnlyOnLeft().isEmpty() || difference.entriesOnlyOnRight().size() != 1 || difference.entriesOnlyOnRight().get(JWTSecurityService.JWT_PARAM_NAME) == null) { - logger.debug("False: expected query params [{}] do not match requested query params [{}]", expected.getQueryParams(), requested.getQueryParams()); + LOG.debug("False: expected query params [{}] do not match requested query params [{}]", expected.getQueryParams(), requested.getQueryParams()); return false; } } catch (Exception e) { - logger.warn("Exception encountered while comparing paths", e); + LOG.warn("Exception encountered while comparing paths", e); return false; } return true; diff --git a/airsonic-main/src/main/java/org/airsonic/player/security/JWTRequestParameterProcessingFilter.java b/airsonic-main/src/main/java/org/airsonic/player/security/JWTRequestParameterProcessingFilter.java index faf59f68..6cc9971a 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/security/JWTRequestParameterProcessingFilter.java +++ b/airsonic-main/src/main/java/org/airsonic/player/security/JWTRequestParameterProcessingFilter.java @@ -22,7 +22,7 @@ import java.io.IOException; import java.util.Optional; public class JWTRequestParameterProcessingFilter implements Filter { - private static final Logger logger = LoggerFactory.getLogger(JWTRequestParameterProcessingFilter.class); + private static final Logger LOG = LoggerFactory.getLogger(JWTRequestParameterProcessingFilter.class); private final AuthenticationManager authenticationManager; private final AuthenticationFailureHandler failureHandler; @@ -63,8 +63,8 @@ public class JWTRequestParameterProcessingFilter implements Filter { return; } - if (logger.isDebugEnabled()) { - logger.debug("Request is to process authentication"); + if (LOG.isDebugEnabled()) { + LOG.debug("Request is to process authentication"); } Authentication authResult; @@ -78,7 +78,7 @@ public class JWTRequestParameterProcessingFilter implements Filter { } } catch (InternalAuthenticationServiceException failed) { - logger.error( + LOG.error( "An internal error occurred while trying to authenticate the user.", failed); unsuccessfulAuthentication(request, response, failed); @@ -92,8 +92,8 @@ public class JWTRequestParameterProcessingFilter implements Filter { return; } - if (logger.isDebugEnabled()) { - logger.debug("Authentication success. Updating SecurityContextHolder to contain: " + if (LOG.isDebugEnabled()) { + LOG.debug("Authentication success. Updating SecurityContextHolder to contain: " + authResult); } @@ -107,10 +107,10 @@ public class JWTRequestParameterProcessingFilter implements Filter { throws IOException, ServletException { SecurityContextHolder.clearContext(); - if (logger.isDebugEnabled()) { - logger.debug("Authentication request failed: " + failed.toString(), failed); - logger.debug("Updated SecurityContextHolder to contain null Authentication"); - logger.debug("Delegating to authentication failure handler " + failureHandler); + if (LOG.isDebugEnabled()) { + LOG.debug("Authentication request failed: " + failed.toString(), failed); + LOG.debug("Updated SecurityContextHolder to contain null Authentication"); + LOG.debug("Delegating to authentication failure handler " + failureHandler); } failureHandler.onAuthenticationFailure(request, response, failed); diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/JWTSecurityService.java b/airsonic-main/src/main/java/org/airsonic/player/service/JWTSecurityService.java index 935a2d87..278f1cb9 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/JWTSecurityService.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/JWTSecurityService.java @@ -19,7 +19,7 @@ import java.util.Date; @Service("jwtSecurityService") public class JWTSecurityService { - private static final Logger logger = LoggerFactory.getLogger(JWTSecurityService.class); + private static final Logger LOG = LoggerFactory.getLogger(JWTSecurityService.class); public static final String JWT_PARAM_NAME = "jwt"; public static final String CLAIM_PATH = "path"; @@ -47,7 +47,7 @@ public class JWTSecurityService { UriComponents components = UriComponentsBuilder.fromUriString(path).build(); String query = components.getQuery(); String claim = components.getPath() + (!StringUtils.isBlank(query) ? "?" + components.getQuery() : ""); - logger.debug("Creating token with claim " + claim); + LOG.debug("Creating token with claim " + claim); return JWT.create() .withClaim(CLAIM_PATH, claim) .withExpiresAt(expireDate) diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/upnp/DispatchingContentDirectory.java b/airsonic-main/src/main/java/org/airsonic/player/service/upnp/DispatchingContentDirectory.java index 10cbb4fc..52bce732 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/upnp/DispatchingContentDirectory.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/upnp/DispatchingContentDirectory.java @@ -44,7 +44,7 @@ import java.util.Arrays; @Service public class DispatchingContentDirectory extends CustomContentDirectory { - public static final Logger LOG = LoggerFactory.getLogger(DispatchingContentDirectory.class); + private static final Logger LOG = LoggerFactory.getLogger(DispatchingContentDirectory.class); public static final String CONTAINER_ID_ROOT = "0"; public static final String CONTAINER_ID_PLAYLIST_PREFIX = "playlist"; diff --git a/airsonic-main/src/main/java/org/airsonic/player/spring/RegisterPrecompiledJSPInitializer.java b/airsonic-main/src/main/java/org/airsonic/player/spring/RegisterPrecompiledJSPInitializer.java index 835d38ab..81e5e4c2 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/spring/RegisterPrecompiledJSPInitializer.java +++ b/airsonic-main/src/main/java/org/airsonic/player/spring/RegisterPrecompiledJSPInitializer.java @@ -24,14 +24,14 @@ import java.nio.charset.Charset; @Component public class RegisterPrecompiledJSPInitializer implements ServletContextInitializer { - private static final Logger logger = LoggerFactory.getLogger(RegisterPrecompiledJSPInitializer.class); + private static final Logger LOG = LoggerFactory.getLogger(RegisterPrecompiledJSPInitializer.class); @Override public void onStartup(ServletContext servletContext) { if (SettingsService.isDevelopmentMode()) { - logger.debug("Not registering precompiled jsps"); + LOG.debug("Not registering precompiled jsps"); } else { - logger.debug("Registering precompiled jsps"); + LOG.debug("Registering precompiled jsps"); registerPrecompiledJSPs(servletContext); } } @@ -39,14 +39,14 @@ public class RegisterPrecompiledJSPInitializer implements ServletContextInitiali private static void registerPrecompiledJSPs(ServletContext servletContext) { WebApp webApp = parseXmlFragment(); for (ServletDef def : webApp.getServletDefs()) { - logger.trace("Registering precompiled JSP: {} -> {}", def.getName(), def.getSclass()); + LOG.trace("Registering precompiled JSP: {} -> {}", def.getName(), def.getSclass()); ServletRegistration.Dynamic reg = servletContext.addServlet(def.getName(), def.getSclass()); // Need to set loadOnStartup somewhere between 0 and 128. 0 is highest priority. 99 should be fine reg.setLoadOnStartup(99); } for (ServletMappingDef mapping : webApp.getServletMappingDefs()) { - logger.trace("Mapping servlet: {} -> {}", mapping.getName(), mapping.getUrlPattern()); + LOG.trace("Mapping servlet: {} -> {}", mapping.getName(), mapping.getUrlPattern()); servletContext.getServletRegistration(mapping.getName()).addMapping(mapping.getUrlPattern()); } } diff --git a/airsonic-main/src/main/java/org/airsonic/player/spring/SpringLiquibase.java b/airsonic-main/src/main/java/org/airsonic/player/spring/SpringLiquibase.java index 59d14dd3..ac84a0cb 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/spring/SpringLiquibase.java +++ b/airsonic-main/src/main/java/org/airsonic/player/spring/SpringLiquibase.java @@ -16,20 +16,20 @@ import java.sql.Connection; import java.util.List; public class SpringLiquibase extends liquibase.integration.spring.SpringLiquibase { - private static final Logger logger = LoggerFactory.getLogger(SpringLiquibase.class); + private static final Logger LOG = LoggerFactory.getLogger(SpringLiquibase.class); @Override public void afterPropertiesSet() throws LiquibaseException { - logger.trace("Starting Liquibase Update"); + LOG.trace("Starting Liquibase Update"); try { super.afterPropertiesSet(); } catch (Exception e) { - logger.error("==============================================="); - logger.error("An exception occurred during database migration"); - logger.error("A rollback file has been generated at " + rollbackFile); - logger.error("Execute it within your database to rollback any changes"); - logger.error("The exception is as follows\n", e); - logger.error("==============================================="); + LOG.error("==============================================="); + LOG.error("An exception occurred during database migration"); + LOG.error("A rollback file has been generated at " + rollbackFile); + LOG.error("Execute it within your database to rollback any changes"); + LOG.error("The exception is as follows\n", e); + LOG.error("==============================================="); throw(e); } } diff --git a/checkstyle.xml b/checkstyle.xml index 0eafb727..73902dd7 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -64,6 +64,7 @@ + diff --git a/pom.xml b/pom.xml index b50d50cb..f0c5e8c9 100644 --- a/pom.xml +++ b/pom.xml @@ -255,6 +255,13 @@ + + + org.airsonic + checkstyle + 1.0-RELEASE + + org.owasp