add login
This commit is contained in:
parent
8396e20146
commit
c510efa6c7
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -1,24 +1,26 @@
|
|||||||
package com.example.demo.speaker;
|
package com.example.demo.speaker;
|
||||||
|
|
||||||
|
|
||||||
|
import com.example.demo.speaker.controller.MVCController.UserSignupMvcController;
|
||||||
import com.example.demo.speaker.model.UserRole;
|
import com.example.demo.speaker.model.UserRole;
|
||||||
import com.example.demo.speaker.service.UserService;
|
import com.example.demo.speaker.service.UserService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@EnableGlobalMethodSecurity(securedEnabled = true)
|
@EnableMethodSecurity(
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
securedEnabled = true
|
||||||
|
)
|
||||||
|
public class SecurityConfiguration {
|
||||||
private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class);
|
private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class);
|
||||||
private static final String LOGIN_URL = "/login";
|
private static final String LOGIN_URL = "/login";
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
@ -36,34 +38,31 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
http.headers().frameOptions().sameOrigin().and()
|
http.headers().frameOptions().sameOrigin().and()
|
||||||
.cors().and()
|
.cors().and()
|
||||||
.csrf().disable()
|
.csrf().disable()
|
||||||
.authorizeRequests()
|
.authorizeHttpRequests()
|
||||||
.antMatchers(UserSignupMvcController.SIGNUP_URL).permitAll()
|
.requestMatchers(UserSignupMvcController.SIGNUP_URL).permitAll()
|
||||||
.antMatchers(HttpMethod.GET, LOGIN_URL).permitAll()
|
.requestMatchers(HttpMethod.GET, LOGIN_URL).permitAll()
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
.and()
|
.and()
|
||||||
.formLogin()
|
.formLogin()
|
||||||
.loginPage(LOGIN_URL).permitAll()
|
.loginPage(LOGIN_URL).permitAll()
|
||||||
|
.defaultSuccessUrl("/appointment", true)
|
||||||
.and()
|
.and()
|
||||||
.logout().permitAll();
|
.logout().permitAll();
|
||||||
|
return http.userDetailsService(userService).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
|
||||||
auth.userDetailsService(userService);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
public void configure(WebSecurity web) {
|
public WebSecurityCustomizer webSecurityCustomizer() {
|
||||||
web.ignoring()
|
return (web) -> web.ignoring()
|
||||||
.antMatchers("/css/**")
|
.requestMatchers("/css/**")
|
||||||
.antMatchers("/images/**")
|
.requestMatchers("/js/**")
|
||||||
.antMatchers("/js/**")
|
.requestMatchers("/templates/**")
|
||||||
.antMatchers("/templates/**")
|
.requestMatchers("/webjars/**");
|
||||||
.antMatchers("/webjars/**");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user