Re: Realms access from Servlet

Your lucky, I sent this sample code to someone else who wanted to
"dynamically add users to a realm from a servlet".

Regards, Benoit.

Sample:

in your servlet code, write something like:

     JigsawServletContext ctxt =
        (JigsawServletContext) getServletContext();
     httpd server = (httpd) ctxt.getServer();

     ResourceReference realm_ref =
            server.getRealmsCatalog().loadRealm("name_of_realm");
     try {
          AuthRealm realm = (AuthRealm) realm_ref.lock();

           realm.registerResource(username, new AuthUser());
           //here you create the new user (AuthUser).

           ResourceReference user_ref = realm.loadUser(username);
          try {
                AuthUser user = (AuthUser) user_ref.lock();
                 user.setPassword(".....");
                 user.set...
                  etc...
          } catch (InvalidResourceException iex) {
              //error ...
          } finally {
                 user_ref.unlock();
          }
    } catch (InvalidResourceException ex) {
          //error ...
     } finally {
          realm_ref.unlock();
     }

Phil wrote:

> Hi all,
>
> Everything is going well - I thought you'd like to know :) Jigsaw is excellent.
>
> I have a serlvet that I would like to add and remove users in several realms.
>
> I'm slowly getting into the api so I thought I'd ask the question so I can benefit from some more good advice. Is there a way for a servlet to get a reference to realms?
>
> Thanks all for your setup help, especially Benoit - you're heroic!
>
> Phil
> ---------------------------------------------------------
> Phil Blake                                phil@tcp.net.au
> Translation Creation Production     http://www.tcp.net.au
> 32 Harrow Road                         tel +612 9519 4235
> Stanmore NSW 2048                      fax +612 9519 9445
> Australia                          toll free 1800 242 954

--
- Benoît Mahé -------------------------------------------------------
                      World Wide Web Consortium (W3C)
                    Architecture domain - Jigsaw Team

  http://www.w3.org/People/Mahe - bmahe@w3.org - +33.4.92.38.79.89
---------------------------------------------------------------------

Received on Wednesday, 10 February 1999 11:15:12 UTC