首页 > 解决方案 > Spring Security 和 i18n

问题描述

当我在页面上更改语言时,我无法访问。

没有.antMatchers("/login*").permitAll() 不起作用,但使用/login*几乎可以,但是当我在 URL 中提供“ http://localhost:8080/login?lang=estest123 ”或登录后与 i18n 无关的东西时,我收到 ??language.change_estest123? ?.

我尝试添加.regexMatchers("^login\\?lang=[a-zA-Z]{2}|^login\\?lang=_{1}[a-zA-Z]{2}").permitAll()但结果与/login*相同。

是否可以仅访问 i18n ?在其他情况下提供错误?或者也许是 i18n 的另一种配置方式,它允许以简单的方式提供这个?

我的网络安全配置:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests()
            .antMatchers("/resources/**", "/registration").permitAll()
            .and()
            .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
            .logout()
            .permitAll();
}

标签: springspring-securityinternationalization

解决方案


参数的存在是否会影响安全性的 url 解析?只需使用/loginand 它应该通过/loginand /login?lang=xxx

但是如果你想在你的配置中使用直接映射,你可以同时使用它们:.antMatchers("/login", "/login*").permitAll()


推荐阅读