How to authenticate for CSW Insert Transaction (HTTP Post)?

6 messages Options
Embed this post
Permalink
wgrunberg

How to authenticate for CSW Insert Transaction (HTTP Post)?

Reply Threaded More More options
Print post
Permalink
Hi,
I have several metadata ETL Python scripts that generate CSW AP ISO
insert transactions (XML through HTTP Post).
Is there a way to login to GeoNewtork through a Post request?

--
_______________________________
Wolfgang Grunberg
Arizona Geological Survey
[hidden email]
520-770-3500



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
GeoNetwork-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork
Francois Prunayre

Re: How to authenticate for CSW Insert Transaction (HTTP Post)?

Reply Threaded More More options
Print post
Permalink
Hello Wolfgang,

2009/10/19 Wolfgang Grunberg <[hidden email]>:
> Hi,
> I have several metadata ETL Python scripts that generate CSW AP ISO
> insert transactions (XML through HTTP Post).
> Is there a way to login to GeoNewtork through a Post request?

You cannot do that in one step for the time being. You need to create
a session and login first using xml.user.login service.

Have a look to this example in JS
https://geonetwork.svn.sourceforge.net/svnroot/geonetwork/trunk/web/geonetwork/scripts/test-csw.js
loginAndRun method.

If you've an example to do that in python, it could be nice to put
this example in the wiki ?

HTH.

Francois

> --
> _______________________________
> Wolfgang Grunberg
> Arizona Geological Survey
> [hidden email]
> 520-770-3500
>
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> GeoNetwork-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
> GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
GeoNetwork-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork
Alex Mandel-2

Re: How to authenticate for CSW Insert Transaction (HTTP Post)?

Reply Threaded More More options
Print post
Permalink
Yes please post and example, I'm interested in adding such a function to
a python metadata plugin in QGIS.

Thanks,
Alex

Francois Prunayre wrote:

> Hello Wolfgang,
>
> 2009/10/19 Wolfgang Grunberg <[hidden email]>:
>> Hi,
>> I have several metadata ETL Python scripts that generate CSW AP ISO
>> insert transactions (XML through HTTP Post).
>> Is there a way to login to GeoNewtork through a Post request?
>
> You cannot do that in one step for the time being. You need to create
> a session and login first using xml.user.login service.
>
> Have a look to this example in JS
> https://geonetwork.svn.sourceforge.net/svnroot/geonetwork/trunk/web/geonetwork/scripts/test-csw.js
> loginAndRun method.
>
> If you've an example to do that in python, it could be nice to put
> this example in the wiki ?
>
> HTH.
>
> Francois
>
>> --
>> _______________________________
>> Wolfgang Grunberg
>> Arizona Geological Survey
>> [hidden email]
>> 520-770-3500
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
>> is the only developer event you need to attend this year. Jumpstart your
>> developing skills, take BlackBerry mobile applications to market and stay
>> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
>> http://p.sf.net/sfu/devconference


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
GeoNetwork-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork
wgrunberg

Re: How to authenticate for CSW Insert Transaction (HTTP Post)?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Francois Prunayre
Some javascript/style in this post has been disabled (why?)
Attached is my sample GeoNetwork CSW transaction with authentication Python script. I wrote it mostly to show how HTTP sessions could be handled but I do not know if it is the best or even an appropriate method.
Where do I submit it for review?
Should I just post it on the wiki?
Ciao, WG
_______________________________
Wolfgang Grunberg
Arizona Geological Survey
[hidden email]
520-770-3500



Francois Prunayre wrote:
Hello Wolfgang,

2009/10/19 Wolfgang Grunberg [hidden email]:
  
Hi,
I have several metadata ETL Python scripts that generate CSW AP ISO
insert transactions (XML through HTTP Post).
Is there a way to login to GeoNewtork through a Post request?
    

You cannot do that in one step for the time being. You need to create
a session and login first using xml.user.login service.

Have a look to this example in JS
https://geonetwork.svn.sourceforge.net/svnroot/geonetwork/trunk/web/geonetwork/scripts/test-csw.js
loginAndRun method.

If you've an example to do that in python, it could be nice to put
this example in the wiki ?

HTH.

Francois

  
--
_______________________________
Wolfgang Grunberg
Arizona Geological Survey
[hidden email]
520-770-3500



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
GeoNetwork-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork

    

  

#!/usr/bin/env python
# this is gn_csw_transaction_example.py

"""
Example CSW 2.0.2 transaction with authentication Python script for GeoNetwork
Tested with GeoNetwork 2.4.1 on Windows

Python 2.6
Wolfgang Grunberg
Arizona Geological Survey
10/20/2009
"""

# Library Imports
import urllib
import urllib2
import cookielib

# module globals and constants
__author__ = "Wolfgang Grunberg"
__credits__ = ["Wolfgang Grunberg", "the Internets"]
__email__ = "[hidden email]"
__status__ = "Prototype"                  # "Prototype", "Development", or "Production"

# GeoNetwork constants
gn_username = "admin"
gn_password = "admin"
gn_baseURL = "http://localhost:8080"
gn_loginURI = "/geonetwork/srv/en/xml.user.login"
gn_logoutURI = "/geonetwork/srv/en/xml.user.logout"
gn_cswURI = "/geonetwork/srv/en/csw"


def gn_csw_transaction():
    """
    Execute GeoNetwork authentication and CSW transaction post
    """
    # HTTP header for authentication
    header_urlencode = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
    # HTTP header for CSW request
    header_xml = {"Content-type": "application/xml", "Accept": "text/plain"}
    # authentication Post parameters
    post_parameters = urllib.urlencode({"username": gn_username, "password": gn_password})
   
    # Sample CSW transactions
    xml_request = "<?xml version=\"1.0\"?>\
            <csw:DescribeRecord xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\"\
            service=\"CSW\" version=\"2.0.2\" outputFormat=\"application/xml\"\
            schemaLanguage=\"http://www.w3.org/XML/Schema\"/>"
   
    # log in URL
    url_in = gn_baseURL+gn_loginURI
    # log out URL
    url_out = gn_baseURL+gn_logoutURI
    # CSW URL
    url_csw = gn_baseURL+gn_cswURI
   
   
    # first, always log out
    request = urllib2.Request(url_out)
    response = urllib2.urlopen(request)
    #print response.read()       # debug
   
    # send authentication request
    request = urllib2.Request(url_in, post_parameters, header_urlencode)
    response = urllib2.urlopen(request)
    # a basic memory-only cookie jar instance
    cookies = cookielib.CookieJar()
    cookies.extract_cookies(response,request)
    cookie_handler= urllib2.HTTPCookieProcessor( cookies )
    # a redirect handler
    redirect_handler= urllib2.HTTPRedirectHandler()
    # save cookie and redirect handler for future HTTP Posts
    opener = urllib2.build_opener(redirect_handler,cookie_handler)
   
    # CSW request
    request = urllib2.Request(url_csw, xml_request2, header_xml)
    response = opener.open(request)
    # CSW respons
    xml_response = response.read()
    print xml_response  # debug
   
    # Do something with the response. For example:
    #xmldoc = minidom.parseString(xml_response)
    #for node in xmldoc.getElementsByTagName('ows:ExceptionText'):       # display <ows:ExceptionText /> value(s)
    #    print "    EXCEPTION: "+node.firstChild.nodeValue
    #xmldoc.unlink()     # cleanup DOM for improved performance
   
    # more CSW requests if desired
   
    # Last, alaways log out
    request = urllib2.Request(url_out)
    response = urllib2.urlopen(request)
    #print response.read()       # debug
   
   
if __name__=="__main__":
    gn_csw_transaction()

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
GeoNetwork-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork
Francois Prunayre

Re: How to authenticate for CSW Insert Transaction (HTTP Post)?

Reply Threaded More More options
Print post
Permalink
2009/10/20 Wolfgang Grunberg <[hidden email]>:
> Attached is my sample GeoNetwork CSW transaction with authentication Python
> script. I wrote it mostly to show how HTTP sessions could be handled but I
> do not know if it is the best or even an appropriate method.
> Where do I submit it for review?
> Should I just post it on the wiki?
I made an how-to on the wiki
http://trac.osgeo.org/geonetwork/wiki/HowToDoCSWTransactionOperations

Thanks Wolgang.

Francois

> Ciao, WG
>
> _______________________________
> Wolfgang Grunberg
> Arizona Geological Survey
> [hidden email]
> 520-770-3500
>
>
>
> Francois Prunayre wrote:
>
> Hello Wolfgang,
>
> 2009/10/19 Wolfgang Grunberg <[hidden email]>:
>
>
> Hi,
> I have several metadata ETL Python scripts that generate CSW AP ISO
> insert transactions (XML through HTTP Post).
> Is there a way to login to GeoNewtork through a Post request?
>
>
> You cannot do that in one step for the time being. You need to create
> a session and login first using xml.user.login service.
>
> Have a look to this example in JS
> https://geonetwork.svn.sourceforge.net/svnroot/geonetwork/trunk/web/geonetwork/scripts/test-csw.js
> loginAndRun method.
>
> If you've an example to do that in python, it could be nice to put
> this example in the wiki ?
>
> HTH.
>
> Francois
>
>
>
> --
> _______________________________
> Wolfgang Grunberg
> Arizona Geological Survey
> [hidden email]
> 520-770-3500
>
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> GeoNetwork-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
> GeoNetwork OpenSource is maintained at
> http://sourceforge.net/projects/geonetwork
>
>
>
>
>
> #!/usr/bin/env python
> # this is gn_csw_transaction_example.py
>
> """
> Example CSW 2.0.2 transaction with authentication Python script for
> GeoNetwork
> Tested with GeoNetwork 2.4.1 on Windows
>
> Python 2.6
> Wolfgang Grunberg
> Arizona Geological Survey
> 10/20/2009
> """
>
> # Library Imports
> import urllib
> import urllib2
> import cookielib
>
> # module globals and constants
> __author__ = "Wolfgang Grunberg"
> __credits__ = ["Wolfgang Grunberg", "the Internets"]
> __email__ = "[hidden email]"
> __status__ = "Prototype"                  # "Prototype", "Development", or
> "Production"
>
> # GeoNetwork constants
> gn_username = "admin"
> gn_password = "admin"
> gn_baseURL = "http://localhost:8080"
> gn_loginURI = "/geonetwork/srv/en/xml.user.login"
> gn_logoutURI = "/geonetwork/srv/en/xml.user.logout"
> gn_cswURI = "/geonetwork/srv/en/csw"
>
>
> def gn_csw_transaction():
>    """
>    Execute GeoNetwork authentication and CSW transaction post
>    """
>    # HTTP header for authentication
>    header_urlencode = {"Content-type": "application/x-www-form-urlencoded",
> "Accept": "text/plain"}
>    # HTTP header for CSW request
>    header_xml = {"Content-type": "application/xml", "Accept": "text/plain"}
>    # authentication Post parameters
>    post_parameters = urllib.urlencode({"username": gn_username, "password":
> gn_password})
>
>    # Sample CSW transactions
>    xml_request = "<?xml version=\"1.0\"?>\
>            <csw:DescribeRecord
> xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\"\
>            service=\"CSW\" version=\"2.0.2\"
> outputFormat=\"application/xml\"\
>            schemaLanguage=\"http://www.w3.org/XML/Schema\"/>"
>
>    # log in URL
>    url_in = gn_baseURL+gn_loginURI
>    # log out URL
>    url_out = gn_baseURL+gn_logoutURI
>    # CSW URL
>    url_csw = gn_baseURL+gn_cswURI
>
>
>    # first, always log out
>    request = urllib2.Request(url_out)
>    response = urllib2.urlopen(request)
>    #print response.read()       # debug
>
>    # send authentication request
>    request = urllib2.Request(url_in, post_parameters, header_urlencode)
>    response = urllib2.urlopen(request)
>    # a basic memory-only cookie jar instance
>    cookies = cookielib.CookieJar()
>    cookies.extract_cookies(response,request)
>    cookie_handler= urllib2.HTTPCookieProcessor( cookies )
>    # a redirect handler
>    redirect_handler= urllib2.HTTPRedirectHandler()
>    # save cookie and redirect handler for future HTTP Posts
>    opener = urllib2.build_opener(redirect_handler,cookie_handler)
>
>    # CSW request
>    request = urllib2.Request(url_csw, xml_request2, header_xml)
>    response = opener.open(request)
>    # CSW respons
>    xml_response = response.read()
>    print xml_response  # debug
>
>    # Do something with the response. For example:
>    #xmldoc = minidom.parseString(xml_response)
>    #for node in xmldoc.getElementsByTagName('ows:ExceptionText'):       #
> display <ows:ExceptionText /> value(s)
>    #    print "    EXCEPTION: "+node.firstChild.nodeValue
>    #xmldoc.unlink()     # cleanup DOM for improved performance
>
>    # more CSW requests if desired
>
>    # Last, alaways log out
>    request = urllib2.Request(url_out)
>    response = urllib2.urlopen(request)
>    #print response.read()       # debug
>
>
> if __name__=="__main__":
>    gn_csw_transaction()
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> GeoNetwork-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
> GeoNetwork OpenSource is maintained at
> http://sourceforge.net/projects/geonetwork
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
GeoNetwork-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork
Andrew Watkins

bug in 2.4.2 in self registration?

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

This appears to work fine when using the McKoi database but shows up using the Postgres db.


System config is setup for geonetwork user management and self registration is enabled.

The user self registers and gets an error back.  in the logs we see that an exception was thrown trying to submit the form data.

parameter 14 is null.    


inspecting the code we see that SelfRegister is expecting to put 14 params into the execute call but 'city' is omitted.


here is the fix:


+++ src/org/fao/geonet/services/register/SelfRegister.java(working copy)

@@ -128,7 +128,7 @@

 

 dbms.execute(query, new Integer(id), username, Util

 .scramble(password), surname, name, PROFILE, address,

-state, zip, country, email, organ, kind);

+city, state, zip, country, email, organ, kind);

 

 dbms.execute(

 "INSERT INTO UserGroups(userId, groupId) VALUES (?, ?)",




Regards Andrew


NIWA is the trading name of the National Institute of Water & Atmospheric Research Ltd.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
GeoNetwork-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geonetwork-devel
GeoNetwork OpenSource is maintained at http://sourceforge.net/projects/geonetwork