/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@)
*/
package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import .slf4j.Slf4j;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
/**
* SwaggerResourceHandler
*
* @author lengleng
*/
public class SwaggerResourceHandler implements HandlerFunction<ServerResponse> {
private final SwaggerResourcesProvider swaggerResources;
private final Environment environment;
private boolean isProdActive;
private String msg401;
public SwaggerResourceHandler(SwaggerResourcesProvider swaggerResources, Environment environment) {
this.swaggerResources = swaggerResources;
this.environment = environment;
this.isProdActive = (this.())
.filter(active -> "test".equalsIgnoreCase(active))
.findAny()
.isPresent();
msg401 = (new ProdSwaggerPath401((), false, null, "请求未授权!!!!!!"));
}
/**
* Handle the given request.
*
* @param request the request to handler
* @return the response
*/
public Mono<ServerResponse> handle(ServerRequest request) {
if (isProdActive) {
String path = ();
("prod环境禁止访问swagger-resources, 环境参数验证: {}, 访问路径: {}", isProdActive, path);
if (("/swagger-resources")) {
return ()
.contentType(MediaType.APPLICATION_JSON_UTF8)
.body((msg401));
}
}
return ()
.contentType(MediaType.APPLICATION_JSON_UTF8)
.body((()));
}
/**
* 生产环境Swagger资源访问错误消息
*/
private class ProdSwaggerPath401 implements Serializable {
private static final long serialVersionUID = 1L;
private int code;
private boolean success;
private Object data;
private String msg;
}
}