0

I'm trying to create a new rule in GeoServer GeoFence via GeoFence RESTful API, But I got HTTP 406 error, I don't know what thing I'm doing wrong, Because I did based on GeoServer GeoFence Plugin.

curl -v -u admin:g8****dg -X POST http://localhost:8080/geoserver/rest/geofence/rules -H "content-type:application/xml" -H "accept:application/xml" -d "
<Rule>
      <userName>[email protected]</userName>
      <workspace>qwBCMzLk24L7nd1dWdizH4zl5nnckGYU</workspace>
      <layer>*</layer>
      <service>*</service>
      <request>*</request>
      <access>DENY</access> </Rule>"
curl -v -u admin:g8****dg -X POST http://localhost:8080/geoserver/rest/geofence/rules -H "content-type:application/json" -H "accept:application/json" -d '{"Rule":{"userName":"[email protected]","roleName":"DEMO","workspace":"qwBCMzLk24L7nd1dWdizH4zl5nnckGYU","layer":"*","service":"*","request":"*","access":"DENY"}}'

I read these links also, But I didn't understand clearly and I didn't find a neat instruction that described step by step How users can create new Rule by GeoServer RESTful API

GeoFence Tutorial in GeoServer Documnent and GeoFence github

I think the path mentioned that GeoServer GeoFence tutorial has a tiny mistake!, instead of http://localhost:8080/geoserver/rest/geofence/rules, there was http://localhost:8080/geoserver/geofence/rest/rules.

I did try both of them but I didn't get result.

What is the correct form of adding new rule to GeoFence (GeoServer version) via RESTful API?

I'm using GeoServer 2.20.2 and Tomcat 9.0.58, Java v8, Debian 11 x64,and GeoServer Geofence server plugin.

4
  • 1
    I think you need to PUT it rather than POST, and set the Content-type header to application/xml
    – Ian Turton
    Apr 11, 2022 at 16:00
  • Yes, your help was helpful, like always. when I removed "accept:application/xml" it worked. thank you so much
    – Navid
    Apr 11, 2022 at 17:07
  • You should probably put that in as answer to help future users
    – Ian Turton
    Apr 12, 2022 at 7:31
  • thank you so much. @IanTurton
    – Navid
    Apr 12, 2022 at 10:16

1 Answer 1

1

Based on @IanTurton solution, He mentioned in comments.If run that command without "accept:application/xml" user will be able to add new rule.

The only header is need is "content-type:application/xml" or if you are trying to send json format use "content-type:application/json".

curl -v -u admin:g8****dg -X POST http://localhost:8080/geoserver/rest/geofence/rules -H "content-type:application/xml" 
-d "
<Rule>
     <userName>[email protected]</userName>
  <workspace>
      qwBCMzLk24L7nd1dWdizH4zl5nnckGYU
  </workspace>
      <layer>*</layer>
      <service>*</service>
      <request>*</request>
      <access>DENY</access>
</Rule>"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.