java - 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;
}
}
解决方案
推荐阅读
- python - 从另一个矩阵的列创建一个矩阵
- javascript - 如何正确编写插件代码成功?
- r - dplyr::coalesce,但对于多行
- javascript - 根据鼠标位置旋转 div
- javascript - 在静态 HTML 中包含 Puppeteer (javascript) 代码
- kdb - 如何将 kdb RDB 设置为仅订阅 tickerplant 中的某些表
- java - 将 JsonSchema 解析为 io.swagger.v3.oas.models.media.Schema
- installation - 赛普拉斯不会在安装时创建目录
- c# - 如何通过用户输入(控制台应用程序)在 C# 中使用带有 List 的 IndexOf 方法自动增加 int userid?
- php - 在 Eloquent 中将数据透视表与多个表连接起来