Was this page helpful?

Modify Page Security Settings

    Description of the code sample

    The following command updates the security settings for page "foo" using the security definitions outlined in "security.xml".

    Sample Code

    curl -u admin:password -H "Content-Type: application/xml" -d @security.xml -i http://mindtouch.address/@api/deki/pages/=foo/security

    Implementation notes 

    curl flags

    -u
    Basic HTTP authentication. Sends a username and password to server so it can verify whether a user is of privilege to perform specific operation.
    -H
    Adds a header or modifies an existing one. In this case, since an XML document is being sent, the content type must be set to "application/xml". The server will not accept the request otherwise.
    -d @file
    Specifies the .xml file that contains the user data.
    -i
    Includes the HTTP response header in the output. Useful for debugging.

    Permissions

    ADMIN permission is required to execute above command. Otherwise, a 403 HTTP response (Forbidden) will be returned.

    Example

    User "Spock" has been demoted to Viewer privileges, which precludes him from editing pages. However, we want to give him a "Contributor" role to page "Starfleet", allowing him to read and edit the page. That would be very logical. We also want to set the page to private so pesky Klingons cannot vandalize it.

    spockurity.xml

    Content-Type: application/xml

    <security>
    	<!-- set "Private" permission -->
    
    	<permissions.page>
    		<restriction>Private</restriction>
    	</permissions.page>
    
    	<!-- add user "Spock" (user ID 78) with "Contributor" role -->
    
    	<grants.added>
    		<grant>
    			<permissions>
    				<role>Contributor</role>
    			</permissions>
    			<user id="78"></user>
    		</grant>
    	</grants.added>
    </security>

    Command Line

    curl -u admin:password -H "Content-Type: application/xml" -d @spockurity.xml -i http://192.168.59.128/@api/deki/pages/=Starfleet/security

    HTTP Response Headers

    HTTP/1.1 200 OK
    Date: Tue, 19 Jan 2010 23:41:07 GMT
    Server: Dream-HTTPAPI/2.0.0.17629 Microsoft-HTTPAPI/2.0
    Content-Length: 2214
    Content-Type: application/xml; charset=utf-8
    X-Data-Stats: request-time-ms=99; mysql-queries=28; mysql-time-ms=88;
    X-Deki-Site: id="default"
    Via: 1.1 dekiwiki
    

    HTTP Response Body

    Content-Type: application/xml

    <?xml version="1.0"?>
    <security href="http://192.168.59.128/@api/deki/pages/569/security">
      <permissions.effective>
        <operations mask="9223372036854779903">LOGIN,BROWSE,READ,SUBSCRIBE,UPDATE,CREATE,DELETE,CHANGEPERMISSIONS,CONTROLPANEL,ADMIN</operations>
      </permissions.effective>
      <permissions.page>
        <operations mask="1">LOGIN</operations>
        <restriction id="3" href="http://192.168.59.128/@api/deki/site/roles/3">Private</restriction>
      </permissions.page>
      <grants>
        <grant>
          <permissions>
            <operations mask="1343">LOGIN,BROWSE,READ,SUBSCRIBE,UPDATE,CREATE,DELETE,CHANGEPERMISSIONS</operations>
            <role id="4" href="http://192.168.59.128/@api/deki/site/roles/4">Contributor</role>
          </permissions>
          <user id="1" href="http://192.168.59.128/@api/deki/users/1">
            <nick>Admin</nick>
            <username>Admin</username>
            <email>admin@admin.com</email>
            <hash.email>64e1b8d34f425d19e1ee2ea7236d3028</hash.email>
            <uri.gravatar>http://www.gravatar.com/avatar/64e1b8d34f425d19e1ee2ea7236d3028</uri.gravatar>
          </user>
          <date.modified>2010-01-17T00:19:19Z</date.modified>
          <user.modifiedby id="1" href="http://192.168.59.128/@api/deki/users/1">
            <nick>Admin</nick>
            <username>Admin</username>
            <email>admin@admin.com</email>
            <hash.email>64e1b8d34f425d19e1ee2ea7236d3028</hash.email>
            <uri.gravatar>http://www.gravatar.com/avatar/64e1b8d34f425d19e1ee2ea7236d3028</uri.gravatar>
          </user.modifiedby>
        </grant>
        <grant>
          <permissions>
            <operations mask="1343">LOGIN,BROWSE,READ,SUBSCRIBE,UPDATE,CREATE,DELETE,CHANGEPERMISSIONS</operations>
            <role id="4" href="http://192.168.59.128/@api/deki/site/roles/4">Contributor</role>
          </permissions>
          <user id="78" href="http://192.168.59.128/@api/deki/users/78">
            <nick>spock</nick>
            <username>spock</username>
            <email>spock@vulcan.com</email>
            <hash.email>febf25b1653f915fd76f9786321517b7</hash.email>
            <uri.gravatar>http://www.gravatar.com/avatar/febf25b1653f915fd76f9786321517b7</uri.gravatar>
          </user>
          <date.modified>2010-01-17T00:32:29Z</date.modified>
          <user.modifiedby id="1" href="http://192.168.59.128/@api/deki/users/1">
            <nick>Admin</nick>
            <username>Admin</username>
            <email>admin@admin.com</email>
            <hash.email>64e1b8d34f425d19e1ee2ea7236d3028</hash.email>
            <uri.gravatar>http://www.gravatar.com/avatar/64e1b8d34f425d19e1ee2ea7236d3028</uri.gravatar>
          </user.modifiedby>
        </grant>
      </grants>
    </security>

    Notes

    Was this page helpful?
    Tag page
    Viewing 1 of 1 comments: view all
    just wondering how the code would differ if you were giving a Group access in the Spockurity.xml file instead of a specific User... i.e. change <user id="78"></user> to ? edited 22:18, 10 Nov 2010
    Posted 22:18, 10 Nov 2010
    Viewing 1 of 1 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by