[英]Spring security don't show images befor loging in. How to fix?
登錄前我在我的網站上看不到圖像。我該如何解決這個問題? 下面是我的 spring 安全配置的 class。 我認為問題出在這個 class 內部。
@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=?");
}
}
嘗試將此方法添加到WebSecurityConfig
例如,對於位於 static 資源目錄中的圖像,位於: src/main/resources/static/images
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/images/**");
}
據我了解,您在從 spring 安全過濾器傳遞 static 資源時遇到問題。 對於這個問題,您需要更改配置以排除 static 資源的地址,在您的情況下它是圖片。 在項目的資源文件夾中創建名為 image 的新文件夾,然后將圖片添加到其中並將這些代碼行添加到 spring 安全配置中
.antMatchers("/","/public/**", "/resources/**","/resources/image/**")
.permitAll()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.