作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 spring security 创建一个登录页面,并在 AntMatcher 列表中添加了 .css 文件以获得许可。但是,我在尝试加载 CSS 文件时仍然收到以下错误。
异常:
home:6 GET http://localhost:8080/defaultStyle.css net::ERR_ABORTED 404
使用更改后的类进行更新。
WebSecurityConfig类代码:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity( jsr250Enabled = true,
prePostEnabled = true )
public class WebSecurityConfig extends WebSecurityConfigurerAdapter
{
@Autowired
CustomUserDetailsService customUserDetailsService;
@Autowired
private JwtAuthenticationEntryPoint unauthorizedHandler;
@Autowired
private JwtAuthenticationFilter jwtAuthenticationFilter;
@Autowired
private CustomAccessDeniedHandler customAccessDeniedHandler;
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception
{
return super.authenticationManagerBean();
}
@Override
public void configure( WebSecurity web ) throws Exception
{
web.ignoring()
.antMatchers( "/*.css" ) // or better ending with ".{js,html}" or something
.antMatchers( "/resources/static/**/*" );
}
@Override
public void configure( HttpSecurity http ) throws Exception
{
http.cors().and().csrf().disable().authorizeRequests()
.antMatchers( "/*", "/admin", "/api/auth/**",
"/static/**",
"/css/*.css",
"/img/**",
"/favicon.ico",
"/**/*.png",
"/**/*.gif",
"/**/*.svg",
"/**/*.jpg",
"/**/*.html",
"/**/*.css",
"/**/*.js",
"/webjars/**" ).permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage( "/home" )
.loginProcessingUrl( "/login-user" )
.defaultSuccessUrl( "/dashboard" ).permitAll()
.and()
.logout().invalidateHttpSession( true )
.clearAuthentication( true )
.logoutRequestMatcher( new AntPathRequestMatcher( "/logout" ) )
.logoutSuccessUrl( "/login?logout" )
.permitAll().and()
.exceptionHandling().accessDeniedHandler( customAccessDeniedHandler ).authenticationEntryPoint( unauthorizedHandler ).and()
.sessionManagement().sessionCreationPolicy( SessionCreationPolicy.STATELESS );
http
.addFilterBefore( jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class );
}
@Autowired
public void globalUserDetails( AuthenticationManagerBuilder auth ) throws Exception
{
auth.userDetailsService( customUserDetailsService )
.passwordEncoder( passwordEncoder() );
}
@Bean
public PasswordEncoder passwordEncoder()
{
return new BCryptPasswordEncoder();
}
}
网络配置类
Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer
{
@Override
public void addResourceHandlers( ResourceHandlerRegistry registry )
{
registry
.addResourceHandler( "swagger-ui.html" )
.addResourceLocations( "classpath:/META-INF/resources/" );
registry
.addResourceHandler( "/webjars/**" )
.addResourceLocations( "classpath:/META-INF/resources/webjars/" );
registry
.addResourceHandler( "/static/**" )
.addResourceLocations( "classpath:/static/" );
registry.addResourceHandler( "/css/**" )
.addResourceLocations( "/css/" );
registry.addResourceHandler( "/img/**" )
.addResourceLocations( "/img/" );
registry.addResourceHandler( "/js/**" )
.addResourceLocations( "/js/" );
}
@Override
public void addCorsMappings( CorsRegistry registry )
{
registry.addMapping( "/**" )
.allowedMethods( "POST", "GET", "PUT", "OPTIONS", "DELETE" )
.allowedHeaders( "X-Auth-Token", "Content-Type" )
.exposedHeaders( "custom-header1", "custom-header2" )
.allowCredentials( false )
.maxAge( 4800 );
}
@Override
public void addViewControllers( ViewControllerRegistry registry )
{
System.out.println( "Inside MvcConfig addViewControllers() adding View forgot" );
registry.addViewController( "/admin/home" ).setViewName( "jsp/home" );
registry.addViewController( "/login" ).setViewName( "/login" );
}
}
新错误
编辑
我已经用修改后的网络安全文件更新了问题,并将异常更改为我现在得到的新异常。
最佳答案
请尝试下面的代码
http.cors().and().csrf().disable().
authorizeRequests()
.antMatchers( "/",
"/static/**",
"/img/**",
"/favicon.ico",
"/**/*.png",
"/**/*.gif",
"/**/*.svg",
"/**/*.jpg",
"/**/*.html",
"/**/*.css",
"/**/*.js",
"/webjars/**" ).permitAll()
.antMatchers( "/api/auth/**" ).permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage( "/home" )
.loginProcessingUrl("/login")
.defaultSuccessUrl( "/dashboard").permitAll()
.and()
关于java - 无法在 html 页面中加载 Css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56831498/
我正在开发一个需要能够平均三个数字的 Facebook 应用程序。但是,它总是返回 0 作为答案。这是我的代码: $y = 100; $n = 250; $m = 300; $number = ($y
我只是无法弄清楚这一点,也找不到任何对我来说有意义的类似问题。我的问题:我从数据库中提取记录,并在我的网页上以每个面板 12 条的倍数显示它们。因此,我需要知道有多少个面板可以使用 JavaScrip
我是一名优秀的程序员,十分优秀!