Skip to content

Commit

Permalink
incorporate comments from review
Browse files Browse the repository at this point in the history
 * import settings
 * Jenkins.getAuthentication
 * DataBoundSetter and don't mess with the constructors

Signed-off-by: Michael Sprauer <[email protected]>
  • Loading branch information
MichaelSp committed Sep 4, 2019
1 parent 7e01e2d commit 58873a7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public FormValidation doValidateTest(@QueryParameter(fixEmpty = true) String nam
domains.add(domain);

ActiveDirectorySecurityRealm activeDirectorySecurityRealm = new ActiveDirectorySecurityRealm(null, domains, site, bindName,
bindPassword, null, GroupLookupStrategy.AUTO, false, true, null, false, (ActiveDirectoryInternalUsersDatabase) null, null);
bindPassword, null, GroupLookupStrategy.AUTO, false, true, null, false, (ActiveDirectoryInternalUsersDatabase) null);

ClassLoader ccl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
import hudson.Functions;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.security.*;
import hudson.security.AbstractPasswordBasedSecurityRealm;
import hudson.security.AuthorizationStrategy;
import hudson.security.ChainedServletFilter;
import hudson.security.GroupDetails;
import hudson.security.SecurityRealm;
import hudson.security.TokenBasedRememberMeServices2;
import hudson.util.ListBoxModel;
import hudson.util.Secret;
import hudson.util.spring.BeanBuilder;
Expand All @@ -50,7 +55,11 @@
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.*;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.springframework.dao.DataAccessException;
import org.springframework.web.context.WebApplicationContext;

Expand All @@ -70,8 +79,18 @@
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectStreamException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -233,26 +252,25 @@ public ActiveDirectorySecurityRealm(String domain, List<ActiveDirectoryDomain> d
boolean removeIrrelevantGroups, Boolean customDomain, CacheConfiguration cache,
Boolean startTls) {
this(domain, domains, site, bindName, bindPassword, server, groupLookupStrategy, removeIrrelevantGroups,
customDomain, cache, startTls, TlsConfiguration.TRUST_ALL_CERTIFICATES, null);
customDomain, cache, startTls, TlsConfiguration.TRUST_ALL_CERTIFICATES);
}

public ActiveDirectorySecurityRealm(String domain, List<ActiveDirectoryDomain> domains, String site, String bindName,
String bindPassword, String server, GroupLookupStrategy groupLookupStrategy,
boolean removeIrrelevantGroups, Boolean customDomain, CacheConfiguration cache,
Boolean startTls, TlsConfiguration tlsConfiguration, String userFromHTTPHeader) {
Boolean startTls, TlsConfiguration tlsConfiguration) {
this(domain, domains, site, bindName, bindPassword, server, groupLookupStrategy, removeIrrelevantGroups,
customDomain, cache, startTls, tlsConfiguration, null, userFromHTTPHeader);
customDomain, cache, startTls, tlsConfiguration, null);
}

@Deprecated
public ActiveDirectorySecurityRealm(String domain, List<ActiveDirectoryDomain> domains, String site, String bindName,
String bindPassword, String server, GroupLookupStrategy groupLookupStrategy,
boolean removeIrrelevantGroups, Boolean customDomain, CacheConfiguration cache,
Boolean startTls, TlsConfiguration tlsConfiguration,
ActiveDirectoryInternalUsersDatabase internalUsersDatabase,
String userFromHTTPHeader) {
ActiveDirectoryInternalUsersDatabase internalUsersDatabase) {
this(domain, domains, site, bindName, bindPassword, server, groupLookupStrategy, removeIrrelevantGroups,
customDomain, cache, startTls, (ActiveDirectoryInternalUsersDatabase) null, userFromHTTPHeader);
customDomain, cache, startTls, (ActiveDirectoryInternalUsersDatabase) null);
}


Expand All @@ -261,8 +279,7 @@ public ActiveDirectorySecurityRealm(String domain, List<ActiveDirectoryDomain> d
public ActiveDirectorySecurityRealm(String domain, List<ActiveDirectoryDomain> domains, String site, String bindName,
String bindPassword, String server, GroupLookupStrategy groupLookupStrategy,
boolean removeIrrelevantGroups, Boolean customDomain, CacheConfiguration cache,
Boolean startTls, ActiveDirectoryInternalUsersDatabase internalUsersDatabase,
String userFromHTTPHeader) {
Boolean startTls, ActiveDirectoryInternalUsersDatabase internalUsersDatabase) {
if (customDomain!=null && !customDomain)
domains = null;
this.domain = fixEmpty(domain);
Expand All @@ -276,7 +293,6 @@ public ActiveDirectorySecurityRealm(String domain, List<ActiveDirectoryDomain> d
this.cache = cache;
this.startTls = startTls;
this.internalUsersDatabase = internalUsersDatabase;
this.userFromHTTPHeader = userFromHTTPHeader;
}

@DataBoundSetter
Expand Down Expand Up @@ -869,6 +885,7 @@ public String getUserFromHTTPHeader() {
return userFromHTTPHeader;
}

@DataBoundSetter
public void setUserFromHTTPHeader(String userFromHTTPHeader) {
this.userFromHTTPHeader = userFromHTTPHeader;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UsernameNotFoundException;

import javax.servlet.*;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.logging.Level;
Expand All @@ -32,8 +37,7 @@ public void doFilter(ServletRequest servletRequest,
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;

if (SecurityContextHolder.getContext().getAuthentication() == null ||
SecurityContextHolder.getContext().getAuthentication() instanceof AnonymousAuthenticationToken) {
if (Jenkins.getAuthentication() instanceof AnonymousAuthenticationToken) {
Authentication auth = Jenkins.ANONYMOUS;
String authenticatedUserFromApiToken = getUserFromAuthorizationHeader(request);

Expand Down

0 comments on commit 58873a7

Please sign in to comment.