Search in sources :

Example 1 with IRole

use of com.helger.photon.security.role.IRole 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)

Example 2 with IRole

use of com.helger.photon.security.role.IRole 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);
}
Also used : Locale(java.util.Locale) IRole(com.helger.photon.security.role.IRole) IUserGroup(com.helger.photon.security.usergroup.IUserGroup) HCA(com.helger.html.hc.html.textlevel.HCA) IUser(com.helger.photon.security.user.IUser) IMenuObject(com.helger.photon.core.menu.IMenuObject) PDTToString(com.helger.commons.datetime.PDTToString) HCTextNode(com.helger.html.hc.impl.HCTextNode) Nonnull(javax.annotation.Nonnull)

Aggregations

IRole (com.helger.photon.security.role.IRole)2 PDTToString (com.helger.commons.datetime.PDTToString)1 HCA (com.helger.html.hc.html.textlevel.HCA)1 HCTextNode (com.helger.html.hc.impl.HCTextNode)1 SMPDBExecutor (com.helger.phoss.smp.backend.sql.SMPDBExecutor)1 IMenuObject (com.helger.photon.core.menu.IMenuObject)1 RoleManagerJDBC (com.helger.photon.jdbc.security.RoleManagerJDBC)1 Role (com.helger.photon.security.role.Role)1 RoleManager (com.helger.photon.security.role.RoleManager)1 IUser (com.helger.photon.security.user.IUser)1 IUserGroup (com.helger.photon.security.usergroup.IUserGroup)1 WebScoped (com.helger.web.scope.mgr.WebScoped)1 File (java.io.File)1 Locale (java.util.Locale)1 Nonnull (javax.annotation.Nonnull)1