Im getting this error even I have allow all required permission

here my securityConfigue

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@RequiredArgsConstructor
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    private final JwtAuthorizationFilter jwtAuthorizationFilter;
    private final CustomAccessDeniedHandler accessDeniedHandler;
    private final CustomAuthenticationEntryPoint authenticationEntryPoint;
    private final CustomUserDetailService userDetailService;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailService).passwordEncoder(passwordEncoder());
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf(csrf -> csrf.disable())
                .cors(cors -> cors.configurationSource(corsConfigurationSource()))
                .sessionManagement(management -> management.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
                .authorizeRequests(requests -> requests.antMatchers(AppConstants.PUBLIC_URLS).permitAll()
                        // "/api/v1/signup","/api/v1/login", 
                        //"/api/v1/verify-email/**",
                        //"/api/v1/forgot-password",
                        //"/api/v1/reset-password/**",
                        //"/images/**",
                        //"/uploads/**"
                        //"/chat"
                        .anyRequest().authenticated())
                .exceptionHandling(handling -> handling.accessDeniedHandler(accessDeniedHandler)
                        .authenticationEntryPoint(authenticationEntryPoint))
                .addFilterBefore(jwtAuthorizationFilter, UsernamePasswordAuthenticationFilter.class);

    }

    @Override @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    CorsConfigurationSource corsConfigurationSource() {
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.addAllowedOrigin("*");
        configuration.addAllowedHeader("*");
        configuration.addAllowedMethod("*");
        configuration.addExposedHeader("*");
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", configuration);
        return source;
    }
}

i want to try connect the server via websocket. here my client-side request

export class StompService {
  constructor() {
    // Initialize StompClient and configure debugging to null
    this.stompClient.debug = null;
    // Connect to the WebSocket server
    this.stompClient.connect({}, (): any => {
      // Successful connection callback
    });
  }

  // Create a WebSocket connection using SockJS
  socket = new SockJS('http://localhost:8080/stomp-endpoint');
  // Initialize the Stomp client using the WebSocket connection
  stompClient = Stomp.over(this.socket);

  // Subscribe to a specific topic and provide a callback function to handle incoming messages
  subscribe(topic: string, callback: any): Subscription {
    return this.stompClient.subscribe('/topic/' + topic, (frame: any): any => {
      // Parse the message body and pass it to the callback function
      callback(JSON.parse(frame.body));
    });
  }

  // Send a message to a specific application using Stomp
  send(app: string, data: any) {
    // Send the data as a JSON string to the specified application
    this.stompClient.send('/app/' + app, {}, JSON.stringify(data));
  }
}

WebSocket configuration is here

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer {

    /**
     * Register Stomp endpoints for WebSocket communication.
     *
     * @param registry The StompEndpointRegistry used to register WebSocket endpoints.
     */
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/stomp-endpoint")
                .setAllowedOriginPatterns("*")
                .withSockJS();
    }

    /**
     * Configure message broker options for WebSocket communication.
     *
     * @param registry The MessageBrokerRegistry used to configure message broker options.
     */
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableSimpleBroker("/topic");
        registry.setApplicationDestinationPrefixes("/app");
    }
}
  1. My WebSocketConfiguration class correct for enabling WebSocket communication using Spring WebSocket and STOMP.enter image description here
0

There are 0 answers