package com.fractal.security;
import com.fractal.views.LoginView;
import com.fractal.views.about.AboutView;
import com.vaadin.flow.spring.security.VaadinWebSecurity;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.provisioning.UserDetailsManager;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@EnableWebSecurity
@Configuration
public class SecurityConfig extends VaadinWebSecurity {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeHttpRequests()
.requestMatchers(new AntPathRequestMatcher("/**")).permitAll();
super.configure(http);
setLoginView(http, LoginView.class);
}
@Override
protected void configure(WebSecurity web) throws Exception {
web.ignoring().requestMatchers(
"/VAADIN/**",
"/favicon.ico",
"/robots.txt",
"/manifest.webmanifest",
"/sw.js",
"/offline.html",
"/icons/**",
"/images/**",
"/styles/**",
"/h2-console/**");
super.configure(web);
}
@Bean
UserDetailsManager userDetailsManager(){
return new InMemoryUserDetailsManager(
User.withUsername("test")
.password("{noop}test")
.roles("USER")
.build()
);
}
}
当我试图打开任何URL时,它不会加载视图。但如果我将注解的看法。使用@PermitAll注解,它将工作。如何在配置类级别解决它如何修复它任何人都可以帮助我。
1条答案
按热度按时间vmpqdwk31#
这是按预期工作。
@DenyAll
是假定的默认值,如果没有指定任何内容。所以你必须有@PermitAll
,@AnonymousAllowed
或@RolesAllowed
。