Search in sources :

Example 1 with IRoleManager

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

use of com.helger.photon.security.role.IRoleManager in project phoss-smp by phax.

the class SMPSecurity method init.

public static void init() {
    LOGGER.info("Starting to initialize SMP security");
    final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
    final IUserGroupManager aUserGroupMgr = PhotonSecurityManager.getUserGroupMgr();
    final IRoleManager aRoleMgr = PhotonSecurityManager.getRoleMgr();
    // Standard users
    if (!aUserMgr.containsWithID(CSMP.USER_ADMINISTRATOR_ID)) {
        final boolean bDisabled = false;
        aUserMgr.createPredefinedUser(CSMP.USER_ADMINISTRATOR_ID, CSMP.USER_ADMINISTRATOR_LOGINNAME, CSMP.USER_ADMINISTRATOR_EMAIL, CSMP.USER_ADMINISTRATOR_PASSWORD, CSMP.USER_ADMINISTRATOR_FIRSTNAME, CSMP.USER_ADMINISTRATOR_LASTNAME, CSMP.USER_ADMINISTRATOR_DESCRIPTION, CSMP.USER_ADMINISTRATOR_LOCALE, CSMP.USER_ADMINISTRATOR_CUSTOMATTRS, bDisabled);
    }
    // Create all roles
    if (!aRoleMgr.containsWithID(CSMP.ROLE_CONFIG_ID))
        aRoleMgr.createPredefinedRole(CSMP.ROLE_CONFIG_ID, CSMP.ROLE_CONFIG_NAME, CSMP.ROLE_CONFIG_DESCRIPTION, CSMP.ROLE_CONFIG_CUSTOMATTRS);
    if (!aRoleMgr.containsWithID(CSMP.ROLE_WRITABLERESTAPI_ID))
        aRoleMgr.createPredefinedRole(CSMP.ROLE_WRITABLERESTAPI_ID, CSMP.ROLE_WRITABLERESTAPI_NAME, CSMP.ROLE_WRITABLERESTAPI_DESCRIPTION, CSMP.ROLE_WRITABLERESTAPI_CUSTOMATTRS);
    // User group Administrators
    if (!aUserGroupMgr.containsWithID(CSMP.USERGROUP_ADMINISTRATORS_ID)) {
        aUserGroupMgr.createPredefinedUserGroup(CSMP.USERGROUP_ADMINISTRATORS_ID, CSMP.USERGROUP_ADMINISTRATORS_NAME, CSMP.USERGROUP_ADMINISTRATORS_DESCRIPTION, CSMP.USERGROUP_ADMINISTRATORS_CUSTOMATTRS);
        // Assign administrator user to administrators user group
        aUserGroupMgr.assignUserToUserGroup(CSMP.USERGROUP_ADMINISTRATORS_ID, CSMP.USER_ADMINISTRATOR_ID);
    }
    aUserGroupMgr.assignRoleToUserGroup(CSMP.USERGROUP_ADMINISTRATORS_ID, CSMP.ROLE_CONFIG_ID);
    aUserGroupMgr.assignRoleToUserGroup(CSMP.USERGROUP_ADMINISTRATORS_ID, CSMP.ROLE_WRITABLERESTAPI_ID);
    // User group for Config users
    if (!aUserGroupMgr.containsWithID(CSMP.USERGROUP_CONFIG_ID))
        aUserGroupMgr.createPredefinedUserGroup(CSMP.USERGROUP_CONFIG_ID, CSMP.USERGROUP_CONFIG_NAME, CSMP.USERGROUP_CONFIG_DESCRIPTION, CSMP.USERGROUP_CONFIG_CUSTOMATTRS);
    aUserGroupMgr.assignRoleToUserGroup(CSMP.USERGROUP_CONFIG_ID, CSMP.ROLE_CONFIG_ID);
    // User group for Writable REST API users
    if (!aUserGroupMgr.containsWithID(CSMP.USERGROUP_WRITABLERESTAPI_ID))
        aUserGroupMgr.createPredefinedUserGroup(CSMP.USERGROUP_WRITABLERESTAPI_ID, CSMP.USERGROUP_WRITABLERESTAPI_NAME, CSMP.USERGROUP_WRITABLERESTAPI_DESCRIPTION, CSMP.USERGROUP_WRITABLERESTAPI_CUSTOMATTRS);
    aUserGroupMgr.assignRoleToUserGroup(CSMP.USERGROUP_WRITABLERESTAPI_ID, CSMP.ROLE_WRITABLERESTAPI_ID);
    // New login logs out old user
    LoggedInUserManager.getInstance().setLogoutAlreadyLoggedInUser(true);
    // Setup internal error handler (if configured)
    SMPInternalErrorHandler.doSetup();
    LOGGER.info("Finished initializing SMP security");
}
Also used : IUserManager(com.helger.photon.security.user.IUserManager) IRoleManager(com.helger.photon.security.role.IRoleManager) IUserGroupManager(com.helger.photon.security.usergroup.IUserGroupManager)

Example 3 with IRoleManager

use of com.helger.photon.security.role.IRoleManager in project peppol-practical by phax.

the class AppSecurity method init.

public static void init() {
    final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
    final IUserGroupManager aUserGroupMgr = PhotonSecurityManager.getUserGroupMgr();
    final IRoleManager aRoleMgr = PhotonSecurityManager.getRoleMgr();
    // Standard users
    if (!aUserMgr.containsWithID(CPPApp.USER_ADMINISTRATOR_ID)) {
        final boolean bDisabled = false;
        aUserMgr.createPredefinedUser(CPPApp.USER_ADMINISTRATOR_ID, CPPApp.USER_ADMINISTRATOR_LOGINNAME, CPPApp.USER_ADMINISTRATOR_EMAIL, CPPApp.USER_ADMINISTRATOR_PASSWORD, CPPApp.USER_ADMINISTRATOR_FIRSTNAME, CPPApp.USER_ADMINISTRATOR_LASTNAME, CPPApp.USER_ADMINISTRATOR_DESCRIPTION, CPPApp.USER_ADMINISTRATOR_LOCALE, CPPApp.USER_ADMINISTRATOR_CUSTOMATTRS, bDisabled);
    }
    // Create all roles
    if (!aRoleMgr.containsWithID(CPPApp.ROLE_CONFIG_ID))
        aRoleMgr.createPredefinedRole(CPPApp.ROLE_CONFIG_ID, CPPApp.ROLE_CONFIG_NAME, CPPApp.ROLE_CONFIG_DESCRIPTION, CPPApp.ROLE_CONFIG_CUSTOMATTRS);
    if (!aRoleMgr.containsWithID(CPPApp.ROLE_VIEW_ID))
        aRoleMgr.createPredefinedRole(CPPApp.ROLE_VIEW_ID, CPPApp.ROLE_VIEW_NAME, CPPApp.ROLE_VIEW_DESCRIPTION, CPPApp.ROLE_VIEW_CUSTOMATTRS);
    if (!aRoleMgr.containsWithID(CPPApp.ROLE_COMMENT_MODERATOR_ID))
        aRoleMgr.createPredefinedRole(CPPApp.ROLE_COMMENT_MODERATOR_ID, CPPApp.ROLE_COMMENT_MODERATOR_NAME, CPPApp.ROLE_COMMENT_MODERATOR_DESCRIPTION, CPPApp.ROLE_COMMENT_MODERATOR_CUSTOMATTRS);
    if (!aRoleMgr.containsWithID(CPPApp.ROLE_PEPPOL_SENDERS_ID))
        aRoleMgr.createPredefinedRole(CPPApp.ROLE_PEPPOL_SENDERS_ID, CPPApp.ROLE_PEPPOL_SENDERS_NAME, CPPApp.ROLE_PEPPOL_SENDERS_DESCRIPTION, CPPApp.ROLE_PEPPOL_SENDERS_CUSTOMATTRS);
    // User group Administrators
    if (!aUserGroupMgr.containsWithID(CPPApp.USERGROUP_ADMINISTRATORS_ID)) {
        aUserGroupMgr.createPredefinedUserGroup(CPPApp.USERGROUP_ADMINISTRATORS_ID, CPPApp.USERGROUP_ADMINISTRATORS_NAME, CPPApp.USERGROUP_ADMINISTRATORS_DESCRIPTION, CPPApp.USERGROUP_ADMINISTRATORS_CUSTOMATTRS);
        // Assign administrator user to administrators user group
        aUserGroupMgr.assignUserToUserGroup(CPPApp.USERGROUP_ADMINISTRATORS_ID, CPPApp.USER_ADMINISTRATOR_ID);
    }
    aUserGroupMgr.assignRoleToUserGroup(CPPApp.USERGROUP_ADMINISTRATORS_ID, CPPApp.ROLE_CONFIG_ID);
    aUserGroupMgr.assignRoleToUserGroup(CPPApp.USERGROUP_ADMINISTRATORS_ID, CPPApp.ROLE_VIEW_ID);
    aUserGroupMgr.assignRoleToUserGroup(CPPApp.USERGROUP_ADMINISTRATORS_ID, CPPApp.ROLE_COMMENT_MODERATOR_ID);
    aUserGroupMgr.assignRoleToUserGroup(CPPApp.USERGROUP_ADMINISTRATORS_ID, CPPApp.ROLE_PEPPOL_SENDERS_ID);
    // User group for Config users
    if (!aUserGroupMgr.containsWithID(CPPApp.USERGROUP_CONFIG_ID))
        aUserGroupMgr.createPredefinedUserGroup(CPPApp.USERGROUP_CONFIG_ID, CPPApp.USERGROUP_CONFIG_NAME, CPPApp.USERGROUP_CONFIG_DESCRIPTION, CPPApp.USERGROUP_CONFIG_CUSTOMATTRS);
    aUserGroupMgr.assignRoleToUserGroup(CPPApp.USERGROUP_CONFIG_ID, CPPApp.ROLE_CONFIG_ID);
    // User group for View users
    if (!aUserGroupMgr.containsWithID(CPPApp.USERGROUP_VIEW_ID))
        aUserGroupMgr.createPredefinedUserGroup(CPPApp.USERGROUP_VIEW_ID, CPPApp.USERGROUP_VIEW_NAME, CPPApp.USERGROUP_VIEW_DESCRIPTION, CPPApp.USERGROUP_VIEW_CUSTOMATTRS);
    aUserGroupMgr.assignRoleToUserGroup(CPPApp.USERGROUP_VIEW_ID, CPPApp.ROLE_VIEW_ID);
}
Also used : IUserManager(com.helger.photon.security.user.IUserManager) IRoleManager(com.helger.photon.security.role.IRoleManager) IUserGroupManager(com.helger.photon.security.usergroup.IUserGroupManager)

Example 4 with IRoleManager

use of com.helger.photon.security.role.IRoleManager in project phoss-directory by phax.

the class AppSecurity method init.

public static void init() {
    final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
    final IUserGroupManager aUserGroupMgr = PhotonSecurityManager.getUserGroupMgr();
    final IRoleManager aRoleMgr = PhotonSecurityManager.getRoleMgr();
    // Standard users
    if (!aUserMgr.containsWithID(USER_ADMINISTRATOR_ID)) {
        final boolean bDisabled = false;
        aUserMgr.createPredefinedUser(USER_ADMINISTRATOR_ID, USER_ADMINISTRATOR_LOGINNAME, USER_ADMINISTRATOR_EMAIL, USER_ADMINISTRATOR_PASSWORD, USER_ADMINISTRATOR_FIRSTNAME, USER_ADMINISTRATOR_LASTNAME, USER_ADMINISTRATOR_DESCRIPTION, USER_ADMINISTRATOR_LOCALE, USER_ADMINISTRATOR_CUSTOMATTRS, bDisabled);
    }
    // Create all roles
    if (!aRoleMgr.containsWithID(ROLE_CONFIG_ID))
        aRoleMgr.createPredefinedRole(ROLE_CONFIG_ID, ROLE_CONFIG_NAME, ROLE_CONFIG_DESCRIPTION, ROLE_CONFIG_CUSTOMATTRS);
    if (!aRoleMgr.containsWithID(ROLE_VIEW_ID))
        aRoleMgr.createPredefinedRole(ROLE_VIEW_ID, ROLE_VIEW_NAME, ROLE_VIEW_DESCRIPTION, ROLE_VIEW_CUSTOMATTRS);
    if (!aRoleMgr.containsWithID(ROLE_SG_OWNER_ID))
        aRoleMgr.createPredefinedRole(ROLE_SG_OWNER_ID, ROLE_SG_OWNER_NAME, ROLE_SG_OWNER_DESCRIPTION, ROLE_SG_OWNER_CUSTOMATTRS);
    // User group Administrators
    if (!aUserGroupMgr.containsWithID(USERGROUP_ADMINISTRATORS_ID)) {
        aUserGroupMgr.createPredefinedUserGroup(USERGROUP_ADMINISTRATORS_ID, USERGROUP_ADMINISTRATORS_NAME, USERGROUP_ADMINISTRATORS_DESCRIPTION, USERGROUP_ADMINISTRATORS_CUSTOMATTRS);
        // Assign administrator user to administrators user group
        aUserGroupMgr.assignUserToUserGroup(USERGROUP_ADMINISTRATORS_ID, USER_ADMINISTRATOR_ID);
    }
    aUserGroupMgr.assignRoleToUserGroup(USERGROUP_ADMINISTRATORS_ID, ROLE_CONFIG_ID);
    aUserGroupMgr.assignRoleToUserGroup(USERGROUP_ADMINISTRATORS_ID, ROLE_VIEW_ID);
    aUserGroupMgr.assignRoleToUserGroup(USERGROUP_ADMINISTRATORS_ID, ROLE_SG_OWNER_ID);
    // User group for Config users
    if (!aUserGroupMgr.containsWithID(USERGROUP_CONFIG_ID))
        aUserGroupMgr.createPredefinedUserGroup(USERGROUP_CONFIG_ID, USERGROUP_CONFIG_NAME, USERGROUP_CONFIG_DESCRIPTION, USERGROUP_CONFIG_CUSTOMATTRS);
    aUserGroupMgr.assignRoleToUserGroup(USERGROUP_CONFIG_ID, ROLE_CONFIG_ID);
    // User group for View users
    if (!aUserGroupMgr.containsWithID(USERGROUP_VIEW_ID))
        aUserGroupMgr.createPredefinedUserGroup(USERGROUP_VIEW_ID, USERGROUP_VIEW_NAME, USERGROUP_VIEW_DESCRIPTION, USERGROUP_VIEW_CUSTOMATTRS);
    aUserGroupMgr.assignRoleToUserGroup(USERGROUP_VIEW_ID, ROLE_VIEW_ID);
    // Allow to kick old sessions
    LoggedInUserManager.getInstance().setLogoutAlreadyLoggedInUser(true);
}
Also used : IUserManager(com.helger.photon.security.user.IUserManager) IRoleManager(com.helger.photon.security.role.IRoleManager) IUserGroupManager(com.helger.photon.security.usergroup.IUserGroupManager)

Aggregations

IRoleManager (com.helger.photon.security.role.IRoleManager)4 IUserManager (com.helger.photon.security.user.IUserManager)4 IUserGroupManager (com.helger.photon.security.usergroup.IUserGroupManager)3 SMPDBExecutor (com.helger.phoss.smp.backend.sql.SMPDBExecutor)1 RoleManagerJDBC (com.helger.photon.jdbc.security.RoleManagerJDBC)1 UserGroupManagerJDBC (com.helger.photon.jdbc.security.UserGroupManagerJDBC)1 UserManagerJDBC (com.helger.photon.jdbc.security.UserManagerJDBC)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 WebScoped (com.helger.web.scope.mgr.WebScoped)1 File (java.io.File)1