From e1b3d1a7a5f430c4ecb8649367bc61973d8c0716 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak <9051964+DuMaM@users.noreply.github.com> Date: Sun, 24 Apr 2022 23:42:52 +0200 Subject: [PATCH] Remove reported form SonarCode code smells (#67) --- .../crowd/CrowdAuthenticationManager.java | 4 +--- .../crowd/CrowdAuthenticationToken.java | 10 ---------- .../crowd/CrowdConfigurationService.java | 2 +- .../crowd/CrowdRememberMeServices.java | 2 +- .../jenkins/crowd/CrowdSecurityRealm.java | 19 ++++++++++++------- .../crowd/CrowdUserDetailsService.java | 2 +- .../de/theit/jenkins/crowd/ErrorMessages.java | 6 +++--- 7 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/main/java/de/theit/jenkins/crowd/CrowdAuthenticationManager.java b/src/main/java/de/theit/jenkins/crowd/CrowdAuthenticationManager.java index 83db6e29..721ef4b7 100644 --- a/src/main/java/de/theit/jenkins/crowd/CrowdAuthenticationManager.java +++ b/src/main/java/de/theit/jenkins/crowd/CrowdAuthenticationManager.java @@ -115,7 +115,6 @@ public Authentication authenticate(Authentication authentication) username, this.configuration.getAllowedGroupNames())); } - // String displayName = null; try { // authenticate user if (LOG.isLoggable(Level.FINE)) { @@ -124,7 +123,6 @@ public Authentication authenticate(Authentication authentication) User user = this.configuration.authenticateUser( username, password); CrowdAuthenticationToken.updateUserInfo(user); - // displayName = user.getDisplayName(); } catch (UserNotFoundException ex) { if (LOG.isLoggable(Level.INFO)) { LOG.info(userNotFound(username)); @@ -152,7 +150,7 @@ public Authentication authenticate(Authentication authentication) // user successfully authenticated // => retrieve the list of groups the user is a member of - List authorities = new ArrayList(); + List authorities = new ArrayList<>(); // add the "authenticated" authority to the list of granted // authorities... diff --git a/src/main/java/de/theit/jenkins/crowd/CrowdAuthenticationToken.java b/src/main/java/de/theit/jenkins/crowd/CrowdAuthenticationToken.java index ca3565f7..d6b1f213 100644 --- a/src/main/java/de/theit/jenkins/crowd/CrowdAuthenticationToken.java +++ b/src/main/java/de/theit/jenkins/crowd/CrowdAuthenticationToken.java @@ -105,16 +105,6 @@ public String getSSOToken() { return this.ssoToken; } - /** - * {@inheritDoc} - * - * @see org.springframework.security.authentication.AbstractAuthenticationToken#getName() - */ - @Override - public String getName() { - return super.getName(); - } - public static void updateUserInfo(com.atlassian.crowd.model.user.User user) { final String displayName = user == null ? null : user.getDisplayName(); if (StringUtils.isNotBlank(displayName)) { diff --git a/src/main/java/de/theit/jenkins/crowd/CrowdConfigurationService.java b/src/main/java/de/theit/jenkins/crowd/CrowdConfigurationService.java index 0c8431de..69c61e69 100644 --- a/src/main/java/de/theit/jenkins/crowd/CrowdConfigurationService.java +++ b/src/main/java/de/theit/jenkins/crowd/CrowdConfigurationService.java @@ -221,7 +221,7 @@ public CrowdConfigurationService(String url, String applicationName, Secret pass this.tokenHelper); } - public ArrayList getAllowedGroupNames() { + public List getAllowedGroupNames() { return allowedGroupNames; } diff --git a/src/main/java/de/theit/jenkins/crowd/CrowdRememberMeServices.java b/src/main/java/de/theit/jenkins/crowd/CrowdRememberMeServices.java index c5f1f8cb..ed393034 100644 --- a/src/main/java/de/theit/jenkins/crowd/CrowdRememberMeServices.java +++ b/src/main/java/de/theit/jenkins/crowd/CrowdRememberMeServices.java @@ -125,7 +125,7 @@ public Authentication autoLogin(HttpServletRequest request, // user is authenticated and validated // => create the user object and finalize the auto-login // process - List authorities = new ArrayList(); + List authorities = new ArrayList<>(); authorities.add(SecurityRealm.AUTHENTICATED_AUTHORITY2); authorities.addAll(this.configuration.getAuthoritiesForUser(user.getName())); result = new CrowdAuthenticationToken(user.getName(), null, authorities, ssoToken); diff --git a/src/main/java/de/theit/jenkins/crowd/CrowdSecurityRealm.java b/src/main/java/de/theit/jenkins/crowd/CrowdSecurityRealm.java index ba61559e..7110c7b2 100644 --- a/src/main/java/de/theit/jenkins/crowd/CrowdSecurityRealm.java +++ b/src/main/java/de/theit/jenkins/crowd/CrowdSecurityRealm.java @@ -147,7 +147,7 @@ public class CrowdSecurityRealm extends AbstractPasswordBasedSecurityRealm { * The configuration data necessary for accessing the services on the remote * Crowd server. */ - transient private CrowdConfigurationService configuration; + private transient CrowdConfigurationService configuration; /** * Default constructor. Fields in config.jelly must match the parameter @@ -326,7 +326,7 @@ private void initializeConfiguration() { /** * {@inheritDoc} * - * @see hudson.security.SecurityRealm#createSecurityComponents() + * @see hudson.security.AbstractPasswordBasedSecurityRealm#createSecurityComponents() */ @Override public SecurityComponents createSecurityComponents() { @@ -390,6 +390,7 @@ public Filter createFilter(FilterConfig filterConfig) { /** * {@inheritDoc} * + * @deprecated use {@link #loadUserByUsername2} * @see hudson.security.AbstractPasswordBasedSecurityRealm#loadUserByUsername(java.lang.String) */ @Override @@ -400,10 +401,15 @@ public org.acegisecurity.userdetails.UserDetails loadUserByUsername(String usern return getSecurityComponents().userDetails.loadUserByUsername(username); } + // TODO: Implement missing loadGroupByGroupname2 /** + * {@inheritDoc} + * * @deprecated use {@link #loadGroupByGroupname2} * @since 1.549 + * @see hudson.security.SecurityRealm#loadGroupByGroupname(java.lang.String) */ + @Override @Deprecated public GroupDetails loadGroupByGroupname(String groupname, boolean fetchMembers) throws org.acegisecurity.userdetails.UsernameNotFoundException, org.springframework.dao.DataAccessException { try { @@ -426,7 +432,8 @@ public UserDetails loadUserByUsername2(String username) throws UsernameNotFoundE /** * {@inheritDoc} * - * @see hudson.security.SecurityRealm#loadGroupByGroupname(java.lang.String) + * @deprecated use {@link #loadGroupByGroupname2} + * @see hudson.security.AbstractPasswordBasedSecurityRealm#loadGroupByGroupname(java.lang.String) */ @Override @Deprecated @@ -466,8 +473,7 @@ public String getName() { /** * {@inheritDoc} * - * @see hudson.security.AbstractPasswordBasedSecurityRealm#authenticate2(java.lang.String, - * java.lang.String) + * @see hudson.security.AbstractPasswordBasedSecurityRealm#authenticate2(java.lang.String, java.lang.String) * */ @Override @@ -516,7 +522,7 @@ protected UserDetails authenticate2(String pUsername, String pPassword) } // create the list of granted authorities - List authorities = new ArrayList(); + List authorities = new ArrayList<>(); // add the "authenticated" authority to the list of granted // authorities... authorities.add(SecurityRealm.AUTHENTICATED_AUTHORITY2); @@ -672,7 +678,6 @@ public FormValidation doTestConnection(@QueryParameter String url, @QueryParamet @QueryParameter String httpProxyPassword, @QueryParameter String socketTimeout, @QueryParameter String httpTimeout, @QueryParameter String httpMaxConnections) { - // Logger log = Logger.getLogger(getClass().getName()); Jenkins.get().checkPermission(Jenkins.ADMINISTER); CrowdConfigurationService tConfiguration = new CrowdConfigurationService( url, applicationName, Secret.fromString(password), sessionValidationInterval, diff --git a/src/main/java/de/theit/jenkins/crowd/CrowdUserDetailsService.java b/src/main/java/de/theit/jenkins/crowd/CrowdUserDetailsService.java index fa3e82a4..3b78d714 100644 --- a/src/main/java/de/theit/jenkins/crowd/CrowdUserDetailsService.java +++ b/src/main/java/de/theit/jenkins/crowd/CrowdUserDetailsService.java @@ -115,7 +115,7 @@ public UserDetails loadUserByUsername(String username) } // create the list of granted authorities - List authorities = new ArrayList(); + List authorities = new ArrayList<>(); // add the "authenticated" authority to the list of granted // authorities... authorities.add(SecurityRealm.AUTHENTICATED_AUTHORITY2); diff --git a/src/main/java/de/theit/jenkins/crowd/ErrorMessages.java b/src/main/java/de/theit/jenkins/crowd/ErrorMessages.java index d20a91f7..6df6a30a 100644 --- a/src/main/java/de/theit/jenkins/crowd/ErrorMessages.java +++ b/src/main/java/de/theit/jenkins/crowd/ErrorMessages.java @@ -25,7 +25,7 @@ */ package de.theit.jenkins.crowd; -import java.util.ArrayList; +import java.util.List; import org.jvnet.localizer.ResourceBundleHolder; @@ -38,7 +38,7 @@ */ public class ErrorMessages { /** Contains the localized messages. */ - private final static ResourceBundleHolder holder = ResourceBundleHolder.get(ErrorMessages.class); + private static final ResourceBundleHolder holder = ResourceBundleHolder.get(ErrorMessages.class); /** * Returns the localized error message when no URL is specified. @@ -202,7 +202,7 @@ public static String applicationAccessDenied(String username) { * @return The localized error message when a user does not have the * permission to login. */ - public static String userNotValid(String username, ArrayList groupNames) { + public static String userNotValid(String username, List groupNames) { return holder.format("userNotValid", username, groupNames.toString()); } }