Created
February 13, 2020 19:42
-
-
Save SpComb/725fbf696e38ab372d37670df09e3f00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.logging.Logger | |
import jenkins.model.Jenkins | |
import org.jenkinsci.plugins.reverse_proxy_auth.ReverseProxySecurityRealm | |
def env = System.getenv() | |
def logger = Logger.getLogger("jenkins.init.auth-http") | |
def instance = Jenkins.getInstance() | |
if (env.JENKINS_HTTP_AUTH) { | |
config = [ | |
forwardedUser: env.JENKINS_HTTP_USER_HEADER ?: "X-Forwarded-User", | |
headerGroups: env.JENKINS_HTTP_GROUP_HEADER ?: "X-Forwarded-Groups", | |
headerGroupsDelimiter: env.JENKINS_HTTP_GROUP_DELIMITER ?: "|", | |
customLogInUrl: env.JENKINS_HTTP_LOGIN_URL, | |
customLogOutUrl: env.JENKINS_HTTP_LOGOUT_URL, | |
] | |
securityRealm = new ReverseProxySecurityRealm( | |
config.forwardedUser ?: "", | |
config.headerGroups ?: "", | |
config.headerGroupsDelimiter ?: "", | |
config.customLogInUrl ?: "", | |
config.customLogOutUrl ?: "", | |
config.server ?: "", | |
config.rootDN ?: "", | |
config.inhibitInferRootDN ?: false, | |
config.userSearchBase ?: "", | |
config.userSearch ?: "", | |
config.groupSearchBase ?: "", | |
config.groupSearchFilter ?: "", | |
config.groupMembershipFilter ?: "", | |
config.groupNameAttribute ?: "", | |
config.managerDN ?: "", | |
config.managerPassword ?: "", | |
config.updateInterval ?: 0, | |
config.disableLdapEmailResolver ?: false, | |
config.displayNameLdapAttribute ?: "", | |
config.emailAddressLdapAttribute ?: "", | |
) | |
logger.info("Configure http auth: " + securityRealm) | |
instance.setSecurityRealm(securityRealm) | |
instance.save() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment