Commit df6c0198 by Patryk Czarnik

in Memory users

parent 74e47dcb
package sklep.model; package sklep.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.Email; import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Pattern;
...@@ -32,6 +33,7 @@ public class Customer { ...@@ -32,6 +33,7 @@ public class Customer {
private String city; private String city;
@OneToMany(mappedBy = "customer") @OneToMany(mappedBy = "customer")
@JsonIgnore
private Set<Order> orders = new LinkedHashSet<>(); private Set<Order> orders = new LinkedHashSet<>();
public String getCustomerEmail() { public String getCustomerEmail() {
......
...@@ -2,7 +2,11 @@ package sklep.security; ...@@ -2,7 +2,11 @@ package sklep.security;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.web.servlet.handler.HandlerMappingIntrospector; import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
...@@ -11,10 +15,23 @@ public class SecurityConfig { ...@@ -11,10 +15,23 @@ public class SecurityConfig {
@Bean @Bean
SecurityFilterChain configHttpSecurity(HttpSecurity httpSecurity, HandlerMappingIntrospector hmi) throws Exception { SecurityFilterChain configHttpSecurity(HttpSecurity httpSecurity, HandlerMappingIntrospector hmi) throws Exception {
httpSecurity.authorizeHttpRequests(auth -> auth.anyRequest().permitAll()) httpSecurity
.authorizeHttpRequests(auth -> auth
.anyRequest().authenticated())
.formLogin(Customizer.withDefaults())
// .httpBasic(Customizer.withDefaults())
.csrf(config -> config.disable()) .csrf(config -> config.disable())
.cors(config -> config.disable()); .cors(config -> config.disable());
return httpSecurity.build(); return httpSecurity.build();
} }
@Bean
InMemoryUserDetailsManager userDetailsService() {
UserDetails[] users = {
User.withUsername("ala").password("{noop}ala123").roles("manager", "worker").build(),
User.withUsername("ola").password("{noop}ola123").roles("worker").build(),
};
return new InMemoryUserDetailsManager(users);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment