Я подключил мой проект Spring Boot с моей базой данных, созданный компонент пользовательского уровня, который принимает мои пользовательские данные, сравнивает его с данными данными и позволяет вам до конечной точки. Я создал конечную точку с именем /приборной панелью, где я хочу вернуть представление JSP, я держал его в папке WebApp с правильным именем. Проблема в том, что я не могу получить к нему доступ без аутентификации, даже если я разрешил это ... < /p>
Это мой класс контроллера < /p>
@Controller
public class PublicController {
@GetMapping("/dashboard")
public String dash(){
return "dashboard.jsp";
}
}
< /code>
Это класс конфигурации < /p>
@EnableWebSecurity
public class SecurityConfiguration {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> auth
// allow public endpoints
.requestMatchers("/dashboard").permitAll()
// everything else needs authentication
.anyRequest().authenticated()
)
// enable login form
.formLogin(Customizer.withDefaults())
.httpBasic(httpBasic -> httpBasic.disable());
return http.build();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
< /code>
Это userdetailsservice class < /p>
public class UserDetailsService implements org.springframework.security.core.userdetails.UserDetailsService {
@Autowired
private UserService userService;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User user=userService.getUserByUserName(username);
if(user!=null){
return org.springframework.security.core.userdetails.User.builder()
.username(user.getUserName())
.password(user.getPassword())
.roles(String.valueOf(user.getRoles()))
.build();
}
throw new UsernameNotFoundException("User Name Not found");
}```
I didn't create any UserManager. The authentication is working fine but showing login even if I have permitted the "/dashboard"
I tried localhost:8080/dashboard every time when I load the application 1st time it prompts me to Log in. all next end point hits are unauthenticated
How I can unauthenticate the permitted end points
Подробнее здесь: https://stackoverflow.com/questions/797 ... pring-boot