Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在登录spring security和spring boot spring 4后重定向到同一页面_Java_Jquery_Spring_Spring Boot_Spring Security - Fatal编程技术网

Java 在登录spring security和spring boot spring 4后重定向到同一页面

Java 在登录spring security和spring boot spring 4后重定向到同一页面,java,jquery,spring,spring-boot,spring-security,Java,Jquery,Spring,Spring Boot,Spring Security,嗨,我是新来的春季保安 我不想在登录前访问主页我使用jquery使用登录web服务在使用spring security之前一切都进行得很顺利我无法用jquery管理它,我不知道该怎么办有人能给我建议吗 另外,如果我在ant macher中添加“/home”,一切正常,但我需要先登录 我看到了关于这个主题的所有stackoverflow问题,它们都是无用的 我的控制器 @ResponseBody @RequestMapping(value="/index/login",method = Reque

嗨,我是新来的春季保安

我不想在登录前访问主页我使用jquery使用登录web服务在使用spring security之前一切都进行得很顺利我无法用jquery管理它,我不知道该怎么办有人能给我建议吗 另外,如果我在ant macher中添加“/home”,一切正常,但我需要先登录 我看到了关于这个主题的所有stackoverflow问题,它们都是无用的

我的控制器

@ResponseBody
@RequestMapping(value="/index/login",method = RequestMethod.POST )
public Response login(@RequestBody LoginData loginData){
    System.out.println("Test Ahmed Test");
    Response response = new Response(loginRepo.validateLogin(loginData) , "home");
    System.out.println("Test Ahmed Test");
    return response;
}
我的安全配置

public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
DataSource dataSource;

@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
    auth.jdbcAuthentication().dataSource(dataSource)
            .usersByUsernameQuery("select username,password, enabled from twitter.login where username=?")
            .authoritiesByUsernameQuery("select username, role from twitter.user_roles where username=?");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable();

    http.formLogin()
            .loginPage("/index")
            .usernameParameter("username")
            .passwordParameter("password")
            .permitAll()
            .and()
            .authorizeRequests()
            .antMatchers(
            "/css/**",
            "/CSS/**",
            "/js/**",
            "/jquery/**",
            "/fonts/**",
            "/JS/**",
            "/img/**",
            "/webjars/**",
            "/**/favicon.ico",
            "/index/**").permitAll()
            .anyRequest().fullyAuthenticated()
            .antMatchers("/home").hasAuthority("ADMIN")
            .and().exceptionHandling().accessDeniedPage("/error/403");

}

}
我的jquery ajax函数

                $.ajax({

                contentType: 'application/json; charset=UTF-8',

                type : "POST",

                 cache : false,

                 crossDomain :false,

                url : url+'/login',

               data : JSON.stringify(formData),

              dataType : 'json',

             success : function(result) {

            console.log('hiiiiiiiiiii'+result.urlName)
            if(result.status == true){
                window.location.href= result.urlName;
            }else{
                alert("Error! Login Error Please Enter Vaild UserName and Password")
            }
            console.log(result);

        },

        error : function(e) {
            alert("Error!")
            console.log("ERROR: ", e);
        }
    });         
还有我的反应模式

private boolean status;

private String urlName;

public Response(boolean status , String urlName){
    this.status = status;
    this.urlName=urlName;
}

public boolean isStatus() {
    return status;
}

public void setStatus(boolean status) {
    this.status = status;
}

public String getUrlName() {
    return urlName;
}

public void setUrlName(String urlName) {
    this.urlName = urlName;
}
}