Skip to content

Commit

Permalink
Apply hilla route protection on Spring config (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
cromoteca authored Apr 16, 2024
1 parent 5ac9643 commit 658726a
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

import com.vaadin.flow.spring.security.VaadinWebSecurity;
import com.vaadin.hilla.route.RouteUtil;

@EnableWebSecurity
@Configuration
public class SecurityConfig extends VaadinWebSecurity {
private final RouteUtil routeUtil;

public SecurityConfig(RouteUtil routeUtil) {
this.routeUtil = routeUtil;
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(registry -> {
registry.requestMatchers(new AntPathRequestMatcher("/")).permitAll();
registry.requestMatchers(routeUtil::isRouteAllowed).permitAll();
});
super.configure(http);
setLoginView(http, "/login", "/");
Expand All @@ -46,4 +53,4 @@ public UserDetailsService users() {
.build();
return new InMemoryUserDetailsManager(user, admin);
}
}
}

0 comments on commit 658726a

Please sign in to comment.