【问题标题】:Why always redirected to the access denied page?为什么总是重定向到拒绝访问页面?
【发布时间】:2016-12-22 09:57:32
【问题描述】:

应用程序 POST 提交未进入 spring REST 控制器。而不是根据提到的“安全配置”文件将该请求重定向到拒绝访问页面。 系统允许通过 spring 安全配置来自任何外部方的所有请求。
但总是将请求重定向到拒绝访问页面

.exceptionHandling().accessDeniedPage("/accessDenied");

angular2 服务

..........
.....
  addHotel(hotelDTO){
        let headers = new Headers({ 'Content-Type': 'application/json' });
        let options = new RequestOptions({ headers: headers });

        this._route_url = this._url+"/restHotelRegistration"
        var result = this._http.post(this._route_url, JSON.stringify(hotelDTO),options)
            .map(res => res.json());
        return result;

    }
......
... 

REST 控制器

  @RequestMapping(value = "restHotelRegistration", method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Void> restSaveHotel(@RequestBody HotelDTO hotelDTO) {
        System.out.println(">>>>> Fetching User with HotelName " + hotelDTO.getHotelName());
        System.out.println(">>>>> Fetching User with Phone " + hotelDTO.getPhone()); 

.......
........
        }

安全配置类

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests()
            .antMatchers("/**").permitAll()

    .and()
            .formLogin()
            .loginPage("/loginPage")
            .usernameParameter("username").passwordParameter("password")
            .successForwardUrl("/successLogin")
            .defaultSuccessUrl("/successLogin",true).permitAll()
            .loginProcessingUrl("/successLogin")
            .failureUrl("/invalidLogin")

            .and().csrf()
    .ignoringAntMatchers("/login", "/logout")
            .and().exceptionHandling().accessDeniedPage("/accessDenied")
    .and()
            .logout()
            .logoutUrl("/logout")
            .logoutSuccessUrl("/logout").permitAll();
}

==== 请求和响应 ====

================================================ ======================== JSON 对象

【问题讨论】:

  • 您是否尝试禁用 csrf 过滤器,甚至只是为了测试它是否正常工作?
  • 你说得对@jlumietu。禁用 csrf 过滤器后,它的工作原理。

标签: angular spring-security cross-domain spring-restcontroller


【解决方案1】:

禁用 csrf 过滤器后它的工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-24
    • 2017-02-21
    • 2012-03-03
    • 1970-01-01
    • 2020-06-19
    • 2021-10-18
    • 2016-12-23
    • 1970-01-01
    相关资源
    最近更新 更多