|
@ -0,0 +1,44 @@ |
|
|
|
|
|
package com.cristobalbernal.foro.seguridad; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
|
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
|
|
|
|
|
import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer; |
|
|
|
|
|
import org.springframework.security.core.userdetails.User; |
|
|
|
|
|
import org.springframework.security.core.userdetails.UserDetails; |
|
|
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService; |
|
|
|
|
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager; |
|
|
|
|
|
import org.springframework.security.web.SecurityFilterChain; |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
|
@EnableWebSecurity |
|
|
|
|
|
public class ConfigSeguridad { |
|
|
|
|
|
@Bean |
|
|
|
|
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { |
|
|
|
|
|
http |
|
|
|
|
|
.authorizeHttpRequests((requests) -> requests |
|
|
|
|
|
.requestMatchers("","/home","/","/registrar","/css/**","/image/**","/fonts/**","js/**","/postdetall").permitAll() |
|
|
|
|
|
.anyRequest().authenticated() |
|
|
|
|
|
) |
|
|
|
|
|
.formLogin((form) -> form |
|
|
|
|
|
.loginPage("/login") |
|
|
|
|
|
.permitAll() |
|
|
|
|
|
) |
|
|
|
|
|
.logout(LogoutConfigurer::permitAll); |
|
|
|
|
|
|
|
|
|
|
|
return http.build(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
|
public UserDetailsService userDetailsService() { |
|
|
|
|
|
UserDetails user = |
|
|
|
|
|
User.withDefaultPasswordEncoder() |
|
|
|
|
|
.username("tobal") |
|
|
|
|
|
.password("1234") |
|
|
|
|
|
.roles("USER") |
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
|
|
return new InMemoryUserDetailsManager(user); |
|
|
|
|
|
} |
|
|
|
|
|
} |