当前位置: 首页 > 知识库问答 >
问题:

Spring Boot 2.0.2 Spring Security如何禁用两个endpoint的自定义表单登录

程亦
2023-03-14

编辑:

在尝试了几天的各种安全配置更改之后,我把。permitall()放在每个应该授权/验证任何请求的endpoint上。但即便如此,尽管我可以自由地“浏览”任何页面而无需验证,但我的设备客户端仍然无法向其正常的应用程序endpoint提交PUT请求。

所以现在的问题是,为什么远程客户机可以成功地向运行在1.5.4 Spring Boot版本上的应用程序提交PUT请求,而当“相同的应用程序”运行在Spring Boot 2.0.2时却不能?

我得到了一个成功的“健康检查”响应(“启动并像往常一样运行...”)当我用浏览器的GET请求击中相同的“设备”endpoint时。但是客户机设备在尝试放置时只得到err_connection_delection(或类似的)。

/编辑

这个问题与我几天前问过的Web套接字迁移有关,但Web套接字部分被证明是一个转移注意力的问题。

    springBootVersion = '2.0.2.RELEASE'
    springVersion = '5.0.13.RELEASE'
    springSecurityVersion = '5.2.1.RELEASE'
@Configuration
@EnableWebSecurity
//@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
@Order(1)// highest priority
class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    SimpleAuthenticationManager sam;

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        // false means go to original destination page after login success
        boolean alwaysRedirectToSuccessUrl = false;

        http.headers().cacheControl().disable();
        http.headers().frameOptions().sameOrigin();
        http.csrf().ignoringAntMatchers("/input/auth/**");// ignoring WebSocket endpoints (secured by other means)
        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.ALWAYS);
        http.authorizeRequests()
            .antMatchers('/widgetInfo/**', '/stats', '/errorCodes').hasAuthority('USER').anyRequest().fullyAuthenticated()
        http.formLogin()
            .loginPage('/widgetInfo/login')
            .loginProcessingUrl("/widgetInfo/fooInfo")
            .defaultSuccessUrl("/widgetInfo/fooInfo", alwaysRedirectToSuccessUrl)
            .failureUrl("/widgetInfo/login?status=LOGIN_FAILURE").permitAll()
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers('/webjars/**', '/static/**', '/css/**', '/js/**', '/input/**');
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.parentAuthenticationManager(sam)
    }
}
@Configuration
@EnableWebSecurity
@Order(11)// lowest priority
class LenientWebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.csrf().ignoringAntMatchers("/input/auth/**");// ignoring WebSocket endpoints (secured by other means)
        http.authorizeRequests().antMatchers('/input', 'input/auth', '/input/**').permitAll()

    }
}

但是它不起作用,/inputendpoint还不能自由访问。问题是什么?

如果我交换@Order,那么我的自定义表单登录就不会发生任何事情。

共有1个答案

习斌
2023-03-14

在这里回答只是为了给可能在这里着陆的未来用户闭环。

问题是Spring Boot1.5.4可以接受“HTTP1.1”请求,而Spring Boot2.0.2不能。

我们的应用程序位于F5设备后面,如果/当应用程序“HealthCheck”请求失败时,该设备拒绝入站请求。这是在1.5.4中工作的“HealthCheck”请求

GET /myGateway/input HTTP/1.1\r\n
GET /myGateway/input \r\n
 类似资料:
  • 我学习了spring教程“SSOwith OAuth2:Angular JS和spring Security Part V”。 2016-05-18 11:14:53.667 DEBUG 22312---[nio-9999-exec-9]O.security.web.filterchainproxy:/login位于附加筛选器链中14的位置5;正在激发筛选器:“logoutfilter”2016-

  • “入门Spring Security and Angular JS系列”中的oauth2 JWT项目有一个自定义登录名。为自定义登录页面添加相同的代码到oauth2-vanilla项目失败,因为登录响应中的授权代码始终为空。我还尝试将Sparklr2(https://github.com/spring-projects/spring-security-oauth/tree/master/sampl

  • servlet堆栈(web)中的Spring Security性允许您在OAuth2授权代码授予流中定制OAuth2登录重定向endpoint基uri(如这里给出的)。我正尝试用Spring WebFlux对反应堆栈做同样的操作。这里的github问题提到了Oauth2LoginSpec上的authorizationRequestResolver和authenticationMatcher,它们可

  • 根据,我使用基本和基于表单的身份验证配置了Spring Security。 我希望下的endpoint不要使用基于表单的安全性。之外的其他endpoint应使用基于表单的登录。我想要一个响应,发送给那些没有在下提供凭据的endpoint的任何调用。 更新:感谢卢克·泰勒在下面的评论,我想出了以下解决方案。 注意:此技术仅适用于Spring Security 3.1。 首先,我挑出。我们从不创建会话

  • 在Spring Security中使用自定义JSP登录页面相当容易。不过,我们的应用程序是基于Vaadin的,我不想使用JSP登录页面。我想要的是作为Vaadin小部件创建的自定义高级登录窗口。 从技术上讲,我可以使用Vaadin的FormLayout和名称字段,比如j_用户名和j_密码……但这是Java类,而不是JSP文件,那么我在http Spring Security元素中指定了什么?我的意