Load GeoServer WMS secured layers with OpenLayers

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Load GeoServer WMS secured layers with OpenLayers

josegar74
Hi

I'm trying to load a secured WMS layer from GeoServer, but seem not possible to send credentials when loading the layer in the map.

I'm trying with this code to create the layer:

var ol_wms = new OpenLayers.Layer.WMS( "WMS.Secured",
                "http://SERVER/geoserver/wms?", {layers: 'SEC_LAYER', user: 'XXXX', password: 'XXXX'} );


But I get an empty image. Seem the user/password parameters are not valid to manage about the authentication for these layers.

I didn't find many information about how getting secured GeoServer layers working in OpenLayers, but hope that is possible. If you can point me in the right direction would be very grateful.

Regards,
Jose García

_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: Load GeoServer WMS secured layers with OpenLayers

Andreas Hocevar-2
On Feb 10, 2011, at 10:53 , jose garcia wrote:

> I'm trying to load a secured WMS layer from GeoServer, but seem not possible to send credentials when loading the layer in the map.
>
> I'm trying with this code to create the layer:
>
> var ol_wms = new OpenLayers.Layer.WMS( "WMS.Secured",
>                 "http://SERVER/geoserver/wms?", {layers: 'SEC_LAYER', user: 'XXXX', password: 'XXXX'} );
>
>
> But I get an empty image. Seem the user/password parameters are not valid to manage about the authentication for these layers.

Right. You need to authenticate the HTTP Basic Auth way:

var ol_wms = new OpenLayers.Layer.WMS( "WMS.Secured",
                "http://XXXX:XXXX@SERVER/geoserver/wms", {LAYERS: 'SEC_LAYER'} );

On a side note: both your method and this method publicly expose username and password, so you could unsecure your layer in the first place as well, unless you are using the authentication just to do usage tracking.

Regards,
Andreas.

>
> I didn't find many information about how getting secured GeoServer layers working in OpenLayers, but hope that is possible. If you can point me in the right direction would be very grateful.
>
> Regards,
> Jose García
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/openlayers-users

--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.

_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: Load GeoServer WMS secured layers with OpenLayers

Robert Anderson-2
if your environment is java, you can use OL4JSFProxy.


WEB-INF/web.xml

...

    <servlet>
        <servlet-name>OL4JSFProxy</servlet-name>
        <servlet-class>org.ol4jsf.proxy.servlet.OL4JSFProxy</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>OL4JSFProxy</servlet-name>
        <url-pattern>/OL4JSFProxy/*</url-pattern>
    </servlet-mapping>

...


WEB-INF/classes/ol4jsf-proxy

<?xml version="1.0" encoding="UTF-8"?>
<ol4jsf-proxy>
    <use-environment id="desenv" />
    <environment id="desenv">
        <description>Development Environment.</description>
        <resources>
            <resource name="wfs">
                <url>http://127.0.0.1:8090/geoserver/wfs</url>
                <authentication>
                            <username>admin</username>
                             <password>geoserver</password>
                 </authentication>
            </resource>
            <resource name="wms">
                <url>http://127.0.0.1:8090/geoserver/wms</url>
                <authentication>
                            <username>admin</username>
                             <password>geoserver</password>
                 </authentication>
            </resource>
        </resources>
    </environment>
</ol4jsf-proxy>



your_page.xhtml (JSF)

...



                <m:wmsLayer name="Cities"
                            url="http://localhost:8084/WebApplication1/OL4JSFProxy/wms"
                            params="{'layers': 'topp:tasmania_cities', transparent: true, format: 'image/gif'}">
                </m:wmsLayer>
...


your_page.xhtml (without JSF)

...

 var ol_wms = new OpenLayers.Layer.WMS( "Cities",
                 "http://localhost:8084/WebApplication1/OL4JSFProxy/wms", {'layers': 'topp:tasmania_cities', transparent: true, format: 'image/gif'} );
...


Regards,

Robert
--
Robert Anderson Nogueira de Oliveira
_________________________
MSN: [hidden email]

"Ausência de evidência não é evidência de ausência." (Carl Sagan)


On Thu, Feb 10, 2011 at 7:05 AM, Andreas Hocevar <[hidden email]> wrote:
On Feb 10, 2011, at 10:53 , jose garcia wrote:

> I'm trying to load a secured WMS layer from GeoServer, but seem not possible to send credentials when loading the layer in the map.
>
> I'm trying with this code to create the layer:
>
> var ol_wms = new OpenLayers.Layer.WMS( "WMS.Secured",
>                 "http://SERVER/geoserver/wms?", {layers: 'SEC_LAYER', user: 'XXXX', password: 'XXXX'} );
>
>
> But I get an empty image. Seem the user/password parameters are not valid to manage about the authentication for these layers.

Right. You need to authenticate the HTTP Basic Auth way:

var ol_wms = new OpenLayers.Layer.WMS( "WMS.Secured",
               "http://XXXX:XXXX@SERVER/geoserver/wms", {LAYERS: 'SEC_LAYER'} );

On a side note: both your method and this method publicly expose username and password, so you could unsecure your layer in the first place as well, unless you are using the authentication just to do usage tracking.

Regards,
Andreas.

>
> I didn't find many information about how getting secured GeoServer layers working in OpenLayers, but hope that is possible. If you can point me in the right direction would be very grateful.
>
> Regards,
> Jose García
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/openlayers-users

--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.

_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users


_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: Load GeoServer WMS secured layers with OpenLayers

josegar74
Thanks both for responses.

About the  providing the credentials like: http://XXXX:XXXX@SERVER/geoserver/wms , i get a blank imag, seem not managing correctly about credentials. I'll try OL4JSFProxy solution.

Regards,
Jose García

On Thu, Feb 10, 2011 at 11:22 AM, Robert Anderson <[hidden email]> wrote:
if your environment is java, you can use OL4JSFProxy.


WEB-INF/web.xml

...

    <servlet>
        <servlet-name>OL4JSFProxy</servlet-name>
        <servlet-class>org.ol4jsf.proxy.servlet.OL4JSFProxy</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>OL4JSFProxy</servlet-name>
        <url-pattern>/OL4JSFProxy/*</url-pattern>
    </servlet-mapping>

...


WEB-INF/classes/ol4jsf-proxy

<?xml version="1.0" encoding="UTF-8"?>
<ol4jsf-proxy>
    <use-environment id="desenv" />
    <environment id="desenv">
        <description>Development Environment.</description>
        <resources>
            <resource name="wfs">
                <url>http://127.0.0.1:8090/geoserver/wfs</url>
                <authentication>
                            <username>admin</username>
                             <password>geoserver</password>
                 </authentication>
            </resource>
            <resource name="wms">
                <url>http://127.0.0.1:8090/geoserver/wms</url>
                <authentication>
                            <username>admin</username>
                             <password>geoserver</password>
                 </authentication>
            </resource>
        </resources>
    </environment>
</ol4jsf-proxy>



your_page.xhtml (JSF)

...



                <m:wmsLayer name="Cities"
                            url="http://localhost:8084/WebApplication1/OL4JSFProxy/wms"
                            params="{'layers': 'topp:tasmania_cities', transparent: true, format: 'image/gif'}">
                </m:wmsLayer>
...


your_page.xhtml (without JSF)

...

 var ol_wms = new OpenLayers.Layer.WMS( "Cities",
                 "http://localhost:8084/WebApplication1/OL4JSFProxy/wms", {'layers': 'topp:tasmania_cities', transparent: true, format: 'image/gif'} );
...


Regards,

Robert
--
Robert Anderson Nogueira de Oliveira
_________________________
MSN: [hidden email]

"Ausência de evidência não é evidência de ausência." (Carl Sagan)



On Thu, Feb 10, 2011 at 7:05 AM, Andreas Hocevar <[hidden email]> wrote:
On Feb 10, 2011, at 10:53 , jose garcia wrote:

> I'm trying to load a secured WMS layer from GeoServer, but seem not possible to send credentials when loading the layer in the map.
>
> I'm trying with this code to create the layer:
>
> var ol_wms = new OpenLayers.Layer.WMS( "WMS.Secured",
>                 "http://SERVER/geoserver/wms?", {layers: 'SEC_LAYER', user: 'XXXX', password: 'XXXX'} );
>
>
> But I get an empty image. Seem the user/password parameters are not valid to manage about the authentication for these layers.

Right. You need to authenticate the HTTP Basic Auth way:

var ol_wms = new OpenLayers.Layer.WMS( "WMS.Secured",
               "http://XXXX:XXXX@SERVER/geoserver/wms", {LAYERS: 'SEC_LAYER'} );

On a side note: both your method and this method publicly expose username and password, so you could unsecure your layer in the first place as well, unless you are using the authentication just to do usage tracking.

Regards,
Andreas.

>
> I didn't find many information about how getting secured GeoServer layers working in OpenLayers, but hope that is possible. If you can point me in the right direction would be very grateful.
>
> Regards,
> Jose García
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/openlayers-users

--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.

_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users


_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users



_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: Load GeoServer WMS secured layers with OpenLayers

Andreas Hocevar-2
I think there may be something else wrong with your application. You shouldn't be getting a blank image. Instead, the browser should show you a basic auth dialog, asking for a login to geoserver.

What happens if you browse to http://SERVER/geoserver/wms?service=WMS&request=GetCapabilities ?

Regards,
Andreas.

On Feb 10, 2011, at 11:45 , jose garcia wrote:

> Thanks both for responses.
>
> About the  providing the credentials like: http://XXXX:XXXX@SERVER/geoserver/wms , i get a blank imag, seem not managing correctly about credentials. I'll try OL4JSFProxy solution.
>
> Regards,
> Jose García
>
> On Thu, Feb 10, 2011 at 11:22 AM, Robert Anderson <[hidden email]> wrote:
> if your environment is java, you can use OL4JSFProxy.
>
>
> WEB-INF/web.xml
>
> ...
>
>     <servlet>
>         <servlet-name>OL4JSFProxy</servlet-name>
>         <servlet-class>org.ol4jsf.proxy.servlet.OL4JSFProxy</servlet-class>
>         <load-on-startup>0</load-on-startup>
>     </servlet>
>
>     <servlet-mapping>
>         <servlet-name>OL4JSFProxy</servlet-name>
>         <url-pattern>/OL4JSFProxy/*</url-pattern>
>     </servlet-mapping>
>
> ...
>
>
> WEB-INF/classes/ol4jsf-proxy
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ol4jsf-proxy>
>     <use-environment id="desenv" />
>     <environment id="desenv">
>         <description>Development Environment.</description>
>         <resources>
>             <resource name="wfs">
>                 <url>http://127.0.0.1:8090/geoserver/wfs</url>
>                 <authentication>
>                             <username>admin</username>
>                              <password>geoserver</password>
>                  </authentication>
>             </resource>
>             <resource name="wms">
>                 <url>http://127.0.0.1:8090/geoserver/wms</url>
>                 <authentication>
>                             <username>admin</username>
>                              <password>geoserver</password>
>                  </authentication>
>             </resource>
>         </resources>
>     </environment>
> </ol4jsf-proxy>
>
>
>
> your_page.xhtml (JSF)
>
> ...
>
>
>
>                 <m:wmsLayer name="Cities"
>                             url="http://localhost:8084/WebApplication1/OL4JSFProxy/wms"
>                             params="{'layers': 'topp:tasmania_cities', transparent: true, format: 'image/gif'}">
>                 </m:wmsLayer>
> ...
>
>
> your_page.xhtml (without JSF)
>
> ...
>
>  var ol_wms = new OpenLayers.Layer.WMS( "Cities",
>                  "http://localhost:8084/WebApplication1/OL4JSFProxy/wms", {'layers': 'topp:tasmania_cities', transparent: true, format: 'image/gif'} );
> ...
>
>
> Regards,
>
> Robert
> --
> Robert Anderson Nogueira de Oliveira
> _________________________
> MSN: [hidden email]
>
> "Ausência de evidência não é evidência de ausência." (Carl Sagan)
>
>
>
> On Thu, Feb 10, 2011 at 7:05 AM, Andreas Hocevar <[hidden email]> wrote:
> On Feb 10, 2011, at 10:53 , jose garcia wrote:
>
> > I'm trying to load a secured WMS layer from GeoServer, but seem not possible to send credentials when loading the layer in the map.
> >
> > I'm trying with this code to create the layer:
> >
> > var ol_wms = new OpenLayers.Layer.WMS( "WMS.Secured",
> >                 "http://SERVER/geoserver/wms?", {layers: 'SEC_LAYER', user: 'XXXX', password: 'XXXX'} );
> >
> >
> > But I get an empty image. Seem the user/password parameters are not valid to manage about the authentication for these layers.
>
> Right. You need to authenticate the HTTP Basic Auth way:
>
> var ol_wms = new OpenLayers.Layer.WMS( "WMS.Secured",
>                "http://XXXX:XXXX@SERVER/geoserver/wms", {LAYERS: 'SEC_LAYER'} );
>
> On a side note: both your method and this method publicly expose username and password, so you could unsecure your layer in the first place as well, unless you are using the authentication just to do usage tracking.
>
> Regards,
> Andreas.
>
> >
> > I didn't find many information about how getting secured GeoServer layers working in OpenLayers, but hope that is possible. If you can point me in the right direction would be very grateful.
> >
> > Regards,
> > Jose García
> > _______________________________________________
> > Users mailing list
> > [hidden email]
> > http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
> --
> Andreas Hocevar
> OpenGeo - http://opengeo.org/
> Expert service straight from the developers.
>
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/openlayers-users

--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.

_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: Load GeoServer WMS secured layers with OpenLayers

spring
This post has NOT been accepted by the mailing list yet.
In reply to this post by Robert Anderson-2
My environment is GeoServer2.2.2, Tomcat 6,  JDK 6, and my application uses strut framework.

I followed Robert's  instructions on  using OL4JFProxy:

In my application WEB-INF/web.xml, I added:

<servlet>
        <servlet-name>OL4JSFProxy</servlet-name>
        <servlet-class>org.ol4jsf.proxy.servlet.OL4JSFProxy</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>OL4JSFProxy</servlet-name>
        <url-pattern>/gis/OL4JSFProxy/*</url-pattern>
    </servlet-mapping>

And in WEB-INF/classes/,  I created a file called 4jsf-proxy:


<?xml version="1.0" encoding="UTF-8"?>
<ol4jsf-proxy>
    <use-environment id="desenv" />
    <environment id="desenv">
        <description>Development Environment.</description>
        <resources>
       
        <resources>
            <resource name="wfs">
                <url>http://localhost:8080/geoserver/nc/wfs</url>
                <authentication>
                            <username>admin</username>
                             <password>geoserver</password>
                 </authentication>
            </resource>
            <resource name="wms">
                <url>http://localhost:8080/geoserver/nc/wms</url>
                <authentication>
                            <username>admin</username>
                             <password>geoserver</password>
                 </authentication>
            </resource>
        </resources>
    </environment>
</ol4jsf-proxy>


After rebooting tomcat, I tried http://localhost:8080/APPLICATION/gis/OL4JSFProxy but  I got the message "OL4JSFProxy is not configured."

What's wrong in my set up? Should I  do the configuration file as 4jsf-proxy or 4jsf-proxy.xml? I tried both but I got the same message.

Thanks,
Maggie
Reply | Threaded
Open this post in threaded view
|

Re: Load GeoServer WMS secured layers with OpenLayers

spring
This post has NOT been accepted by the mailing list yet.
I figured out that I need to use 4jsf-proxy.xml and I had a syntax error - an extra line of <resources>. I fixed that and  it worked!  

Thanks Robert! Your instructions are so helpful!

Maggie
Reply | Threaded
Open this post in threaded view
|

Re: Load GeoServer WMS secured layers with OpenLayers

mumairr
This post has NOT been accepted by the mailing list yet.
Hi,

Could you please share complete procedure for configuring ol4jsf???

I am unable to configure it properly.
Reply | Threaded
Open this post in threaded view
|

Re: Load GeoServer WMS secured layers with OpenLayers

icaglar
This post has NOT been accepted by the mailing list yet.
Put your ol4jsf-proxy.xml file to classpath that will resolve your issue.