Моя HTML-форма:
<form id="User" name="User" action="<%=request.getContextPath()%>/${role}/login"
success="<%=request.getContextPath()%>/${role}/index"
onsubmit="return AppSecurity.submitLogin(this);">
Мой контроллер,
@RequestMapping(value = {"/", "/login"}, method = RequestMethod.GET)
public void login(HttpServletRequest request, HttpServletResponse response) throws Throwable {
System.out.println(">>>> inside login method");
//response.sendRedirect("http://localhost:8080/auth/login");
}
Моя конфигурация безопасности,
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private SecurityProperties security;
@Autowired
private AuthenticationFailureHandler authFailureHandler;
@Autowired
private AuthenticationSuccessHandler authSuccessHandler;
@Autowired
private AuthenticationEntryPoint authEntryPoint;
@Autowired
private LogoutSuccessHandler authLogoutHandler;
private static List<String> DEFAULT_IGNORED = Arrays.asList(new String[]{"/css/**", "/js/**", "/images/**", "/**/favicon.ico"});
public static List<String> getIgnored(SecurityProperties security) {
ArrayList ignored = new ArrayList(security.getIgnored());
if (ignored.isEmpty()) {
ignored.addAll(DEFAULT_IGNORED);
} else if (ignored.contains("none")) {
ignored.remove("none");
}
return ignored;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
System.out.println("*************** spring security configure");
http.exceptionHandling().authenticationEntryPoint(authEntryPoint);
http.csrf().disable();
http.authorizeRequests()
.antMatchers("/admin/hr/Employees/List/").permitAll()
.antMatchers("/registration").permitAll()
.antMatchers("/forgotPassword").permitAll()
.antMatchers("/min/**").permitAll()
.antMatchers("/src/**").permitAll()
.antMatchers("/images/**").permitAll()
.antMatchers("/css/**").permitAll()
.antMatchers("/data/**").permitAll()
.antMatchers("/fonts/**").permitAll()
.antMatchers("/img/**").permitAll()
.antMatchers("/js/**").permitAll()
.antMatchers("/public/**").permitAll()
.antMatchers("/temp/**").permitAll()
.antMatchers("/www/**").permitAll()
.antMatchers("/login").permitAll()
.antMatchers("/logout").permitAll()
.antMatchers("/admin/**").authenticated()
// .antMatchers("/**").permitAll()
.and()
.formLogin()
.loginPage("/login/")
// .defaultSuccessUrl("/auth", true)
.failureHandler(this.authFailureHandler)
.successHandler(this.authSuccessHandler)
.permitAll()
.and()
.logout()
.deleteCookies("remember-me")
.logoutUrl("/logout/")
.logoutSuccessHandler(authLogoutHandler)
.permitAll()
.and()
.rememberMe();
http.headers().frameOptions().sameOrigin();
}
@Autowired
UserDetailsService userDetailsService;
@Override
@Autowired
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
System.out.println("*************** auth configure");
auth.userDetailsService(this.userDetailsService).passwordEncoder(passwordEncoder());
}
private static PasswordEncoder encoder;
@Bean
public PasswordEncoder passwordEncoder() {
if (encoder == null) {
encoder = new BCryptPasswordEncoder();
}
return encoder;
}
@Autowired
private AdminsDao adminsDao;
@Bean
UserDetailsService zUserDetailsService() {
return new UserDetailsService() {
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Admins admins = null;
try {
admins = adminsDao.findOneByUserName(username);
} catch (Exception e) {
e.printStackTrace();
}
if (admins == null) {
System.out.println("Login user does not exist===========");
throw new UsernameNotFoundException("could not find the user '" + username + "'");
} else {
boolean enabled = false;
admins = new Admins();
admins.setUserName("user");
admins.setPassword(passwordEncoder().encode("123456"));
admins.setStatus(1);
System.out.println("Login user exist===========" + admins.getUserName());
AuthUser u = new AuthUser(admins.getUserName(), admins.getPassword(), admins.getStatus() == 1, true, true, true,
AuthorityUtils.createAuthorityList("USER"));
u.setEntity(admins);
return u;
}
}
};
}
}
Это веб-приложение с весенней загрузкой иЯ хочу работать над весенним входом в систему безопасности.Я пробовал много вещей, но вход в систему не работает.Он даже не выполняет Userdetailservice.Когда я нажимаю на мой URL
http://localhost:8082/security/
, моя страница входа работает нормально.Затем я ввожу фиктивное имя пользователя и пароль и вводю логинЯ получил сообщение об ошибке:
exception: "org.springframework.web.HttpRequestMethodNotSupportedException"
message: "Request method 'POST' not supported"
path: "/security/login/"
status: 405**'
Я отправляю запрос через ajax.Пожалуйста, помогите и спасибо заранее.