J'ai regarde encore un autre tuto et j'ai modifie ma classe de configuration de spring security comme ceci
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
package org.schoolmind.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
/**
* @author cedrickiadjeu
*
*/
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http
.authorizeRequests()
.antMatchers( "/schoolmind/index").permitAll()
.antMatchers("/schoolmind/indexAdmin").hasRole("ADMIN")
.and()
.formLogin();
//.loginPage("/login").failureUrl("/login-error");
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("12345").roles("ADMIN");
}
} |
Mais lorsque je demande la page j'obtiens une erreur 404
There was an unexpected error (type=Not Found, status=404).No message available
alors qu'en désactivant la sécurité sur la page en question elle s'affiche sans problème.
Donc je reste toujours coincé déjà que je ne sais même pas si l'authentification a reussi ou pas.
Voila mon controleur au cas ou l'erreur pourrait venir de la:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
/**
*
*/
package org.schoolmind.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author cedrickiadjeu
*
*/
@Controller
@RequestMapping(value="/schoolmind")
public class IndexController {
@RequestMapping(value="/index")
public String index(@RequestParam(name="lang" ,defaultValue="fr")String lang){
return "index";
}
@RequestMapping(value="/indexAdmin", method=RequestMethod.GET)
public String indexAdmin(@RequestParam(name="lang" ,defaultValue="fr")String lang){
return "indexAdmin";
}
} |
Tres simpliste puisque mon but est juste de tester spring security avant de l'utiliser dans mon application
Partager