public SecurityComponents createSecurityComponents() {
Binding binding = new Binding();
binding.setVariable("instance", this);
BeanBuilder builder = new BeanBuilder();
String fileName = "LDAPBindSecurityRealm.groovy";
try {
File override = new File(Jenkins.getInstance().getRootDir(), fileName);
builder.parse(
override.exists() ? new AutoCloseInputStream(new FileInputStream(override)) :
Jenkins.getInstance().servletContext.getResourceAsStream("/WEB-INF/security/"+ fileName),binding);
} catch (FileNotFoundException e) {
throw new Error("Failed to load "+fileName,e);
}
WebApplicationContext appContext = builder.createApplicationContext();
ldapTemplate = new LdapTemplate(findBean(InitialDirContextFactory.class, appContext));
return new SecurityComponents(
findBean(AuthenticationManager.class, appContext),