我收到一个白标错误页面此应用程序没有 /error 的显式映射,因此您将其视为后备。出现意外错误(类型=禁止,状态=403)。 禁止。
这是我的H2应用程序.properties
##H2 CONSOLE - DEVELOPMENT
spring.h2.console.path=/h2-console
spring.datasource.url=jdbc:mysql://localhost:3306/reusablerocket
spring.datasource.username=root
spring.datasource.password=1234
spring.jpa.database=h2
spring.h2.console.enabled=true
spring.jpa.show-sql=true
这是我的 MySQL 应用程序.properties
##MYSQL DATABASE - PRODUCTION
spring.jpa.database=mysql
spring.datasource.url=mysql://localhost:3306/reusablerocket
spring.datasource.username=root
spring.datasource.password=1234
这是我的 SecurityConfig 代码:
@Configuration
public class SecurityConfig {
@Autowired
private DataSource dataSource;
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public UserDetailsService userDetailsService() {
InMemoryUserDetailsManager userDetailsManager = new InMemoryUserDetailsManager();
userDetailsManager.createUser(User.withUsername("[email protected]")
.password(passwordEncoder().encode("1234"))
.roles("USER")
.build());
return userDetailsManager;
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authConfig) throws Exception {
return authConfig.getAuthenticationManager();
}
@Bean
public DaoAuthenticationProvider authenticationProvider(UserDetailsService userDetailsService) {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService);
authProvider.setPasswordEncoder(passwordEncoder());
return authProvider;
}
@Bean
public AccessDeniedHandler accessDeniedHandler() {
return new AccessDeniedHandlerImpl();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http, AccessDeniedHandler accessDeniedHandler) throws Exception {
http.authorizeRequests()
.requestMatchers("/secure/**").hasRole("USER")
.requestMatchers("/", "/js/**", "/css/**", "/images/**", "/**").permitAll()
.anyRequest().authenticated()
.and().formLogin()
.loginPage("/login").permitAll()
.and().logout()
.invalidateHttpSession(true)
.clearAuthentication(true)
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login?logout").permitAll()
.and().exceptionHandling()
.accessDeniedHandler(accessDeniedHandler);
http.authenticationProvider(authenticationProvider(userDetailsService()));
http.headers().frameOptions().sameOrigin();
return http.build();
}
}
我将 sql application.properties 作为我的配置文件(我正在使用 eclipse)
我尝试更改一些设置,删除一些依赖项,从应用程序属性更改用户名和密码。但没有任何效果。我需要尽快知道这是 4 天内到期的作业!!!!!!