登錄前我在我的網站上看不到影像。我該如何解決這個問題?下面是我的 spring 安全配置類。我認為問題出在這門課上。
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/home" , "/about", "/blog/**", "/blog", "/blog/add", "/registration").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/sign-in")
.permitAll()
.and()
.logout()
.permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.passwordEncoder(NoOpPasswordEncoder.getInstance())
.usersByUsernameQuery("select username, password, active from usr where username=?")
.authoritiesByUsernameQuery("select u.username, ur.roles from usr u inner join user_role ur on u.id = ur.user_id where u.username=?");
}
}
uj5u.com熱心網友回復:
嘗試將此方法添加到 WebSecurityConfig
例如對于位于靜態資源目錄中的影像: src/main/resources/static/images
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/images/**");
}
uj5u.com熱心網友回復:
據我了解,您在從彈簧安全過濾器傳遞靜態資源時遇到問題。對于這個問題,您需要更改配置以排除靜態資源的地址,在您的情況下它是圖片。在專案的資源檔案夾中創建名為 image 的新檔案夾,然后將圖片添加到其中并將這些代碼行添加到 spring 安全配置中
.antMatchers("/","/public/**", "/resources/**","/resources/image/**")
.permitAll()
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/418831.html
標籤:
