[Building Sakai] Permissions Exception user modifying 'myworkspace' programmatically

David Wafula davidwaf at gmail.com
Mon Jul 25 07:37:59 PDT 2011


Soon after posting this, i did solve the problem. The problem was i was
getting a wrong userid...so i used the following line:


 String userid = userDirectoryService.getCurrentUser().getId();

instead of

 String userid = userDirectoryService.getUserByEid(staffNumber).getId();


That worked.
Thanks.

On Mon, Jul 25, 2011 at 3:59 PM, David Wafula <davidwaf at gmail.com> wrote:

> Hi all,
> I am still working on extending My Workspace, but decided to create a new
> thread with a new question. So i settled on the following use case:.
>
> 1. User logs in, validated against LDAP. If first-time login, the user is
> programmatically created.
> 2. After adding the user, we get the workspace site of the user.
> 3. We set the page to edit mode, and we attempt to add a tool to "my
> workspace".
>
>
> Now, in step 3, i get:
>
> org.sakaiproject.exception.PermissionException user=null lock=site.upd
> resource=/site/~4fedf98c-501d-43c3-b62e-d52f4322a157
>
> Am meant to understand a user has full rights to thier own workspace, no?
> Below is the code am using ..help fix the permissions;
>
>
>            //first ...add user
>
>            userDirectoryService.addUser(null, staffNumber,
>                         lDAPUser.getGivenname(), lDAPUser.getSurname(),
> lDAPUser.getEmail(), null, type, null);
>
>            //then get userid
>            String userid =
> userDirectoryService.getUserByEid(staffNumber).getId();
>
>             String myWorkspaceId = siteService.getUserSiteId(userid);
>             Site siteEdit = null;
>             SitePage sitePageEdit = null;
>
>             try {
>                 siteEdit = siteService.getSite(myWorkspaceId);
>             } catch (IdUnusedException e) {
>                 M_log.error("No workspace for user: " + myWorkspaceId + ",
> skipping...");
>                 return;
>             }
>             String toolTitle = "Course Creator";
>             sitePageEdit = siteEdit.addPage();
>             sitePageEdit.setTitle(toolTitle);
>             sitePageEdit.setLayout(0);
>             int position = 0;
>             int numPages = siteEdit.getPages().size();
>             if (position > numPages) {
>                 position = numPages - 1;
>             }
>
>             sitePageEdit.setPosition(position);
>             sitePageEdit.setPopup(false);
>
>             ToolConfiguration tool = sitePageEdit.addTool();
>             Tool t = tool.getTool();
>
>             String toolId = "sakai.coursecreator";
>             tool.setTool(toolId, toolManager.getTool(toolId));
>             tool.setTitle(toolTitle);
>
>             siteService.save(siteEdit);
>
>
>
> siteService.save() results in Perminssions Exception.
>
> Regards,
> --
> David Wafula
>



-- 
David Wafula
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20110725/07f33b0d/attachment.html 


More information about the sakai-dev mailing list