首页 > 解决方案 > Spring Security 登录在本地工作,但不在现场

问题描述

我的应用程序是用 Java 和 Spring Security 构建的。我有两种登录方式,一种是使用 windows 登录(也称为活动目录),另一种是使用管理员用户创建的密码。当我通过 IntelliJ 在本地运行时,这两个都可以工作,但是当我将应用程序部署到服务器时,它只允许使用 Windows 登录凭据的人登录。如果您尝试在实时站点上使用自定义登录名登录,它只是刷新登录页面并删除输入的用户名和密码。我没有收到任何错误。此外,当用户 admin 创建自定义登录时,它存储在一个 sql 表中,密码经过哈希处理。所以创建功能有效/用户存在,只是登录不起作用。知道可能是什么原因......不确定我是否应该查看代码或服务器连接。我使用 Tomcat 和 IIS 来托管这个站点。

网页配置文件

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
   @Value("${ad.hg.url}")
    private String AD_HG_URL;

    @Value("${ad.hp.nt.url}")
    private String AD_HP_NT_URL;

    @Autowired
    DBAuthorizationFetcher dbAuthorizationFetcher;

    @Autowired
    ManualUserDetailsService manualUserDetailsService;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().ignoringAntMatchers("/specialSplit/**");

        http.authorizeRequests()
                .antMatchers("/css/**","/js/**","/images/**","/login","/accessDenied","/loginFailed","/changePassword","/resetPassword").permitAll()
                .antMatchers("/newClient","/callLogs/**","/addClient","/saveClient","/delete/**","/save/**","/specialSplit/**").hasRole("OLIDB_ADMIN")
                .antMatchers("/admin","/toggle/user/**").hasRole("USER_ADMIN")
                .anyRequest().hasRole("OLIDB_USER").and()
                .formLogin().loginPage("/login").failureHandler(new CustomAuthenticationFailureHandler()).successForwardUrl("/")
                .and().exceptionHandling().accessDeniedPage("/accessDenied")
                .and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/");
    }
    @Override
    protected void configure(AuthenticationManagerBuilder authManagerBuilder) throws Exception {
        //authManagerBuilder.authenticationProvider(databaseAuthenticationProvider);
        authManagerBuilder.authenticationProvider(activeDirectoryLdapAuthenticationProvider("HEFFGROUP.COM",AD_HP_NT_URL));
        authManagerBuilder.authenticationProvider(activeDirectoryLdapAuthenticationProvider("HG",AD_HG_URL));
        authManagerBuilder.authenticationProvider(manualAuthenticationProvider());
    }

    public AuthenticationProvider activeDirectoryLdapAuthenticationProvider(String domain,String url) {
        ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(domain, url);
        provider.setConvertSubErrorCodesToExceptions(true);
        provider.setUseAuthenticationRequestCredentials(true);
        provider.setUserDetailsContextMapper(dbAuthorizationFetcher);
        return provider;
    }

    public DaoAuthenticationProvider manualAuthenticationProvider() {
        DaoAuthenticationProvider authProvider
                = new DaoAuthenticationProvider();
        authProvider.setUserDetailsService(manualUserDetailsService);
        authProvider.setPasswordEncoder(new BCryptPasswordEncoder(11));
        return authProvider;
    }
}

标签: javahibernateauthenticationspring-securityauthorization

解决方案


推荐阅读