首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring安全配置访问

Spring安全配置访问
EN

Stack Overflow用户
提问于 2017-03-21 18:19:12
回答 1查看 553关注 0票数 0

我正在配置Security中的端点访问。我想要做的是:

  1. 每个人都能获得资源
  2. 每个人都可以登录/注册。
  3. 只有经过身份验证的用户才能访问注销和所有其他映射的端点。

下面是我的配置,它满足了两个需求,并防止了未登录用户访问/logout。

代码语言:javascript
复制
http.authorizeRequests()
                .antMatchers("/register").permitAll()
                .antMatchers("/register/*").permitAll()
                .antMatchers("/favicon.ico").permitAll()
                .antMatchers("**/*.html").permitAll()
                .antMatchers("**/*.css").permitAll()
                .antMatchers("**/*.js").permitAll()
                .and()
                .formLogin().loginPage("/login").failureUrl("/login-error").defaultSuccessUrl("/")
                    
                .usernameParameter("username").passwordParameter("password")
                .and()
                    
                .logout().logoutSuccessUrl("/login").deleteCookies("JSESSIONID").logoutUrl("/logout");
EN

回答 1

Stack Overflow用户

发布于 2017-05-29 06:37:42

要确保对应用程序的请求需要对用户进行身份验证,请使用.anyRequest().authenticated()

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42935208

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档