尝试删除Java AD身份验证

时间:2018-04-28 17:16:13

标签: java spring-boot javax

我有一个旧的应用程序,我正在尝试站起来并开始在我的本地计算机上工作。原始应用程序是在域上开发的,并使用LDAP身份验证。我的机器不再连接到任何域,我想删除所有身份验证,但是当我尝试将其注释掉时,它不会构建。

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

private static final Logger log = Logger.getLogger(SecurityConfig.class
        .getName());

@Override
protected void configure(HttpSecurity http) throws Exception {

    // String configPath = (String) new InitialContext()
    // .lookup("java:comp/env/twiddyApiConfigPath");
    // Properties properties = new Properties();
    // InputStream inputStream = new FileInputStream(configPath);
    // properties.load(inputStream);

    // Boolean productionBuild = Boolean.valueOf(properties
    // .getProperty("productionBuild"));

    Boolean productionBuild = false;
    if (productionBuild) {
        // @formatter:off
        http.csrf()
                .disable()
                // never use server side sessions (stateless mode)
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .addFilterAfter(new JwtFilter(),
                        AnonymousAuthenticationFilter.class);
        // @formatter:on
    } else {
        // @formatter:off
        http.csrf().disable()
                // never use server side sessions (stateless mode)
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
        // @formatter:on
    }
}

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

@Configuration
protected static class AuthenticationConfiguration extends
        GlobalAuthenticationConfigurerAdapter {

    @Autowired
    private Environment env;

    @Bean
    public UserDetailsContextMapper userDetailsContextMapper() {

    //          return new LdapUserDetailsMapper() {
    //              @Override
    //              public UserDetails mapUserFromContext(DirContextOperations ctx,
   //                       String username,
   //                       Collection<? extends GrantedAuthority> authorities) {
  //                    UserDetails details = super.mapUserFromContext(ctx,
  //                            username, authorities);
  //                    return new CustomLdapUserDetails((LdapUserDetails) details,
 //                         env);
 //             }
 //         };
    }

    //@Override
    //public void init(AuthenticationManagerBuilder auth) throws Exception {

         //DefaultSpringSecurityContextSource contextSource;

        // String configPath = (String) new
        // InitialContext().lookup("java:comp/env/twiddyApiConfigPath");
        // String configPath = "C:\\temp\\api.properties";

        // Properties properties = new Properties();
        // InputStream inputStream = new FileInputStream(configPath);
        // properties.load(inputStream);

         / String ldapUrl = properties.getProperty("ldapAddress");
        // String ldapString = "ldap://" + ldapUrl;
        // String ldapUsername = properties.getProperty("ldapUsername");
        // String ldapPassword = properties.getProperty("ldapPassword");

         //contextSource = new
         //DefaultSpringSecurityContextSource(ldapString);
         // contextSource.setUserDn(ldapUsername);
        // contextSource.setPassword(ldapPassword);
         //contextSource.setReferral("follow");
         //contextSource.afterPropertiesSet();

         //@formatter:off
         //auth.ldapAuthentication()
         //.userDetailsContextMapper(userDetailsContextMapper());
         //.userSearchFilter("sAMAccountName={0}")
         //.userSearchBase("OU=CompanyName").contextSource(contextSource);
         //@formatter:on
    //}
}

}

0 个答案:

没有答案