Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Commit

Permalink
Remove reported form SonarCode code smells (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
DuMaM authored Apr 24, 2022
1 parent 1f7594c commit e1b3d1a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public Authentication authenticate(Authentication authentication)
username, this.configuration.getAllowedGroupNames()));
}

// String displayName = null;
try {
// authenticate user
if (LOG.isLoggable(Level.FINE)) {
Expand All @@ -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));
Expand Down Expand Up @@ -152,7 +150,7 @@ public Authentication authenticate(Authentication authentication)

// user successfully authenticated
// => retrieve the list of groups the user is a member of
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
List<GrantedAuthority> authorities = new ArrayList<>();

// add the "authenticated" authority to the list of granted
// authorities...
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/de/theit/jenkins/crowd/CrowdAuthenticationToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public CrowdConfigurationService(String url, String applicationName, Secret pass
this.tokenHelper);
}

public ArrayList<String> getAllowedGroupNames() {
public List<String> getAllowedGroupNames() {
return allowedGroupNames;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
List<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(SecurityRealm.AUTHENTICATED_AUTHORITY2);
authorities.addAll(this.configuration.getAuthoritiesForUser(user.getName()));
result = new CrowdAuthenticationToken(user.getName(), null, authorities, ssoToken);
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/de/theit/jenkins/crowd/CrowdSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -326,7 +326,7 @@ private void initializeConfiguration() {
/**
* {@inheritDoc}
*
* @see hudson.security.SecurityRealm#createSecurityComponents()
* @see hudson.security.AbstractPasswordBasedSecurityRealm#createSecurityComponents()
*/
@Override
public SecurityComponents createSecurityComponents() {
Expand Down Expand Up @@ -390,6 +390,7 @@ public Filter createFilter(FilterConfig filterConfig) {
/**
* {@inheritDoc}
*
* @deprecated use {@link #loadUserByUsername2}
* @see hudson.security.AbstractPasswordBasedSecurityRealm#loadUserByUsername(java.lang.String)
*/
@Override
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -516,7 +522,7 @@ protected UserDetails authenticate2(String pUsername, String pPassword)
}

// create the list of granted authorities
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
List<GrantedAuthority> authorities = new ArrayList<>();
// add the "authenticated" authority to the list of granted
// authorities...
authorities.add(SecurityRealm.AUTHENTICATED_AUTHORITY2);
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public UserDetails loadUserByUsername(String username)
}

// create the list of granted authorities
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
List<GrantedAuthority> authorities = new ArrayList<>();
// add the "authenticated" authority to the list of granted
// authorities...
authorities.add(SecurityRealm.AUTHENTICATED_AUTHORITY2);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/de/theit/jenkins/crowd/ErrorMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
package de.theit.jenkins.crowd;

import java.util.ArrayList;
import java.util.List;

import org.jvnet.localizer.ResourceBundleHolder;

Expand All @@ -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.
Expand Down Expand Up @@ -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<String> groupNames) {
public static String userNotValid(String username, List<String> groupNames) {
return holder.format("userNotValid", username, groupNames.toString());
}
}

0 comments on commit e1b3d1a

Please sign in to comment.