public void validateAdminUserAndPassword(RepositoryConfig config,
String user, String password) throws RepositoryException
{
try {
//Read in domain.xml. This will fail with a ConfigException if there is no domain.xml
final PEFileLayout layout = getFileLayout(config);
ConfigContext configContext = getConfigContext(config);
//Fetch the name of the realm for the DAS system jmx connector
String dasName = ServerHelper.getDAS(configContext).getName();
JmxConnector conn = ServerHelper.getServerSystemConnector(configContext,
dasName);
String realmName = conn.getAuthRealmName();
SecurityService security = ServerHelper.getConfigForServer(configContext,
dasName).getSecurityService();
//Load in the file realm
//Before loading the realm, we must ensure that com.sun.aas.instanceRoot
//is set correcty, since the keyfile is most likely referenced using this.
//In addition java.security.auth.login.config must be setup.
String oldRoot = System.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY);
String oldConf = System.getProperty("java.security.auth.login.config");
System.setProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY,
layout.getRepositoryDir().getAbsolutePath());
System.setProperty("java.security.auth.login.config",
layout.getLoginConf().getAbsolutePath());
RealmConfig.createRealms(realmName,
new AuthRealm[] {security.getAuthRealmByName(realmName)});
//Restore previous values just in case.
if (oldRoot != null) {
System.setProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY, oldRoot);