I only have the following three classes in my project and a view file. No config files. I have tried to configure spring security on an spring mvc app.
When i run this as java application and access it in browser it asks for password.
i m entering use and password in the respective form fields but it does not authenticate.
I checked logs and found this line
Using default security password: 75a836df-d369-4600-aad2-a50567ebd283
When ii used this it successfully logged me in.
I cant understand this. Can anyone explain this to me? Am I missing something?
package hello;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
}
}
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
package hello;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class GreetingController {
@RequestMapping("/greeting")
private String greeting(@RequestParam(value="name", defaultValue="World", required=false) String name, Model model) {
model.addAttribute("name", name);
return "greeting";
}
}
Aucun commentaire:
Enregistrer un commentaire