use of com.helger.photon.security.usergroup.IUserGroup 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");
}
}
}
use of com.helger.photon.security.usergroup.IUserGroup in project peppol-practical by phax.
the class AppCommonUI method createViewLink.
@Nonnull
public static IHCNode createViewLink(@Nonnull final IWebPageExecutionContext aWPEC, @Nullable final ITypedObject<String> aObject, @Nullable final String sDisplayName) {
if (aObject == null)
return HCTextNode.createOnDemand(sDisplayName);
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
if (aObject instanceof IRole) {
final IRole aTypedObj = (IRole) aObject;
final String sRealDisplayName = sDisplayName != null ? sDisplayName : aTypedObj.getName();
final String sMenuItemID = BootstrapPagesMenuConfigurator.MENU_ADMIN_SECURITY_ROLE;
final IMenuObject aObj = aWPEC.getMenuTree().getItemDataWithID(sMenuItemID);
if (aObj != null && aObj.matchesDisplayFilter())
return new HCA(getViewLink(aWPEC, sMenuItemID, aTypedObj)).addChild(sRealDisplayName).setTitle("Show details of role '" + sRealDisplayName + "'");
return new HCTextNode(sRealDisplayName);
}
if (aObject instanceof IUser) {
final IUser aTypedObj = (IUser) aObject;
final String sRealDisplayName = sDisplayName != null ? sDisplayName : SecurityHelper.getUserDisplayName(aTypedObj, aDisplayLocale);
final String sMenuItemID = BootstrapPagesMenuConfigurator.MENU_ADMIN_SECURITY_USER;
final IMenuObject aObj = aWPEC.getMenuTree().getItemDataWithID(sMenuItemID);
if (aObj != null && aObj.matchesDisplayFilter())
return new HCA(getViewLink(aWPEC, sMenuItemID, aTypedObj)).addChild(sRealDisplayName).setTitle("Show details of user '" + sRealDisplayName + "'");
return new HCTextNode(sRealDisplayName);
}
if (aObject instanceof IUserGroup) {
final IUserGroup aTypedObj = (IUserGroup) aObject;
final String sRealDisplayName = sDisplayName != null ? sDisplayName : aTypedObj.getName();
final String sMenuItemID = BootstrapPagesMenuConfigurator.MENU_ADMIN_SECURITY_USER_GROUP;
final IMenuObject aObj = aWPEC.getMenuTree().getItemDataWithID(sMenuItemID);
if (aObj != null && aObj.matchesDisplayFilter())
return new HCA(getViewLink(aWPEC, sMenuItemID, aTypedObj)).addChild(sRealDisplayName).setTitle("Show details of user group '" + sRealDisplayName + "'");
return new HCTextNode(sRealDisplayName);
}
// add other types as desired
throw new IllegalArgumentException("Unsupported object: " + aObject);
}
Aggregations