How to add a new user to a realm programmatically?

I'm running my web application on Sun Java Application Server 8. Using Admin Console or asadmin doesn't solve the problem. I need to add a new user to a realm called "file" and I need to do that using method. I named this method "addNewUser(user,password)" and it looks as follows:

publicvoid addNewUser(String user, String password){

final AppserverConnectionSource src =

new AppserverConnectionSource("localhost", 8686,"admin","adminadmin",null);

try{

final DomainRoot domainRoot = src.getDomainRoot();

System.out.println(domainRoot.getDomainConfig().getApplicationRoot());

}catch (IOException ex){

ex.printStackTrace();

}

//...and what then?

}

The method above doesn't throw any exceptions so far. Whether I'm on right or wrong way, I got stuck. There must be simple way to solve the problem by writing few lines of code. Thanks in advance for any solutions.

[1479 byte] By [nirgala] at [2007-10-3 9:17:17]
# 1

Hi,

This should be very much possible.

Please see:

https://glassfish.dev.java.net/nonav/javaee5/amx/javadoc/index.html

Once you've got the domain-root, you should traverse and get a named "config",

using getConfigConfigMap("server-config") method and then get the

SecurityConfig out of that. Once you get the Security Config, you should get

the default realm using getDefaultRealm method and then it should be

possible for you to use addUser.

Please let me know if it helps.

Kedar

kedar.mhaswadea at 2007-7-15 4:30:12 > top of Java-index,Core,Monitoring & Management...
# 2
It works indeed :)Thanks Kedar
nirgala at 2007-7-15 4:30:12 > top of Java-index,Core,Monitoring & Management...