Source:
<code>protected void setAuthorities(GrantedAuthority[] authorities) { final Jenkins instance = Jenkins.getInstance(); <START> if(instance!=null) { <END> final SecurityRealm realm = instance.getSecurityRealm(); if ((realm instanceof ActiveDirectorySecurityRealm)) { final ActiveDirectorySecurityRealm activeDirectoryRealm = (ActiveDirectorySecurityRealm)realm; if (activeDirectoryRealm.removeIrrelevantGroups) { Set<String> referencedGroups = new HashSet<String>(); { final AuthorizationStrategy authorizationStrategy = instance.getAuthorizationStrategy(); if(authorizationStrategy!=null) for (String group : authorizationStrategy.getGroups()) { referencedGroups.add(group.toLowerCase()); } } if (!referencedGroups.isEmpty()) { List<GrantedAuthority> relevantGroups = new ArrayList<GrantedAuthority>(); for (GrantedAuthority group : authorities) { String groupName = group.getAuthority(); if (groupName != null && referencedGroups.contains(groupName.toLowerCase())) { relevantGroups.add(group); } } authorities = relevantGroups.toArray(new GrantedAuthority[relevantGroups.size()]); } } } } super.setAuthorities(authorities); StringBuffer sb = new StringBuffer(); sb.append(super.toString()).append(": "); sb.append("Username: ").append(getUsername()).append("; "); sb.append("Password: [PROTECTED]; "); sb.append("Enabled: ").append(isEnabled()).append("; "); sb.append("AccountNonExpired: ").append(isAccountNonExpired()).append("; "); sb.append("credentialsNonExpired: ").append(isCredentialsNonExpired()).append("; "); sb.append("AccountNonLocked: ").append(isAccountNonLocked()).append("; "); if (this.getAuthorities() != null) { sb.append("Granted Authorities: "); for (int i = 0; i < this.getAuthorities().length; i++) { if (i > 0) { sb.append(", "); } sb.append(this.getAuthorities()[i].toString()); } } else { sb.append("Not granted any authorities"); } toStringValue = sb.toString(); }</code><technical_language>Depending expect, interested in Jenkins.getActiveInstance() instead remove null check</technical_language>

Target:
protected void setAuthorities(GrantedAuthority[] authorities) { SecurityRealm realm = Jenkins.getInstance().getSecurityRealm(); if ((realm instanceof ActiveDirectorySecurityRealm)) { ActiveDirectorySecurityRealm activeDirectoryRealm = (ActiveDirectorySecurityRealm)realm; if (activeDirectoryRealm.removeIrrelevantGroups) { Set<String> referencedGroups = new HashSet<String>(); for (String group : Jenkins.getInstance().getAuthorizationStrategy().getGroups()) { referencedGroups.add(group.toLowerCase()); } if (!referencedGroups.isEmpty()) { List<GrantedAuthority> relevantGroups = new ArrayList<GrantedAuthority>(); for (GrantedAuthority group : authorities) { String groupName = group.getAuthority(); if (groupName != null && referencedGroups.contains(groupName.toLowerCase())) { relevantGroups.add(group); } } authorities = relevantGroups.toArray(new GrantedAuthority[relevantGroups.size()]); } } } super.setAuthorities(authorities); StringBuffer sb = new StringBuffer(); sb.append(super.toString()).append(": "); sb.append("Username: ").append(getUsername()).append("; "); sb.append("Password: [PROTECTED]; "); sb.append("Enabled: ").append(isEnabled()).append("; "); sb.append("AccountNonExpired: ").append(isAccountNonExpired()).append("; "); sb.append("credentialsNonExpired: ").append(isCredentialsNonExpired()).append("; "); sb.append("AccountNonLocked: ").append(isAccountNonLocked()).append("; "); if (this.getAuthorities() != null) { sb.append("Granted Authorities: "); for (int i = 0; i < this.getAuthorities().length; i++) { if (i > 0) { sb.append(", "); } sb.append(this.getAuthorities()[i].toString()); } } else { sb.append("Not granted any authorities"); } toStringValue = sb.toString(); }