我正在使用npm包"http-server"(https://www.npmjs.com/package/http-server)来设置一个简单的网络服务器,但我无法使用SSL.我在package.json中的命令是
http-server -p 8000 -o -S
Run Code Online (Sandbox Code Playgroud)
在我的根目录中使用cert.pem和key.pem(现在)."-o"选项将浏览器打开到默认页面,但页面使用HTTP提供,甚至无法通过HTTPS访问.我没有收到任何错误或警告.我也尝试过添加"-C"和"-K"选项而没有运气.这个套餐有没有成功?
我使用以下Maven依赖项来自动配置所有必要的参数,以使我的项目在AWS上运行:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我没有任何关键功能,具体取决于AWS,它只是在运行时从S3加载一些文件.因此,在本地开发(以及测试)期间,我不需要任何AWS自动配置.
我在本地运行时得到的逻辑错误是:
...
Caused by: java.lang.IllegalStateException: There is no EC2 meta data available, because the application is not running in the EC2 environment. Region detection is only possible if the application is running on a EC2 instance
at org.springframework.util.Assert.state(Assert.java:392) ~[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.cloud.aws.core.region.Ec2MetadataRegionProvider.getRegion(Ec2MetadataRegionProvider.java:39) ~[spring-cloud-aws-core-1.2.2.RELEASE.jar:1.2.2.RELEASE]
at org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean.createInstance(AmazonWebserviceClientFactoryBean.java:98) ~[spring-cloud-aws-core-1.2.2.RELEASE.jar:1.2.2.RELEASE]
at org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean.createInstance(AmazonWebserviceClientFactoryBean.java:44) ~[spring-cloud-aws-core-1.2.2.RELEASE.jar:1.2.2.RELEASE]
...
Run Code Online (Sandbox Code Playgroud)
对于测试和本地开发,是否有一个干净,可行的解决方案?
我的类路径上有Spring Security(并且已经验证了我自己的REST控制器的工作状态),但我的Actuator端点默认都是公开的(除了/shutdown).
我可以随意禁用端点(在阅读完这个问题之后),但是启用的端点始终可用而无需身份验证且没有management.security.role我的属性所需的角色.
即使我明确地设置endpoints.beans.sensitive=true了例子,它仍然可以在没有身份验证的情况下访问.
我的安全配置使用LDAP进行身份验证:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private LdapContextSource contextSource;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.contextSource(contextSource)
.groupRoleAttribute("<hidden>")
.groupSearchBase("<hidden>")
.groupSearchFilter("<hidden>")
.userDnPatterns("<hidden>");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic();
}
}
Run Code Online (Sandbox Code Playgroud)
我在此测试期间的application.properties:
# Log4J properties
logging.file=${user.home}/nubis-log.log
logging.level.org.springframework.web=INFO
logging.level.org.hibernate=INFO
logging.register-shutdown-hook=true
# SSL configuration
server.ssl.key-store=<hidden>
server.ssl.key-store-password=<hidden>
server.ssl.keyStoreType=<hidden>
server.ssl.key-password=<hidden>
# Spring actuator
endpoints.enabled=false
endpoints.info.enabled=true
endpoints.health.enabled=true
endpoints.beans.enabled=true
endpoints.beans.sensitive=true
management.security.role=ADMIN
Run Code Online (Sandbox Code Playgroud)
我的控制台输出: …
我最近建立了一个 Artifactory 存储库并使用 SSL 证书对其进行保护。它不是自签名的,但虽然大多数操作系统都预装了它,但 JRE 没有。
问题是在 Maven 存储库首选项窗口(IntelliJ 首选项 > 构建、执行、部署 > 构建工具 > Maven > 存储库)中包含我的服务器的记录在按下更新按钮时出现错误。以下是摘自idea.log:
Caused by: java.lang.RuntimeException: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)
... 57 more
Run Code Online (Sandbox Code Playgroud)
所以我尝试将我们的根证书添加到 IntelliJ 的服务器证书(IntelliJ 首选项 > 工具 > 服务器证书)并重新启动 IntelliJ,但错误仍然存在。
有没有其他人遇到过这个问题?
我的首选项窗口的屏幕截图:
我有两个要比较的文件(文件 Web API)对象数组,但我不知道可以使用哪些属性来进行比较。
数组可能会变得非常大,所以我不想比较文件内容。实际上,即使必须读取文件也将是一个巨大的约束......还有什么是检查两个 File 对象是否引用同一个文件的好方法?请注意,它们可以位于不同的路径中,因此文件名可能不是唯一的...
我正在使用 Elastic Beanstalk 部署 Spring Boot Web 服务器,在应用程序负载均衡器 (Elastic Load Balancer) 后面运行。业务规则是只能通过 HTTPS 联系此 Web 服务器。因此任何 HTTP 请求都必须首先转发到 HTTPS。
根据Amazon 的这篇文章,我应该简单地检查由负载均衡器设置的x-forwarded-for和标头。x-forwarded-proto这些标头包含有关客户端向负载均衡器发出的原始请求的信息。
因此,我开始寻找 Spring Boot 的内置方法(顺便说一句,我正在使用内置的 Tomcat 服务器)来检查这两个标头并进行重定向,而不必自己编写太多代码。Spring Boot(我们使用的是 1.4 版)文档声明要使用以下应用程序属性:
security.require_ssl=true
server.tomcat.remote_ip_header=x-forwarded-for
server.tomcat.protocol_header=x-forwarded-proto
Run Code Online (Sandbox Code Playgroud)
使用 Postman 进行测试会得到 HTTP 200,我应该在其中获得 301/302 重定向。我怀疑这是由于我使用 Spring Security 造成的。为了使其与 Spring Security 一起工作,我可以将其添加到我的WebSecurityConfigurerAdapter:
http.requiresChannel().anyRequest().requiresSecure();
Run Code Online (Sandbox Code Playgroud)
但现在我的标头被忽略,所有请求都转发到 HTTPS,即使原始请求已经是 HTTPS 了。所以现在没有任何作用。
罗德里戈·克萨达(Rodrigo Quesada)在这里的答案似乎是我所需要的,但由于某种原因,它仍然不尊重我的标题。这个请求仍然给我一个重定向而不是 200:
GET / HTTP/1.1
Host: localhost:8080
X-Forwarded-Proto: https
X-Forwarded-For: 192.168.0.30
Run Code Online (Sandbox Code Playgroud)
这里和其他网站上还有许多其他解决方案,使用另一个中间 Web …
我正在使用 Spring Boot 来设置 REST API。我将制作一堆@RestControllers 并希望在那些返回我调用的特定抽象类的子类型的方法上设置切入点Model。这些控制器看起来像这样:
@RestController
public class UserController {
@RequestMapping(...)
public Person getAllPeople() {
...
}
}
Run Code Online (Sandbox Code Playgroud)
我的Person课程看起来像这样:
public class Person extends Model {
...
}
Run Code Online (Sandbox Code Playgroud)
那么是否可以写出如下所示的建议:
@Aspect
@Component
public class ModelAspect {
@AfterReturning(
value = "execution(<T extends mypackages.Model> T mypackages.api.*.*(..))",
returning = "model")
public void doSomethingWithModel(Model model) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
当然,这是行不通的,因为该建议在语法上无效。在参考文档中,我只找到了有关泛型参数的信息,没有找到返回类型的信息(Spring AOP 参考)。我现在拥有的是这样的,但我认为像上面的例子这样的东西会更有效:
@Aspect
@Component
public class ModelAspect {
@AfterReturning(
value = "execution(* mypackages.api.*.*(..))",
returning = "model") …Run Code Online (Sandbox Code Playgroud) java ×4
spring-boot ×3
maven ×2
spring ×2
ssl ×2
filelist ×1
httpserver ×1
javascript ×1
node.js ×1
npm ×1
repository ×1
spring-aop ×1
spring-cloud ×1
tomcat ×1