Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve 2 spotbugs issues and increase spotbugs checks #100

Merged
merged 12 commits into from
Feb 11, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public class GitLabAuthenticationToken extends AbstractAuthenticationToken {
private final transient User me;
private transient GitLabSecurityRealm myRealm = null;







MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved
/**
* Cache for faster organization based security
*/
Expand Down Expand Up @@ -106,9 +112,9 @@ public GitLabAuthenticationToken(String accessToken, String gitlabServer, TokenT
authorities.add(SecurityRealm.AUTHENTICATED_AUTHORITY);
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins != null && jenkins.getSecurityRealm() instanceof GitLabSecurityRealm) {
if (myRealm == null) {

myRealm = (GitLabSecurityRealm) jenkins.getSecurityRealm();
}

// Search for scopes that allow fetching team membership. This is
// documented online.
// https://developer.gitlab.com/v3/orgs/#list-your-organizations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@

import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.userdetails.User;
import org.acegisecurity.userdetails.UserDetails;


/**
* @author Mike
*
*/
public class GitLabOAuthUserDetails extends User implements UserDetails {
public class GitLabOAuthUserDetails extends User {
MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved

/**
*
*/
private static final long serialVersionUID = 1709511212188366292L;

public GitLabOAuthUserDetails(org.gitlab4j.api.models.User user, GrantedAuthority[] authorities) {
super(user.getUsername(), "", true, true, true, true, authorities);
super(user.getUsername(), user.getEmail(), true, true, true, true, authorities);
MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved
}

}
22 changes: 11 additions & 11 deletions src/main/java/org/jenkinsci/plugins/GitLabSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
Expand Down Expand Up @@ -221,24 +220,25 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co
}

private void setValue(GitLabSecurityRealm realm, String node, String value) {
switch (node.toLowerCase()) {
case "clientid":
realm.setClientID(value);
break;
case "clientsecret":
realm.setClientSecret(value);
break;
case "gitlabweburi":
switch (node) {
MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved
case "gitlabWebUri":
realm.setGitlabWebUri(value);
break;
case "gitlabapiuri":
case "gitlabApiUri":
realm.setGitlabApiUri(value);
break;
case "clientID":
realm.setClientID(value);
break;
case "clientSecret":
realm.setClientSecret(value);
break;
default:
throw new ConversionException("Invalid node value = " + node);
MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}


}

/**
Expand Down