Skip to content

Commit

Permalink
* Path Matcher
Browse files Browse the repository at this point in the history
* Security Config
  • Loading branch information
SteKoe committed Oct 28, 2022
1 parent c540e94 commit bc111ca
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
successHandler.setDefaultTargetUrl(this.adminContextPath + "/");

http.authorizeHttpRequests((authorizeRequests) -> authorizeRequests
.requestMatchers(this.adminContextPath + "/assets/**").permitAll()
.requestMatchers(this.adminContextPath + "/login").permitAll().anyRequest().authenticated())
.requestMatchers(new AntPathRequestMatcher(this.adminContextPath + "/assets/**")).permitAll()
.requestMatchers(new AntPathRequestMatcher(this.adminContextPath + "/login")).permitAll().anyRequest().authenticated())
.formLogin((formLogin) -> formLogin.loginPage(this.adminContextPath + "/login")
.successHandler(successHandler))
.logout((logout) -> logout.logoutUrl(this.adminContextPath + "/logout"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
successHandler.setDefaultTargetUrl(this.adminContextPath + "/");

http.authorizeHttpRequests((authorizeRequests) -> authorizeRequests
.requestMatchers(this.adminContextPath + "/assets/**").permitAll()
.requestMatchers(this.adminContextPath + "/login").permitAll().anyRequest().authenticated())
.requestMatchers(new AntPathRequestMatcher(this.adminContextPath + "/assets/**")).permitAll()
.requestMatchers(new AntPathRequestMatcher(this.adminContextPath + "/login")).permitAll().anyRequest().authenticated())
.formLogin((formLogin) -> formLogin.loginPage(this.adminContextPath + "/login")
.successHandler(successHandler))
.logout((logout) -> logout.logoutUrl(this.adminContextPath + "/logout"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
successHandler.setDefaultTargetUrl(this.adminServer.path("/"));

http.authorizeHttpRequests((authorizeRequests) -> authorizeRequests
.requestMatchers(this.adminServer.path("/assets/**")).permitAll()
.requestMatchers(this.adminServer.path("/login")).permitAll().anyRequest().authenticated())
.requestMatchers(new AntPathRequestMatcher(this.adminServer.path("/assets/**"))).permitAll()
.requestMatchers(new AntPathRequestMatcher(this.adminServer.path("/login"))).permitAll().anyRequest().authenticated())
.formLogin((formLogin) -> formLogin.loginPage(this.adminServer.path("/login"))
.successHandler(successHandler))
.logout((logout) -> logout.logoutUrl(this.adminServer.path("/logout")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
successHandler.setDefaultTargetUrl(this.adminServer.path("/"));

http.authorizeHttpRequests((authorizeRequests) -> authorizeRequests
.requestMatchers(this.adminServer.path("/assets/**")).permitAll() // <1>
.requestMatchers(this.adminServer.path("/variables.css")).permitAll()
.requestMatchers(this.adminServer.path("/actuator/info")).permitAll()
.requestMatchers(this.adminServer.path("/actuator/health")).permitAll()
.requestMatchers(this.adminServer.path("/login")).permitAll().anyRequest().authenticated() // <2>
.requestMatchers(new AntPathRequestMatcher(this.adminServer.path("/assets/**"))).permitAll() // <1>
.requestMatchers(new AntPathRequestMatcher(this.adminServer.path("/variables.css"))).permitAll()
.requestMatchers(new AntPathRequestMatcher(this.adminServer.path("/actuator/info"))).permitAll()
.requestMatchers(new AntPathRequestMatcher(this.adminServer.path("/actuator/health"))).permitAll()
.requestMatchers(new AntPathRequestMatcher(this.adminServer.path("/login"))).permitAll().anyRequest().authenticated() // <2>
).formLogin(
(formLogin) -> formLogin.loginPage(this.adminServer.path("/login")).successHandler(successHandler).and() // <3>
).logout((logout) -> logout.logoutUrl(this.adminServer.path("/logout"))).httpBasic(Customizer.withDefaults()) // <4>
Expand All @@ -80,8 +80,12 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// Required to provide UserDetailsService for "remember functionality"
@Bean
public InMemoryUserDetailsManager userDetailsService() {
UserDetails user = User.withDefaultPasswordEncoder().username(security.getUser().getName())
.password("{noop}" + security.getUser().getPassword()).roles("USER").build();
User.UserBuilder users = User.withDefaultPasswordEncoder();
UserDetails user = users
.username(security.getUser().getName())
.password(security.getUser().getPassword())
.roles("USER")
.build();
return new InMemoryUserDetailsManager(user);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
successHandler.setDefaultTargetUrl(this.adminServer.path("/"));

http.authorizeHttpRequests((authorizeRequests) -> authorizeRequests
.requestMatchers(this.adminServer.path("/assets/**")).permitAll()
.requestMatchers(this.adminServer.path("/login")).permitAll().anyRequest().authenticated())
.requestMatchers(new AntPathRequestMatcher(this.adminServer.path("/assets/**"))).permitAll()
.requestMatchers(new AntPathRequestMatcher(this.adminServer.path("/login"))).permitAll().anyRequest().authenticated())

.formLogin((formLogin) -> formLogin.loginPage(this.adminServer.path("/login"))
.successHandler(successHandler))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
successHandler.setDefaultTargetUrl(this.adminServer.path("/"));

http.authorizeHttpRequests((authorizeRequests) -> authorizeRequests
.requestMatchers(this.adminServer.path("/assets/**")).permitAll()
.requestMatchers(this.adminServer.path("/login")).permitAll().anyRequest().authenticated())
.requestMatchers(new AntPathRequestMatcher(this.adminServer.path("/assets/**"))).permitAll()
.requestMatchers(new AntPathRequestMatcher(this.adminServer.path("/login"))).permitAll().anyRequest().authenticated())
.formLogin((formLogin) -> formLogin.loginPage(this.adminServer.path("/login"))
.successHandler(successHandler))
.logout((logout) -> logout.logoutUrl(this.adminServer.path("/logout")))
Expand Down

0 comments on commit bc111ca

Please sign in to comment.