Search in sources :

Example 1 with RoleManagerJDBC

use of com.helger.photon.jdbc.security.RoleManagerJDBC in project phoss-smp by phax.

the class V12__MigrateUserGroupsToDB method migrate.

public void migrate(@Nonnull final Context context) throws Exception {
    try (final WebScoped aWS = new WebScoped()) {
        LOGGER.info("Migrating all user groups to the DB");
        final String sFilename = PhotonSecurityManager.FactoryXML.DIRECTORY_SECURITY + PhotonSecurityManager.FactoryXML.FILENAME_USERGROUPS_XML;
        final File aFile = WebFileIO.getDataIO().getFile(sFilename);
        if (aFile.exists()) {
            final IUserManager aUserMgr = new UserManagerJDBC(SMPDBExecutor::new, SMPDBExecutor.TABLE_NAME_CUSTOMIZER);
            final IRoleManager aRoleMgr = new RoleManagerJDBC(SMPDBExecutor::new, SMPDBExecutor.TABLE_NAME_CUSTOMIZER);
            final UserGroupManager aMgrXML = new UserGroupManager(sFilename, aUserMgr, aRoleMgr);
            final ICommonsList<IUserGroup> aUserGroups = aMgrXML.getAll();
            if (aUserGroups.isNotEmpty()) {
                final UserGroupManagerJDBC aMgrNew = new UserGroupManagerJDBC(SMPDBExecutor::new, SMPDBExecutor.TABLE_NAME_CUSTOMIZER, aUserMgr, aRoleMgr);
                for (final IUserGroup aUserGroup : aUserGroups) {
                    // Don't run the callback here
                    if (aMgrNew.internalCreateNewUserGroup((UserGroup) aUserGroup, false, false) == null)
                        LOGGER.error("Failed to migrate user group " + aUserGroup + " to DB");
                }
            }
            // Rename to avoid later inconsistencies
            WebFileIO.getDataIO().renameFile(sFilename, sFilename + ".migrated");
            LOGGER.info("Finished migrating all " + aUserGroups.size() + " user groups to the DB");
        } else {
            LOGGER.warn("No user group file found");
        }
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) UserGroupManager(com.helger.photon.security.usergroup.UserGroupManager) IUserManager(com.helger.photon.security.user.IUserManager) IUserGroup(com.helger.photon.security.usergroup.IUserGroup) SMPDBExecutor(com.helger.phoss.smp.backend.sql.SMPDBExecutor) UserGroup(com.helger.photon.security.usergroup.UserGroup) IUserGroup(com.helger.photon.security.usergroup.IUserGroup) IRoleManager(com.helger.photon.security.role.IRoleManager) UserGroupManagerJDBC(com.helger.photon.jdbc.security.UserGroupManagerJDBC) UserManagerJDBC(com.helger.photon.jdbc.security.UserManagerJDBC) RoleManagerJDBC(com.helger.photon.jdbc.security.RoleManagerJDBC) File(java.io.File)

Example 2 with RoleManagerJDBC

use of com.helger.photon.jdbc.security.RoleManagerJDBC 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");
        }
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) IRole(com.helger.photon.security.role.IRole) Role(com.helger.photon.security.role.Role) IRole(com.helger.photon.security.role.IRole) RoleManager(com.helger.photon.security.role.RoleManager) RoleManagerJDBC(com.helger.photon.jdbc.security.RoleManagerJDBC) File(java.io.File) SMPDBExecutor(com.helger.phoss.smp.backend.sql.SMPDBExecutor)

Aggregations

SMPDBExecutor (com.helger.phoss.smp.backend.sql.SMPDBExecutor)2 RoleManagerJDBC (com.helger.photon.jdbc.security.RoleManagerJDBC)2 WebScoped (com.helger.web.scope.mgr.WebScoped)2 File (java.io.File)2 UserGroupManagerJDBC (com.helger.photon.jdbc.security.UserGroupManagerJDBC)1 UserManagerJDBC (com.helger.photon.jdbc.security.UserManagerJDBC)1 IRole (com.helger.photon.security.role.IRole)1 IRoleManager (com.helger.photon.security.role.IRoleManager)1 Role (com.helger.photon.security.role.Role)1 RoleManager (com.helger.photon.security.role.RoleManager)1 IUserManager (com.helger.photon.security.user.IUserManager)1 IUserGroup (com.helger.photon.security.usergroup.IUserGroup)1 UserGroup (com.helger.photon.security.usergroup.UserGroup)1 UserGroupManager (com.helger.photon.security.usergroup.UserGroupManager)1