Goal: To write data/nodes to content (specifically to /etc/userdata) when a user logs in.
We can achieve this in 2 ways (either way, the user needs to be a 'system user')
Process 1:
Step 1: Use in-built system user in OSGI configuration. In OSGI select Apache Sling Service User Mapper Service
group.abc.commons-service:writeService=oauthservice (where 'oauthservice' is a system user)
Step 2: Assign that system user the permissions to access the content folder.
You see the system users in CRX at: /home/users/system
Process 2:
Step 1: Create a new system user. to do this
Login as admin > Open 'User Administration > Select 'Create System User' > Enter "user id" > Hit the Green button (you will not se a save button :)
I have created "abcwriteservice" user
Step 2: Go to Permissions, and for the user 'abcwriteservice' give Permissions to access the folder where you'd like to write. (In this example: /etc/userdata )
Step 3: Open OSGI console and go to "Apache Sling Service User Mapper Service" to define the service-user mapping. For example: 'group.commons-service:writeService=abcwriteservice'
Step 4: In code, i added extra parameter, as:
Map<String, Object> param = new HashMap<String, Object>(); param.put(ResourceResolverFactory.SUBSERVICE, "writeService"); try { resourceResolverWriter = factory.getServiceResourceResolver(param); if (resourceResolverWriter == null) throw new Exception("Could not obtain a CRX User for the Service:'writeService'"); Node usersRootNode = adminSession.getNode("/etc/userdata/users");
|
Ref: http://stackoverflow.com/questions/31350548/resourceresolverfactory-getserviceresourceresolver-throws-exception-in-aem-6-1
Nhận xét
Đăng nhận xét