gpt4 book ai didi

java - Vaadin 和 WebSecurity 中的 permitAll 问题 - 不工作

转载 作者:行者123 更新时间:2023-11-29 04:07:31 25 4
gpt4 key购买 nike

我对@Route 在 Vaadin 中的看法很少,现在我想添加安全性和一些登录。在我的 SecurityConfiguration 类中,我为 2 个 View 设置了 antMatchers.permitAll(),其余 View 设置为 Role ADMIN。但它没有像我认为的那样工作。它要求登录才能访问每个 View ,登录后无论用户具有什么角色,我都可以访问所有 View 。

我希望本教程对我有所帮助,但是没有登录就无法访问 View 。

Securing Your App With Spring Security

我的配置类:

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

private UserService userService;

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

@Autowired
public SecurityConfiguration(UserService userService) {
this.userService = userService;
}

@Autowired
private void configureAuth(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userService);
auth.inMemoryAuthentication()
.withUser("user")
.password(passwordEncoder().encode("user"))
.roles("USER");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().and()
.anonymous()
.and()
.authorizeRequests()
.antMatchers("/", "/login").permitAll()
.antMatchers("/recipe-manager", "/ingredient-manager").hasAnyRole("ADMIN")
.and()
.formLogin().loginPage("/login").permitAll()
.and()
.logout().logoutSuccessUrl("/")
.and()
.csrf().disable().cors().disable().headers().disable();
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(
"/VAADIN/**",
"/favicon.ico",
"/robots.txt",
"/manifest.webmanifest",
"/sw.js",
"/offline-page.html",
"/icons/**",
"/images/**",
"/frontend/**",
"/webjars/**",
"/h2-console/**",
"/frontend-es5/**", "/frontend-es6/**");
}
}

我的 View 有如下注释:

@Route("recipe-manager")
public class RecipeManagerView extends VerticalLayout
@Route("")
public class RecipeBrowserView extends VerticalLayout
@Route("login")
public class LoginView extends VerticalLayout
@Route("ingredient-manager")
public class IngredientManagerView extends VerticalLayout

我希望任何人都可以访问 RecipeBrowserViewLoginView,但只有登录用户才能访问 RecipeManagerView IngredientMangerView.

最佳答案

您不能对 Vaadin 路由使用来自 Spring Security 的基于路径的匹配。 Spring Security 根据请求路径进行匹配,而在 Vaadin 中从一个 View 到另一个 View 的导航作为内部请求中的元数据发送,该内部请求始终转到相同的硬编码路径。

相反,您可以在 Vaadin 提供的拦截器中实现您的访问控制逻辑。你可以看看https://vaadin.com/tutorials/securing-your-app-with-spring-security了解更多相关信息。

关于java - Vaadin 和 WebSecurity 中的 permitAll 问题 - 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57554363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com