Java - antMatchers

 
Vista:
sin imagen de perfil
Val: 5
Ha aumentado su posición en 6 puestos en Java (en relación al último mes)
Gráfica de Java

antMatchers

Publicado por gabriela paola (3 intervenciones) el 17/02/2020 20:14:59
Hola! buenas tardes, tengo problema en el siguiente codigo :


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
 
	@Override
	protected void configure(HttpSecurity http) throws Exception {
		http.authorizeRequests()
				.antMatchers("/web/games.html").permitAll()
				.antMatchers("/api/games").permitAll()
				.antMatchers("/resources/static/web/scripts/games.js").permitAll()
				.antMatchers("/resources/static/web/css/games.css").permitAll()
				.antMatchers("/web/**").hasAuthority("USER")
				.antMatchers("/api/game_view/**").hasAuthority("USER")
				.antMatchers("/resources/static/web/**").hasAuthority("USER");
		http.formLogin()
				.usernameParameter("name")
				.passwordParameter("pwd")
				.loginPage("/api/login");
		http.logout().logoutUrl("/api/logout");
	}

cuando accedo a games.html no me carga el javascript ni el css. No se supone que en ".antMatchers("/resources/static/web/scripts/games.js").permitAll()" estoy accediendo a esos archivos? Muchas gracias por la ayuda!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

antMatchers

Publicado por Julian (1 intervención) el 17/02/2020 21:24:05
Hola

Te recomiendo que utilices una sola linea para el acceso a los recursos.
Ejemplo

1
2
3
4
http
                .authorizeRequests()
                .antMatchers("/", "/web/**", "/css/** " ,"/js/**", "/images/**", "/listar", "/locale")
                .permitAll()

1
2
3
//No es necesario colocar toda la ruta
//solo con que se le de el permiso a la carpeta css
.antMatchers("/resources/static/web/css/games.css").permitAll()

//Observando tu código tienes dos carpetas web.
// Se deberia renombrar para no tener problemas de permisos
1
.antMatchers("/web/games.html").permitAll()

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
2
Comentar