Re: [xwiki-devs] How to setup 'Prevent unregistered users from viewing pages' in config or programmatically?
Oh, and the value must be 1 to enable. On 03/21/2016 08:29 AM, Sergiu Dumitriu wrote:
That's an object property, so you can use a normal page REST call to set it.
page: XWiki.XWikiPreferences object: XWiki.XWikiPreferences[0] property: authenticate_view / authenticate_edit
On 03/21/2016 08:07 AM, abtv wrote:
I would like to deny seen pages for unregistered users. I can do it via the following:
Choose `Administration` -> `Users & Groups` -> `Rights` then select `Prevent unregistered users from viewing pages, regardless of the page or space rights` and `Prevent unregistered users from editing pages, regardless of the page or space rights`.
But I would like to automate it while deploying xwiki. It means no user interactions with UI. Is there any way to do it? Maybe, config file or via java extension?
-- Sergiu Dumitriu http://purl.org/net/sergiu/
It's good idea, but I would prefer to use java code in xwiki instead of REST call from outside of xwiki. Is it possible? -- View this message in context: http://xwiki.475771.n2.nabble.com/How-to-setup-Prevent-unregistered-users-fr... Sent from the XWiki- Dev mailing list archive at Nabble.com.
Yes, using the standard APIs for interacting with documents. XWikiDocument doc = xcontext.getWiki().getDocument(<reference to XWiki.XWikiPreferences>, xcontext); doc.setIntValue(<reference to XWiki.XWikiPreferences>, "authenticate_view", 1); doc.setIntValue(<reference to XWiki.XWikiPreferences>, "authenticate_edit", 1); xcontext.getWiki().saveDocument(doc, xcontext); Or, shorter and without using the deprecated old core APIs: @Inject private DocumentAccessBridge bridge; ... bridge.setProperty(<reference to XWiki.XWikiPreferences>, <reference to XWiki.XWikiPreferences>, "authenticate_view", 1); On 03/22/2016 03:33 AM, abtv wrote:
It's good idea, but I would prefer to use java code in xwiki instead of REST call from outside of xwiki. Is it possible?
-- Sergiu Dumitriu http://purl.org/net/sergiu/
Yes, I have found this API and http://platform.xwiki.org/xwiki/bin/view/DevGuide/DsXWikiPreferences too. The problem is I don't understand what to pass to getProperty as params. You wrote: bridge.setProperty(<reference to XWiki.XWikiPreferences>, <reference to XWiki.XWikiPreferences>, "authenticate_view", 1); The following returns null: documentAccessBridge.getProperty("XWiki.XWikiPreferences[0]", "XWiki.XWikiPreferences[0]", "authenticate_view"); Could you write what I should pass to getProperty method, please? And to prevent future questions what should I read to solve such problems? -- View this message in context: http://xwiki.475771.n2.nabble.com/How-to-setup-Prevent-unregistered-users-fr... Sent from the XWiki- Dev mailing list archive at Nabble.com.
At least I can read these values with the following: Object y1 = documentAccessBridge.getProperty("XWiki.XWikiPreferences", "authenticate_view"); Object y2 = documentAccessBridge.getProperty("XWiki.XWikiPreferences", "authenticate_edit"); -- View this message in context: http://xwiki.475771.n2.nabble.com/How-to-setup-Prevent-unregistered-users-fr... Sent from the XWiki- Dev mailing list archive at Nabble.com.
I've found a solution: DocumentReference dr = new DocumentReference("xwiki", "XWiki", "XWikiPreferences"); documentAccessBridge.setProperty(dr, dr, "authenticate_view", 1); documentAccessBridge.setProperty(dr, dr, "authenticate_edit", 1); -- View this message in context: http://xwiki.475771.n2.nabble.com/How-to-setup-Prevent-unregistered-users-fr... Sent from the XWiki- Dev mailing list archive at Nabble.com.
participants (2)
-
abtv -
Sergiu Dumitriu