@Override
  public SecurityComponents createSecurityComponents() {
    Binding binding = new Binding();
    binding.setVariable("instance", this);

    BeanBuilder builder = new BeanBuilder(Jenkins.getInstance().pluginManager.uberClassLoader);

    String fileName;
    if (getLDAPURL() != null) {
      fileName = "ReverseProxyLDAPSecurityRealm.groovy";
    } else {
      fileName = "ReverseProxySecurityRealm.groovy";
    }

    try {
      File override = new File(Jenkins.getInstance().getRootDir(), fileName);
      builder.parse(
          override.exists()
              ? new AutoCloseInputStream(new FileInputStream(override))
              : getClass().getResourceAsStream(fileName),
          binding);
    } catch (FileNotFoundException e) {
      throw new Error("Failed to load " + fileName, e);
    }
    WebApplicationContext appContext = builder.createApplicationContext();

    if (getLDAPURL() == null) {
      proxyTemplate = new ReverseProxySearchTemplate();

      return new SecurityComponents(
          findBean(AuthenticationManager.class, appContext),
          new ReverseProxyUserDetailsService(appContext));
    } else {
      ldapTemplate = new LdapTemplate(findBean(InitialDirContextFactory.class, appContext));

      if (groupMembershipFilter != null) {
        ProxyLDAPAuthoritiesPopulator authoritiesPopulator =
            findBean(ProxyLDAPAuthoritiesPopulator.class, appContext);
        authoritiesPopulator.setGroupSearchFilter(groupMembershipFilter);
      }

      return new SecurityComponents(
          findBean(AuthenticationManager.class, appContext),
          new ProxyLDAPUserDetailsService(this, appContext));
    }
  }
Exemple #2
0
  /** Create the Spring application context that will hold CAS filters. */
  protected WebApplicationContext getApplicationContext() {
    if (this.applicationContext == null) {
      Binding binding = new Binding();
      binding.setVariable("securityRealm", this);
      binding.setVariable("casProtocol", this.casProtocol);

      BeanBuilder builder = new BeanBuilder(getClass().getClassLoader());
      builder.parse(
          getClass()
              .getClassLoader()
              .getResourceAsStream(getClass().getName().replace('.', '/') + ".groovy"),
          binding);

      this.applicationContext = builder.createApplicationContext();
    }
    return this.applicationContext;
  }