List <Config> configList = configs.getConfig();
Config config = configList.get(0);
SecurityService securityService = config.getSecurityService();
AuthRealm fileAuthRealm = null;
for (AuthRealm authRealm : securityService.getAuthRealm()) {
if (authRealm.getName().equals(ADMIN_REALM)) {
fileAuthRealm = authRealm;
break;
}
}
if (fileAuthRealm == null) {
report.setMessage(localStrings.getLocalString(
"change.admin.password.adminrealmnotfound", "Server " +
"Error: There is no admin realm to perform this operation"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// Get FileRealm class name, match it with what is expected.
String fileRealmClassName = fileAuthRealm.getClassname();
// Report error if provided impl is not the one expected
if (fileRealmClassName != null &&
!fileRealmClassName.equals(
"com.sun.enterprise.security.auth.realm.file.FileRealm")) {
report.setMessage(
localStrings.getLocalString(
"change.admin.password.adminrealmnotsupported",
"Configured admin realm is not supported."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// ensure we have the file associated with the authrealm
String keyFile = null;
for (Property fileProp : fileAuthRealm.getProperty()) {
if (fileProp.getName().equals("file"))
keyFile = fileProp.getValue();
}
if (keyFile == null) {
report.setMessage(
localStrings.getLocalString(
"change.admin.password.keyfilenotfound",
"There is no physical file associated with admin realm"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// We have the right impl so let's get to updating existing user
FileRealm fr = null;
try {
realmsManager.createRealms(config);
fr = (FileRealm) realmsManager.getFromLoadedRealms(config.getName(), fileAuthRealm.getName());
if (fr == null) {
throw new NoSuchRealmException(fileAuthRealm.getName());
}
} catch(NoSuchRealmException e) {
report.setMessage(
localStrings.getLocalString(
"change.admin.password.realmnotsupported",