java - Spring Security 不适用于 Weblogic 12.2.1.2
问题描述
我有一个使用Spring Security的 Web 应用程序。它适用于Tomcat,但不适用于Weblogic 12.2.1.2。
在 Weblogic 上,当用户尝试访问受限 URL(例如 localhost:7001/website/restricted/welcome)时,不会将用户重定向到登录页面。在 Tomcat 上,用户被正确重定向到登录页面。
我读到这是Weblogic 12.1的一个错误,它似乎已在 Weblogic 12.2 中修复。但我使用的是 Weblogic 12.2.1.2并且遇到了同样的问题。
我阅读了一些解决方案,但我很难理解它们,因为我有不同的 Spring 配置。
这些是我关于 Spring Security 的课程。
这是扩展WebSecurityConfigurerAdapter的类。
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth)
throws Exception {
auth.inMemoryAuthentication()
.passwordEncoder(passwordEncoder())
.withUser("username1")
.password(passwordEncoder()
.encode("password1"))
.roles("ADMIN");
}
@Bean
public PasswordEncoder passwordEncoder() {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
return passwordEncoder;
}
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.formLogin()
.loginPage("/login")
.usernameParameter("userId")
.passwordParameter("password");
httpSecurity.formLogin()
.defaultSuccessUrl("/")
.failureHandler(new CustomAuthenticationFailureHandler())
.and()
.sessionManagement()
.maximumSessions(1)
.expiredUrl("/login?expired")
.maxSessionsPreventsLogin(true);
httpSecurity.logout()
.logoutSuccessUrl("/login?logout");
httpSecurity.rememberMe()
.rememberMeParameter("rememberMe")
.key("rememberMeKey")
.tokenValiditySeconds(1800);
httpSecurity.exceptionHandling()
.accessDeniedPage("/login?accessDenied");
httpSecurity.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/**/add").access("hasRole('ADMIN')")
.antMatchers("/**/market/**").access("hasRole('USER')");
httpSecurity.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
}
}
这是扩展AbstractSecurityWebApplicationInitializer的类。
public class SecurityWebApplicationInitializer
extends AbstractSecurityWebApplicationInitializer
implements WebApplicationInitializer {
@Override
protected boolean enableHttpSessionEventPublisher() {
return true;
}
}
问题似乎与Spring Boot相关。当使用Spring Tool Suite时,我使用Spring Starter Project 向导(Spring boot)遇到问题。如果我不使用 Spring Boot,Spring Security 可以正常工作!
我应该如何解决这个问题?谢谢
解决方案
推荐阅读
- html - 只显示最近的猫鼬时间戳?
- python - 使用 Python 访问网络资源。JSON问题?
- math - 什么是成对不同?
- laravel-routing - 某些 URL 在生产中是 404
- c#-8.0 - 将空文字转换为非空 C# 8
- html - 我如何对齐两张不同高度的图片HTML
- pandas - 为什么插值 NaN 会导致空图?
- python - 将 pandas DataFrame 更改为 numpy 数组但保留列名
- netsuite - 报告中的 Netsuite 字段为空白,并保存了转移单的搜索
- node.js - 如何使用replace替换nodejs中字符串中的所有特殊字符?