[daisy] Running Example under daisy 2.0

Paul Focke paul at outerthought.org
Mon Dec 11 01:23:47 CST 2006


On Friday 08 December 2006 19:39, Greg Sieranski wrote:
> importPackage(Packages.org.outerj.daisy.repository);
> importClass(Packages.org.outerj.daisy.repository.clientimpl.RemoteRepositor
>yManager);
>
> // A RepositoryManager represents one 'physical' repository (one database).
> // All Repository instances retrieved from one RepositoryManager thus
> represent the same repository,
> // the difference between the instances is they are authenticated for
> different users.
> // A Repository object is obtained from the RepositoryManager and is
> contextualized for a certain user.
> // Thus instead of having to supply credentials to each method, you
> authenticate once via the RepositoryManager\
> // and can then do all further operations on this Repository object.
> var repositoryManager = new
> RemoteRepositoryManager("http://localhost:9263", new
> Credentials("testuser","testuser"));
>
> var repository = repositoryManager.getRepository(new
> Credentials("testuser","testuser"));
>
> // With the UserManager we can manage users and roles
> var userManager = repository.getUserManager();
>
> // Get references to some roles
> var guestRole = userManager.getRole("guest", false);
> var adminRole = userManager.getRole("Administrator", false);
>
> // Create the new user
> var newUser = userManager.createUser("greg");
>
> // The user needs to be added to at least one role
> newUser.addToRole(guestRole);
> newUser.addToRole(adminRole);
>
> // Optionally, set a defaul role which will be active after
> // logging in. If not set, all roles (with the exception of the
> Administrator role)
> // will be active on login
> // newUser.setDefaultRole(guestRole);
> newUser.setDefaultRole(adminRole);
>
> // Password is required when using Daisy's built-in authentication scheme
> newUser.setPassword("hello");
>
> // Alternatively, set another authentication scheme:
> // newUser.setAuthenticationScheme("my-ldap");
>
> // Optional things
> newUser.setFirstName("new");
> newUser.setLastName("user");
>
> // Setting updateableByUser will allow the user to access the
> // user settings page in the wiki, so that the user can
> // update their e-mail
> newUser.setUpdateableByUser(true);
>
> newUser.save();
>
> I am trying to run the following example under daisy 2.0 and I am
> receiving the following error message:
>
> C:\opt\daisy-2.0\bin>daisy-js c:\opt\daisy\examples\new-user.js
> org.mozilla.javascript.WrappedException: Wrapped
> org.outerj.daisy.repository.user.UserManagementException: Only
> Administrators can update user records.
Hi,

Perhaps you can check is if the user is in the correct role.
repository.isInRole("Administrator");
or you can just always switch role to administrator to be sure.
repository.switchRole(adminRole.getId());

And another little tip. You might want to have a look at daisy-utils.js which 
contains a few convenience methods for getting a repository instance.  Have a 
look here 
http://cocoondev.org/daisydocs-1_5/daisywiki/general/60/198.html

hth,

Paul


More information about the daisy mailing list