Цепочка фильтров безопасности не работает в Spring SecurityJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Цепочка фильтров безопасности не работает в Spring Security

Сообщение Anonymous »

Я не могу использовать конечные точки пружинного приложения. Это дает мне 403 запретный ответ, кроме одной конечной точки. Я реализовал шестигранную архите. Все потребности удовлетворяются портами. Настроил это в конфигурации безопасности и добавленный поставщик AUTH в цепочке безопасности. За исключением конечной точки /auth /приветствуюсь, я получаю 403 запрещенную ошибку для других конечных точек. < /P>
@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();

authProvider.setUserDetailsService(customUserDetailsService);
authProvider.setPasswordEncoder(passwordEncoder());

return authProvider;
}

@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authConfig) throws Exception {
return authConfig.getAuthenticationManager();
}

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception{
return httpSecurity
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests((auth) -> auth
.anyRequest().permitAll())
.build();

}

// Контроллер
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AuthController {

private final RegisterRequestToCommandMapper registerRequestToCommandMapper;
private final LoginRequestToCommandMapper loginRequestToCommandMapper;
private final AuthUseCase authUseCase;

@GetMapping("/Welcome")
public ResponseEntity sayWelcome(){
return ResponseEntity
.status(HttpStatus.OK)
.body("Welcome");
}

@PostMapping("/login")
public ResponseEntity login(@RequestBody LoginRequest request){
LogginResponse logginResponse = authUseCase.login(loginRequestToCommandMapper.toLogginCommand(request));
return ResponseEntity
.status(HttpStatus.OK)
.body(logginResponse);
}

@PostMapping("/register")
public ResponseEntity register(@RequestBody RegisterRequest request){
authUseCase.register(registerRequestToCommandMapper.toRegisterCommand(request));
return ResponseEntity
.status(HttpStatus.CREATED)
.build();
}

}


// Authservice
@Service
@RequiredArgsConstructor
public class AuthUseCaseService implements AuthUseCase {

private final UserRepository userRepository;
private final AuthenticationProvider authenticationProvider;
private final TokenProvider tokenProvider;
private final PasswordEncoderProvider passwordEncoderProvider;

@Override
public void register(RegisterCommand command) {
User userFromRepo = userRepository.findByUserName(command.getUsername()).get();
if(userFromRepo != null){
throw new UsernameAlreadyExistsException(command.getUsername());
}

userRepository.save(User.of(command.getUsername(),command.getFullname(),passwordEncoderProvider.encode(command.getPassword())));
}

@Override
public LogginResponse login(LogginCommand command) {
AuthenticatedUser authenticatedUser = authenticationProvider.authenticate(command);
String token = tokenProvider.getToken(authenticatedUser);
LogginResponse logginResponse = new LogginResponse();
logginResponse.setUsername(authenticatedUser.username());
logginResponse.setToken(token);
logginResponse.setRoles(authenticatedUser.roles());
return logginResponse;
}
}



Подробнее здесь: https://stackoverflow.com/questions/797 ... g-security
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»