简体   繁体   English

如何使用OpenLayers从Geoserver访问私有层?

[英]How to access with OpenLayers a private layer from Geoserver?

I can use the following code to show public layers, but if it demands authentication, I can't (as expected). 我可以使用以下代码来显示公共层,但是如果需要身份验证,则不能(按预期)。

var untiled = new ol.layer.Image({
  source: new ol.source.ImageWMS({
    ratio: 1,
    url: 'http://url/geoserver/workspacename/wms',
    params: {
      'FORMAT': format,
      'VERSION': '1.1.1',
      STYLES: '',
      LAYERS: 'workspacename:layername'
    }
  })
});

How can I authenticate via OpenLayers request? 如何通过OpenLayers请求进行身份验证? There's any way to exhibit the private layers or if I want to use OpenLayers I must let all my layers open? 有什么方法可以显示私有层,或者如果我想使用OpenLayers,我必须让我的所有层都打开吗? Thanks in advance. 提前致谢。

I end up finding two solutions to this problem. 我最终找到了解决这个问题的两种方法。 One was point out by the Mike in the comments and the other one I get it in the Reddit . 一个是在Mike的评论中指出的,另一个是我在Reddit中得到的。

Basically, in the first one, you have to change the imageLoadFunction to send in every requisition the username and the password in the header. 基本上,在第一个中,您必须更改imageLoadFunction以在每个请求中发送标题中的用户名和密码。 There's a problem in this approach, though, the credentials will be available in the source code. 但是,这种方法存在问题,凭据将在源代码中可用。

The other option is to deal with the Geoserver authentication in the server side. 另一个选择是在服务器端处理Geoserver身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM