//package org.egl_cepgl.pm.config;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity;
//import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
//import org.springframework.security.config.web.server.ServerHttpSecurity;
//import org.springframework.security.oauth2.jwt.JwtDecoder;
//import org.springframework.security.oauth2.jwt.JwtDecoders;
//import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter;
//import org.springframework.security.web.server.SecurityWebFilterChain;
//import org.springframework.web.cors.CorsConfiguration;
//
//import java.util.List;
//
//@Slf4j
//@Configuration
//@EnableWebFluxSecurity
//@EnableReactiveMethodSecurity
//public class SecurityConfigOld
//{
//    @Value("${spring.security.oauth2.resourceserver.jwt.issuer-uri}")
//    String ISSUER_URI;
//
//    @Value("${keycloak.client}")
//    String KC_CLIENT_ID;
//
//    @Bean
//    public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http)
//    {
//        http.cors()
//                .configurationSource(request -> {
//                    var cors = new CorsConfiguration();
//                    cors.setAllowedOrigins(List.of("http://localhost:4500"));
//                    cors.setAllowedMethods(List.of("GET", "POST", "OPTIONS", "PUT", "DELETE"));
//                    cors.setAllowedHeaders(List.of("*"));
//                    cors.setAllowCredentials(true);
//                    return cors;
//                }).
//                and()
//                .authorizeExchange()
//                //ALLOWING REGISTER API FOR DIRECT ACCESS
//                .pathMatchers(
//                        "/api/**"
//                        //"/user-service/api/users/all"
//                ).hasRole("ADMIN")
////                .pathMatchers(
////                        "/rsocket/**"
////                ).permitAll()
//                //ALL OTHER APIS ARE AUTHENTICATED
//                .anyExchange().authenticated()
//                .and()
//                .csrf().disable()
//                .oauth2Login()
//                .and()
//                .oauth2ResourceServer(oauth2 -> oauth2
//                        .jwt(jwt -> jwt.jwtAuthenticationConverter(jwtAuthenticationConverter())) // Configure JWT authentication
//                )
//                .jwt();
//        return http.build();
//    }
//
//    @Bean
//    public JwtAuthenticationConverter jwtAuthenticationConverter() {
//        JwtAuthenticationConverter converter = new JwtAuthenticationConverter();
//        // Replace "your-client-id" with the actual client ID of your resource server
//        converter.setJwtGrantedAuthoritiesConverter(new CustomJwtGrantedAuthoritiesConverter(KC_CLIENT_ID));
//        return converter;
//    }
//
//    @Bean
//    public JwtDecoder jwtDecoder()
//    {
//        return JwtDecoders.fromIssuerLocation(ISSUER_URI);
//    }
//}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
