首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >允许URL中的语言参数(Spring / Security)

允许URL中的语言参数(Spring / Security)
EN

Stack Overflow用户
提问于 2021-08-23 09:59:07
回答 1查看 451关注 0票数 0

你好亲爱的社区,

关于我的目标的细节:

实际结果:

  • 国际化运作得很好

然后我增加了安全性:

代码语言:javascript
复制
http.authorizeRequests()

    // Restrict Endpoints
    .antMatchers("/login/**").hasAnyRole("admin", "member")

    // Allow Forms
    .antMatchers("/member/**").permitAll()

    // Allow Resources
    .antMatchers("/js/**").permitAll()
    .antMatchers("/css/**").permitAll()

    // Deny All
    .anyRequest().authenticated();
}

由于.anyRequest().authenticated(),根路径上的请求(如/?lang=de )将触发身份验证。

我试过的是:

http.authorizeRequests()

代码语言:javascript
复制
    // Restrict Endpoints
    .antMatchers("/login/**").hasAnyRole("admin", "member")

    // Allow Forms
    .antMatchers("/member/**").permitAll()

    // Allow Resources
    .antMatchers("/js/**").permitAll()
    .antMatchers("/css/**").permitAll()

    // Trick to allow Internationalization
    .antMatchers("/*").permitAll()

    // Deny All
    .anyRequest().authenticated();
}

我添加了可以工作的.antMatchers("/*").permitAll(),但是它允许根路径上的很多资源。我的目标是只允许没有身份验证的/?lang=de

有什么机会吗?

我研究过的资源,但无法与之相适应:

好样看待

OtenMoten

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-23 10:19:46

终于起作用了。

上面我告诉过我不适合上面提到的堆栈溢出链接,但是它是有效的。

我补充说:

.regexMatchers("/.*lang=.*").permitAll()

http.authorizeRequests()

代码语言:javascript
复制
// Restrict Endpoints
.antMatchers("/login/**").hasAnyRole("admin", "member")

// Allow Forms
.antMatchers("/member/**").permitAll()

// Allow Resources
.antMatchers("/js/**").permitAll()
.antMatchers("/css/**").permitAll()

.regexMatchers("/.*lang=.*").permitAll()

// Deny All
.anyRequest().authenticated();

}

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

https://stackoverflow.com/questions/68890628

复制
相关文章

相似问题

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