content: /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package com.alipay.api.config.filter;/*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import jakarta.annotation.Resource;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
  
  @Configuration
  public class WebMvcConfig implements WebMvcConfigurer {
  
      @Resource
      private PermissionInterceptor permissionInterceptor;
      @Resource
      private LocaleChangeInterceptor localeChangeInterceptor;
      @Resource
      private LangContextInterceptor langContextInterceptor;
      @Resource
      private OpenApiInterceptor openApiInterceptor;
  
      @Override
      public void addInterceptors(InterceptorRegistry registry) {
          // 添加国际化拦截器
          registry.addInterceptor(localeChangeInterceptor);
          // 添加语言上下文拦截器
          registry.addInterceptor(langContextInterceptor);
          // 添加OpenApi拦截器，用于检测@OpenApi注解
          registry.addInterceptor(openApiInterceptor).addPathPatterns("/api/**");
          // 添加权限拦截器，但OpenApi拦截器已经处理过的请求将被放行
          registry.addInterceptor(permissionInterceptor).addPathPatterns("/api/**")
                  .excludePathPatterns("/api/agent/**")
                  .excludePathPatterns("/api/user/queryUserInfo")
                  .excludePathPatterns("/api/user/login")
                  .excludePathPatterns("/api/user/register")
                  .excludePathPatterns("/api/tenant/checkInviteCode")
                  .excludePathPatterns("/api/open/v1/**");
      }
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
      }
  }