• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating users programatically

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear ranchers:

Could anyone please tell me how I could write my application to programatically create users in an application server's security realm, and assign roles from the application server's security realm to these users?

Thanks in advance.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That depends on which app server you're using. This area is not specified by the J2EE spec, so each server implements it in its own way.
 
Henrique Ordine
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
O, ok. I don't really want to loose the portability, but thanks anyway.
Ulf, if it's not too much to ask, how would you implement this functionality in a way that it would keep your application portable. My application needs to allow users to register themselves. I would normally use a database table to keep usernames and passwords, but I was just wondering if there was a better way to do this.

Thanks again.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using a database table sounds like the normal way to do it. If you want independence from the DB, you could use an in-memory database like HSQLDB running as part of the app server.
 
Henrique Ordine
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, thanks Ulf.
This way I wouldn't be able to use declarative security for EJBs or web resources though, right? Neither would I be able to use programmatic security using getCallerPrincipal() or getUserPrincipal() for that matter, right?

I was thinking of having an Interface with methods I would need in my application related to that functionality, such as createUser(), changePassword(), and then I would have different implementations of this interface for different App Servers and have an Abstract Factory return the implementation of the app server that my application would be currently using based on a parameter.
Would you say that was a good idea?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This way I wouldn't be able to use declarative security for EJBs or web resources though, right? Neither would I be able to use programmatic security using getCallerPrincipal() or getUserPrincipal() for that matter, right?


Correct.

I was thinking of having an Interface with methods I would need in my application related to that functionality, such as createUser(), changePassword(), and then I would have different implementations of this interface for different App Servers and have an Abstract Factory return the implementation of the app server that my application would be currently using based on a parameter. Would you say that was a good idea?


That would work, but it sounds like a lot of work. Are you sure you can't use standard APIs like JAAS or JNDI/LDAP coupled with web app or EJB security?
 
Henrique Ordine
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I'm not sure. I'll have a look at those.
Again, thanks very much.
reply
    Bookmark Topic Watch Topic
  • New Topic