当前位置: 首页 > news >正文

红桥网站建设网站怎么做图片转链

红桥网站建设,网站怎么做图片转链,住房和城乡建设部网站 绿地,网站微场景代码本篇文章要实现的功能#xff1a; 1.集成swagger2.集成swagger登录功能#xff0c;访问 /swagger-ui.html需要先登录3.集成安全认证#xff0c;访问接口时携带header 请求接口时携带了上一步输入的header参数和值 1.集成swagger jdk11#xff0c;SpringBoot 2.7.13 pom…本篇文章要实现的功能 1.集成swagger2.集成swagger登录功能访问 /swagger-ui.html需要先登录3.集成安全认证访问接口时携带header 请求接口时携带了上一步输入的header参数和值 1.集成swagger jdk11SpringBoot 2.7.13 pom.xml依赖swagger2.10.5 dependencygroupIdio.springfox/groupIdartifactIdspringfox-swagger2/artifactIdversion2.10.5/version /dependency dependencygroupIdio.springfox/groupIdartifactIdspringfox-swagger-ui/artifactIdversion2.10.5/version /dependency dependencygroupIdio.springfox/groupIdartifactIdspringfox-spring-webmvc/artifactIdversion2.10.5/version /dependencyapplication.yml swagger:enable: true #是否开启swaggerbasic:enable: true #是否开启登录认证username: adminpassword: admin2.集成swagger登录功能访问 /swagger-ui.html需要先登录 新建 Swagger2Config import com.zypcy.mono.interceptor.SwaggerInterceptor; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.handler.MappedInterceptor; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ParameterBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.schema.ModelRef; import springfox.documentation.service.*; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;import java.util.ArrayList; import java.util.List;Configuration EnableWebMvc EnableSwagger2WebMvc ConditionalOnProperty(name {swagger.enable},havingValue true,matchIfMissing false ) public class Swagger2Config implements WebMvcConfigurer {Value(${spring.profiles.active})private String active;Value(${swagger.basic.username:admin})private String username;Value(${swagger.basic.password:admin})private String password;private String basePackage com.zypcy.mono.controller;/*** 开放swagger-ui.html资源* param registry*/Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler(/**).addResourceLocations(classpath:/static/);registry.addResourceHandler(swagger-ui.html).addResourceLocations(classpath:/META-INF/resources/);registry.addResourceHandler(/webjars/**).addResourceLocations(classpath:/META-INF/resources/webjars/);WebMvcConfigurer.super.addResourceHandlers(registry);}/* 在此处配置拦截器,要不然拦不到swagger的静态资源 */BeanConditionalOnProperty(name swagger.basic.enable, havingValue true)public MappedInterceptor getMappedInterceptor() {return new MappedInterceptor(new String[]{/swagger-ui.html, /v2/api-docs, /webjars/**}, new SwaggerInterceptor(username, password));}Beanpublic Docket createRestApi() {return new Docket(DocumentationType.SWAGGER_2).enable(!prod.equals(active)).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage(basePackage)).paths(PathSelectors.any()).build().securitySchemes(securitySchemes()).securityContexts(securityContexts());}private ApiInfo apiInfo() {return new ApiInfoBuilder().title(Mono API 接口文档).description(Mono REST API 接口文档).termsOfServiceUrl().contact(new Contact(zhuyu, https://zhuyu.blog.csdn.net, 645906265qq.com)).license(Mono License Version 2.0).licenseUrl(http://www.xxx.xxx/licenses/LICENSE-2.0).version(1.0).build();}//3.集成安全认证访问接口时携带headerprivate ListSecurityScheme securitySchemes() {ListSecurityScheme res new ArrayList();res.add(new ApiKey(AppId, AppId, header));res.add(new ApiKey(Authorization, Authorization, header));return res;}private ListSecurityContext securityContexts() {ListSecurityContext res new ArrayList();res.add(SecurityContext.builder().securityReferences(defaultAuth()).forPaths(PathSelectors.regex(/.*)).build());return res;}private ListSecurityReference defaultAuth() {ListSecurityReference res new ArrayList();AuthorizationScope authorizationScope new AuthorizationScope(global, accessEverything);AuthorizationScope[] authorizationScopes new AuthorizationScope[1];authorizationScopes[0] authorizationScope;res.add(new SecurityReference(AppId, authorizationScopes));res.add(new SecurityReference(Authorization, authorizationScopes));return res;}/*** 添加header调用代码this.header(x-request-info, string, false, appId101;tokena256f4c4f38a76115355d2d039e2882e;)* param name* param type* param required* param defaultValue* return*/private Parameter header(String name, String type, boolean required, String defaultValue) {ParameterBuilder param new ParameterBuilder();return param.name(name).modelRef(new ModelRef(type)).parameterType(header).defaultValue(defaultValue).required(required).build();}}创建拦截器 SwaggerInterceptor import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.util.AntPathMatcher; import org.springframework.util.FileCopyUtils; import org.springframework.web.servlet.HandlerInterceptor;import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.util.Base64;/*** Description:* Author: zhuyu* Date: 2023/11/22 20:44*/ public class SwaggerInterceptor implements HandlerInterceptor {private String username;private String password;public SwaggerInterceptor(String username, String password) {this.username username;this.password password;}Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {String authorization request.getHeader(Authorization);boolean isAuthSuccess httpBasicAuth(authorization);if (!isAuthSuccess) {response.setCharacterEncoding(utf-8);response.setStatus(401);response.setHeader(WWW-authenticate, Basic realm\Realm\);try (PrintWriter writer response.getWriter()) {writer.print(Forbidden, unauthorized user);}}return isAuthSuccess;}public boolean httpBasicAuth(String authorization) throws IOException {if (authorization ! null authorization.split( ).length 2) {String userAndPass new String(Base64.getDecoder().decode((authorization.split( )[1])));String username userAndPass.split(:).length 2 ? userAndPass.split(:)[0] : null;String password userAndPass.split(:).length 2 ? userAndPass.split(:)[1] : null;if (this.username.equals(username) this.password.equals(password)) {return true;}}return false;}Overridepublic void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {String uri request.getRequestURI();AntPathMatcher pathMatcher new AntPathMatcher();if (!pathMatcher.match(/swagger-ui.html, uri) !pathMatcher.match(/webjars/**, uri)) {response.setStatus(404);return;}ResourcePatternResolver resolver new PathMatchingResourcePatternResolver();Resource[] resources resolver.getResources(classpath:/META-INF/resources uri);if (resources ! null resources.length 0) {FileCopyUtils.copy(resources[0].getInputStream(), response.getOutputStream());} else {response.setStatus(404);}} }
http://www.yutouwan.com/news/397456/

相关文章:

  • 网站群系统建设长期做网站应该购买稳定的空间
  • 站内免费推广的方式有哪些制作自己的个人网站
  • 可以把网站服务器放在哪里做建设网站的活的兼职
  • flash网站免费源码带后台成都都网站建设
  • 重庆网站建设公司招聘广州金融网站设计
  • 大型网站seowordpress 读取最新文章
  • 昆山规划与建设局网站公司网站开发排名
  • 如何做网站更新企业文化宣传
  • 广东网站建设电话咨询专门型网站
  • 手表到哪个网站买apple官网
  • seo网站结构如何优化阿里巴巴官网下载手机版
  • 电脑软件下载官方网站旅游网站设计风格
  • 怎么查看网站是否被百度收录做网站建设的企业
  • 模板网免费百度seo排名技术必不可少
  • 自己做网站需要服务器吗slider revolution wordpress
  • 茂名专业网站建设公司平面设计最新招聘信息
  • seo推广需要网站吗酷炫给公司网站欣赏
  • 余姚市城乡建设局网站网站后台基本功能
  • 自己动手做衣服的网站徐州公共资源建设交易平台
  • 怎么用ppt做网站企业门户网站模板
  • 3d网页游戏排行优化外包服务公司
  • 觉得自己做的网站土怎么办手机之家对比
  • 网站联系我们页面设计专业做企业网站
  • 网站设计电商运营做一个静态网站需要多少钱
  • 网站的设计与维护摘要建设银行网站点不进去了怎么办
  • 怎么做网络销售的网站logo标志设计
  • 为学校网站做网站推广策划德阳建设机械网站
  • 宜昌做网站公司有哪些网站做网站模板平台
  • 海城网站制作安卓软件开发培训
  • 沈阳想做网站自己怎么学电商运营