use of com.helger.photon.security.role.Role in project phoss-smp by phax.
the class V10__MigrateRolesToDB method migrate.
public void migrate(@Nonnull final Context context) throws Exception {
try (final WebScoped aWS = new WebScoped()) {
LOGGER.info("Migrating all roles to the DB");
final String sFilename = PhotonSecurityManager.FactoryXML.DIRECTORY_SECURITY + PhotonSecurityManager.FactoryXML.FILENAME_ROLES_XML;
final File aFile = WebFileIO.getDataIO().getFile(sFilename);
if (aFile.exists()) {
final RoleManager aMgrXML = new RoleManager(sFilename);
final ICommonsList<IRole> aRoles = aMgrXML.getAll();
if (aRoles.isNotEmpty()) {
final RoleManagerJDBC aMgrNew = new RoleManagerJDBC(SMPDBExecutor::new, SMPDBExecutor.TABLE_NAME_CUSTOMIZER);
for (final IRole aRole : aRoles) {
// Don't run the callback here
if (aMgrNew.internalCreateNewRole((Role) aRole, false, false) == null)
LOGGER.error("Failed to migrate role " + aRole + " to DB");
}
}
// Rename to avoid later inconsistencies
WebFileIO.getDataIO().renameFile(sFilename, sFilename + ".migrated");
LOGGER.info("Finished migrating all " + aRoles.size() + " roles to the DB");
} else {
LOGGER.warn("No role file found");
}
}
}
Aggregations