Spring 为特定域设计的引导 Web 服务
Spring Boot web service designed for a specific domain
我想限制我的 spring 启动安全性,只允许特定域(或主机名)进行 Web 服务调用。
想法是只允许一个应用程序(基于 Spring MVC)在 spring 启动应用程序中访问这些网络服务。
更新
我尝试合并 hasIpAddress 如下所示,但没有效果
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll().and().authorizeRequests().anyRequest().access("hasIpAddress('localhost')");
}
spring security 中有这样的设置吗?或者我需要使用拦截器?
在 spring 网络安全中有 hasIpAddress 表达式,您可以在其中传递 ip 或范围。
示例配置:
<http use-expressions="true">
<intercept-url pattern="/myUrlPattern/*" access="hasIpAddress('100.10.11.12')" />
</http>
更多说明here。
也许你可以利用响应头来控制可以访问你的服务的有效IP。 Spring 在我看来,应该使用安全来处理用户身份验证和授权。
response.setHeader("Access-Control-Allow-Origin", "*");
试试:
http.authorizeRequests()
.anyRequest().hasIpAddress('localhost');
希望这对您有所帮助
我想限制我的 spring 启动安全性,只允许特定域(或主机名)进行 Web 服务调用。
想法是只允许一个应用程序(基于 Spring MVC)在 spring 启动应用程序中访问这些网络服务。
更新
我尝试合并 hasIpAddress 如下所示,但没有效果
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll().and().authorizeRequests().anyRequest().access("hasIpAddress('localhost')");
}
spring security 中有这样的设置吗?或者我需要使用拦截器?
在 spring 网络安全中有 hasIpAddress 表达式,您可以在其中传递 ip 或范围。
示例配置:
<http use-expressions="true">
<intercept-url pattern="/myUrlPattern/*" access="hasIpAddress('100.10.11.12')" />
</http>
更多说明here。
也许你可以利用响应头来控制可以访问你的服务的有效IP。 Spring 在我看来,应该使用安全来处理用户身份验证和授权。
response.setHeader("Access-Control-Allow-Origin", "*");
试试:
http.authorizeRequests()
.anyRequest().hasIpAddress('localhost');
希望这对您有所帮助