Не могу получить Spring Boot, чтобы использовать страницу пользовательского входа в систему ⇐ JAVA
-
Anonymous
Не могу получить Spring Boot, чтобы использовать страницу пользовательского входа в систему
Я пытаюсь заставить Spring Boot использовать страницу пользовательского входа в систему, но ничто из того, что я пробовал до сих пор, не имело никакого успеха. Файл. < /p>
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-tomcat
provided
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-data-jpa
jar
org.springframework.security
spring-security-config
jar
org.springframework.security
spring-security-web
jar
org.springframework.data
spring-data-jpa
jar
jakarta.persistence
jakarta.persistence-api
jar
org.mariadb.jdbc
mariadb-java-client
3.5.3
org.springframework.boot
spring-boot-starter-security
org.thymeleaf.extras
thymeleaf-extras-springsecurity6
3.1.3.RELEASE
< /code>
import PollardCreations.Tjabal.Services.StudentDetailsService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
/**
*
* @author
*/
@Configuration
@EnableWebSecurity
public class SecurityConfig
{
@Bean
public PasswordEncoder passwordEncoder()
{
return new BCryptPasswordEncoder();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception
{
return http
.cors(Customizer.withDefaults())
.authorizeHttpRequests
(auth -> auth
.requestMatchers("style.css").permitAll()
.requestMatchers("/signInPage.html").permitAll()
.requestMatchers("/error.html").permitAll()
.anyRequest().authenticated()
)
.formLogin(form -> form
.loginPage("/signInPage.html").permitAll()
// .loginProcessingUrl("/SignInPage")
.defaultSuccessUrl("/signedInStudentAddSession.html", true)
.permitAll()
// .failureUrl("/SignInPage?error=true")
)
.logout(logout -> logout
.logoutSuccessUrl("/SignInPage?logout")
)
.build();
}
@Bean
public DaoAuthenticationProvider authenticationProvider
(StudentDetailsService userDetailsService, PasswordEncoder passwordEncoder)
{
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setUserDetailsService(userDetailsService);
provider.setPasswordEncoder(passwordEncoder);
return provider;
}
}
< /code>
Пожалуйста, будьте добры, я пытался разобраться в себе самостоятельно без успеха
Я знаю, что моя реализация кода, вероятно, немного беспорядочно
Я предполагаю, что я либо что -то, что должно быть очевидным, либо я не настраивал что -то правильно < /p>
.>
Подробнее здесь: https://stackoverflow.com/questions/796 ... login-page
Я пытаюсь заставить Spring Boot использовать страницу пользовательского входа в систему, но ничто из того, что я пробовал до сих пор, не имело никакого успеха. Файл. < /p>
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-tomcat
provided
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-data-jpa
jar
org.springframework.security
spring-security-config
jar
org.springframework.security
spring-security-web
jar
org.springframework.data
spring-data-jpa
jar
jakarta.persistence
jakarta.persistence-api
jar
org.mariadb.jdbc
mariadb-java-client
3.5.3
org.springframework.boot
spring-boot-starter-security
org.thymeleaf.extras
thymeleaf-extras-springsecurity6
3.1.3.RELEASE
< /code>
import PollardCreations.Tjabal.Services.StudentDetailsService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
/**
*
* @author
*/
@Configuration
@EnableWebSecurity
public class SecurityConfig
{
@Bean
public PasswordEncoder passwordEncoder()
{
return new BCryptPasswordEncoder();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception
{
return http
.cors(Customizer.withDefaults())
.authorizeHttpRequests
(auth -> auth
.requestMatchers("style.css").permitAll()
.requestMatchers("/signInPage.html").permitAll()
.requestMatchers("/error.html").permitAll()
.anyRequest().authenticated()
)
.formLogin(form -> form
.loginPage("/signInPage.html").permitAll()
// .loginProcessingUrl("/SignInPage")
.defaultSuccessUrl("/signedInStudentAddSession.html", true)
.permitAll()
// .failureUrl("/SignInPage?error=true")
)
.logout(logout -> logout
.logoutSuccessUrl("/SignInPage?logout")
)
.build();
}
@Bean
public DaoAuthenticationProvider authenticationProvider
(StudentDetailsService userDetailsService, PasswordEncoder passwordEncoder)
{
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setUserDetailsService(userDetailsService);
provider.setPasswordEncoder(passwordEncoder);
return provider;
}
}
< /code>
Пожалуйста, будьте добры, я пытался разобраться в себе самостоятельно без успеха
Я знаю, что моя реализация кода, вероятно, немного беспорядочно
Я предполагаю, что я либо что -то, что должно быть очевидным, либо я не настраивал что -то правильно < /p>
.>
Подробнее здесь: https://stackoverflow.com/questions/796 ... login-page