Package de.innovationgate.webgate.api

Examples of de.innovationgate.webgate.api.WGDatabase


    public WGDatabase connectPlugin(WGAPlugin plugin, Map domainConfigs) throws InvalidPluginException, WGIllegalArgumentException, FileSystemException, IOException {

            // Look if already connected to the correct file
            String dbKey = plugin.buildDatabaseKey();
            WGDatabase db = contentdbs.get(dbKey);
            if (db != null) {
                try {
                    Long pluginFileTime = (Long) db.getAttribute(DBATTRIB_PLUGIN_FILETIME);
                    Version pluginVersion = (Version) db.getAttribute(DBATTRIB_PLUGIN_VERSION);
                    if (pluginVersion.equals(plugin.getPluginID().getVersion()) &&
                        (pluginFileTime != null && pluginFileTime.equals(new Long(plugin.getFileLastModified())))) {
                        if (!db.isSessionOpen()) {
                            db.openSession();
                        }
                        return db;
                    }
                    else {
                        removeContentDB(dbKey);
                        db = null;
                    }
                }           
                catch (Exception e) {
                    throw new InvalidPluginException(plugin, "Error checking existent plugin database " + dbKey, e);
                }
            }

            if (!plugin.isActive()) {
                throw new InvalidPluginException(plugin, "Plugin is deactivated");
            }
            if (!plugin.isValid()) {
                throw new InvalidPluginException(plugin, "Plugin is invalid");
            }

           
            // First connect all mandatory plugins
            try {

                Iterator mandatoryPlugins = plugin.getMandatoryPlugins().values().iterator();
                while (mandatoryPlugins.hasNext()) {
                    WGAPlugin mandatoryPlugin  = (WGAPlugin) mandatoryPlugins.next();
                    connectPlugin(mandatoryPlugin, domainConfigs);
                }
            }
            // A mandatory plugin is invalid. Cancel connect.
            catch (InvalidPluginException e) {
                throw e;
            }
  
            logCategoryInfo("Plugin " + plugin.getInstallationKey(), 2);
           
            // Mandatory db options (for plugins)
            Map<String, String> dbOptions = new HashMap<String, String>();
            dbOptions.put(WGDatabase.COPTION_DBREFERENCE, dbKey.toLowerCase());
            dbOptions.put(WGDatabase.COPTION_READERPROFILECREATION, "true");
            dbOptions.put(WGDatabase.COPTION_USERCACHELATENCY, String.valueOf(_wgaConfiguration.getUserCacheLatencyMinutes()));
           
            // We try to automatically migrate plugin content stores to CS5 format
            dbOptions.put(WGDatabase.COPTION_CONTENT_STORE_VERSION, String.valueOf(WGDatabase.CSVERSION_WGA5));
           
            // Clear the plugin database before connecting if the plugin is updated and should clear the db on update
            if (plugin.getRuntimeContext().isUpdated()) {
                if (plugin.getCsConfig().getPluginConfig() instanceof de.innovationgate.wga.common.beans.csconfig.v3.PluginConfig) {
                    de.innovationgate.wga.common.beans.csconfig.v3.PluginConfig v3Config = (de.innovationgate.wga.common.beans.csconfig.v3.PluginConfig) plugin.getCsConfig().getPluginConfig();
                    if (v3Config.isClearDatabaseOnUpdate()) {
                        getLog().info("Clearing plugin database for installation key " + plugin.getInstallationKey());
                        plugin.getParent().deletePluginDatabase(plugin);
                    }
                }
                plugin.getRuntimeContext().setUpdated(false);
            }
           
            // Connect
            getLog().info("Connecting plugin " + plugin.getPluginID().getUniqueName() + " Version " + plugin.getPluginID().getVersion().toString());
              
            try {
                db = WGFactory.getInstance().openDatabase(null, de.innovationgate.webgate.api.hsql.WGDatabaseImpl.class.getName(), plugin.buildDatabasePath(), null, null, dbOptions);
            }
            catch (Throwable e1) {
                throw new InvalidPluginException(plugin, "Could not connect plugin \"" + plugin.getPluginID().getUniqueName() + "\"", e1);
            }

            if (db == null || !db.isSessionOpen()) {
                throw new InvalidPluginException(plugin, "Could not connect plugin \"" + plugin.getPluginID().getUniqueName() + "\" - Check logged messages above for error details");
            }

            try {
                db.getSessionContext().setTask("Initializing database in WGA");
               
                // Plugin dbs are always CS5 since they are automatically migrated
                //getLog().info("Database of plugin " + plugin.getPluginID().getUniqueName() + " is content store version " + db.getContentStoreVersion());
               
                PluginConfig pc = plugin.getCsConfig().getPluginConfig();
                String auth = pc.getAuthentication();
                db.setTitle(pc.getTitle());
               
               
                // Set mandatory database attributes
                initializeDBAttributes(db, dbKey, dbKey, new HashSet());
               
                // Create authentication
                if (auth != null) {
                    String authImplClass = null;
                    Map<String,String> authOptions = new HashMap<String, String>();
                   
                    // Delegate authentication to the default domain
                    if (auth.equals(PluginConfig.AUTHSOURCE_DEFAULT_DOMAIN)) {
                        authImplClass = WGAAuthModuleFactory.AUTHMODULE_DELEGATE;
                        authOptions.put(DelegatingAuthModule.COPTION_DOMAIN, "default");
                    }
                    // Use some plugin for authentication
                    else {
                        WGAPlugin authPlugin = plugin.getParent().getPluginByUniqueName(auth);
                    if (authPlugin != null) {
                        authImplClass = CSAuthModule.class.getName();
                        authOptions.put(CSAuthModule.COPTION_DBKEY, authPlugin.buildDatabaseKey());
                    }
                    else {
                            getLog().error("Unable to find authentication plugin " + auth);
                        }
                    }
                   
                    if (authImplClass != null) {
                        AuthenticationModule authModule = WGFactory.getAuthModuleFactory().getAuthModule(authImplClass, authOptions, db);
                        db.setAuthenticationModule(authModule);
                    }
                   
                }
               
                // Enforce some plugin settings via db attributes
                db.setAttribute(DBATTRIB_PERSMODE, String.valueOf(pc.getPersonalisationMode()));
                db.setAttribute(DBATTRIB_PERSSTATMODE, String.valueOf(Constants.PERSSTATMODE_SESSION));
                db.setAttribute(DBATTRIB_PLUGIN_FILETIME, new Long(plugin.getFileLastModified()));
                db.setAttribute(DBATTRIB_PLUGIN_ID, plugin.getPluginID());
                db.setAttribute(DBATTRIB_PLUGIN_VERSION, plugin.getPluginID().getVersion());
               
                if (!pc.isUsageAsContentStore()) {
                    db.setAttribute(DBATTRIB_ALLOW_PUBLISHING, "false");
                }
               
                if (!pc.isShowOnStartPage()) {
                    db.setAttribute(DBATTRIB_STARTPAGE, "false");
                }
   
                // Configure design provider
                DesignReference ref = new DesignReference(Constants.DESIGNCOL_PLUGIN, plugin.getInstallationKey(), null);
                db.setDesignProvider(new FileSystemDesignProvider(ref, this, db, plugin.getDesignURL().toString(), Collections.EMPTY_MAP));
                db.setAllowDesignModification(false);
              
                // Determine if ACL is empty
                boolean aclEmpty = false;
                try {
                    if (db.isConnected() && db.hasFeature(WGDatabase.FEATURE_ACL_MANAGEABLE) && db.getACL().getAllEntries().size() == 0) {
                        aclEmpty = true;
                    }
                }
                catch (WGBackendException e1) {
                    getLog().error("Error retrieving ACL state of db '" + db.getDbReference() + "'", e1);
                }
               
                // Process system container
                SystemContainerManager.SystemContainerContext scContext = null;
                try {
                    scContext = _systemContainerManager.addDatabase(db, plugin, aclEmpty);
                }
                catch (Exception e) {
                    this.log.error("Exception processing system file container for plugin '" + plugin.getPluginID().getUniqueName() + "'", e);
                }
                       
                // Build map of publisher options from wga.xml. We only use gobal options here since plugins have no own options in wga.xml
                // and csconfig.xml options are processed via system container
                Map<String, String> publisherOptions = new HashMap<String, String>();
                // publisherOptions.putAll(_globalPublisherOptions); Plugins should not be influenced by global options of the current configuration
                if (scContext != null) {
                    scContext.putPublisherOptions(publisherOptions);
                }
   
                // Publisher options initialisation which is equal for content dbs and plugins
                processPublisherOptions(db, publisherOptions);
               
                // Set plugin homepage. The method chooses either the plugin-specific homepage or the publisher option
                // Must be after publisher option initialisation to be able to react on them
                db.setAttribute(DBATTRIB_HOME_PAGE, plugin.getPluginHomepage());
               
                // check if db is empty before hdb script runs
                boolean isEmptyDB = db.isContentEmpty();
                               
                // Validate default language definition
                if (!isEmptyDB) {
                    db.determineDefaultLanguage();
                }
                                                               
                // System container initialisations
                if (scContext != null) {
                    scContext.performInitialisation(new Boolean(isEmptyDB));
                    if (isEmptyDB) {
                        db.onConnect(new ValidateDefaultLanguageAction());
                    }
                }
               
                // Registering connection
                this.contentdbs.put(db.getDbReference(), db);
                performNewDBOperations(db);
               
                // Mark this database as fully connected
                db.setAttribute(DBATTRIB_FULLY_CONNECTED, "true");
               
                // Initially create field mappings. These can only come from csconfig.xml for plugins
                updateFieldMappings(db, null);
               
                return db;
            }
            catch (Throwable e) {
                try {
                    db.close();
                }
                catch (WGAPIException e2) {
                    // Silent failure of closing an uninitialized plugin bc. the connection failure is more important
                }
                plugin.setValid(false);
View Full Code Here


    }

    public String getDesignDatabaseKey(String dbkey) {

        WGDatabase db = getContentdbs().get(dbkey);
        if (db == null) {
            return dbkey;
        }

        return getDesignDatabaseKey(db);
View Full Code Here

        dir.mkdir();
       
        // Create dump database
        Map<String, String> options = new HashMap<String, String>();
        options.put(WGDatabase.COPTION_MONITORLASTCHANGE, "false");
        WGDatabase dbTarget = WGFactory.getInstance().openDatabase(null, de.innovationgate.webgate.api.hsql.WGDatabaseImpl.class.getName(), dir.getAbsolutePath() + "/wgacs", "sa", null, options);
        dbTarget.setDbReference("Temporary WGACS dump target");
       
        // Replicate
        log.info("Synchronizing data to dump database");
        dbSource.lock();
        try {
            ContentStoreDumpManager importer = new ContentStoreDumpManager(dbSource, dbTarget, log);
            importer.exportDump(includeACL, includeSystemAreas);
        }
        finally {
            dbSource.unlock();
        }
       
        // Close database and zip up its contents
        log.info("Creating dump file");
        dbTarget.close();
        File zipFile = File.createTempFile("csz", ".tmp", WGFactory.getTempDir());
        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
        out.setLevel(9);
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; i++) {
View Full Code Here

        }
       
        // Open dump database
        Map<String, String> options = new HashMap<String, String>();
        options.put(WGDatabase.COPTION_MONITORLASTCHANGE, "false");
        WGDatabase sourceDB = WGFactory.getInstance().openDatabase(null, de.innovationgate.webgate.api.hsql.WGDatabaseImpl.class.getName(), dir.getAbsolutePath() + "/wgacs", null, null, options);
        sourceDB.setDbReference("WGA Content Store Initial data dump");
       
        if (log != null) {
            log.info("Importing dump data");
        }
       
        // Do the dump
        ContentStoreDumpManager importer = new ContentStoreDumpManager(sourceDB, targetDB, log);
        boolean result = importer.importDump(includeACL, includeSystemAreas);
       
        // Close dump database
        sourceDB.close();
       
        return result;
    }
View Full Code Here

            if (dbObjs.isEmpty()) {
                return false;
            }

            Iterator<WGDatabase> dbs = getContentdbs().values().iterator();
            WGDatabase db = null;
            int accessLevel = WGDatabase.ACCESSLEVEL_NOTLOGGEDIN;
           
            // Do a login on the first database found that belongs to this domain
            while (dbs.hasNext()) {
                db = dbs.next();
                String compareDomain = (String) db.getAttribute(WGACore.DBATTRIB_DOMAIN);
                if (compareDomain != null && compareDomain.equalsIgnoreCase(domain)) {
                    accessLevel = getBruteForceLoginBlocker().login(db, user, password);
                    if (accessLevel > WGDatabase.ACCESSLEVEL_NOTLOGGEDIN) {
                        isLoginSuccessful = true;
                        if (db.isSessionOpen()) {
                            setSessionCookie(request, response, db);
                        }
                        break;
                    } else {
                        // unable to login to db of domain
                        // do not try to login to further dbs in this domain bc.
                        // - each db of a domain must support the same auth information
                        // - we will block the login to early bc. each further login request are counted by bruteForceLoginBlocker
                        isLoginSuccessful = false;
                        break;
                    }
                }
            }
        }
       

        // React on login success
        if (isLoginSuccessful) {
           
            // First do a logout for sure
            logout(domain, request.getSession());
           
            getSessionLogins(request.getSession()).put(domain, new DBLoginInfo(user, password));
           
            // F00004852
            // perform a reopenSession on all opened databases of this domain
            Iterator<WGDatabase> dbsInDomain = getDatabasesForDomain(domain).iterator();
            while (dbsInDomain.hasNext()) {
              WGDatabase db = dbsInDomain.next();
              if (db.isSessionOpen()) {
                db.reopenSession(user, password);
              }
            }
           
            return true;
        } else {
View Full Code Here

       
    }

    public void disconnectPlugin(WGAPlugin plugin) {
        String dbKey = plugin.buildDatabaseKey();
        WGDatabase db = this.contentdbs.get(dbKey);
        if (db != null) {
            getLog().info("Disconnecting plugin " + plugin.getPluginID().getUniqueName() + " Version " + plugin.getPluginID().getVersion().toString());
            removeContentDB(dbKey);
        }
       
View Full Code Here

        List<String> designs = new ArrayList<String>();
        Iterator<WGAPlugin> plugins = _core.getPluginSet().getPlugins().iterator();
        while (plugins.hasNext()) {
            WGAPlugin plugin = (WGAPlugin) plugins.next();
            if (plugin.isActive() && plugin.isValid() && plugin.getCsConfig().getPluginConfig().isUsageAsDesignProvider()) {
                WGDatabase db = _core.getContentdbs().get(plugin.buildDatabaseKey());
                if (db != null) {
                    designs.add(plugin.getInstallationKey());
                }
            }
        }
View Full Code Here

        WGAPlugin plugin = _core.getPluginSet().getPluginsByInstallationKey().get(name);
        if (plugin == null || !(plugin.isActive() && plugin.isValid() && plugin.getCsConfig().getPluginConfig().isUsageAsDesignProvider())) {
            return null;
        }
           
        WGDatabase db = _core.getContentdbs().get(plugin.buildDatabaseKey());
        if (db == null) {
            return null;
        }
       
        WGADesign design = new WGADesign();
View Full Code Here

    HttpSession session = getEnvironment().getPageContext().getSession();
    if (session == null) {
      return TMLUserProfile.RC_NO_SESSION;
    }

    WGDatabase persDB = getwgacore().openPersonalisationDB(domain, session);
    if (persDB == null) {
      return TMLUserProfile.RC_NOT_PERSONALIZED;
    }

    //  ensure persdb is in correct mode (custom)
    Integer persMode = Integer.valueOf((String) getwgacore().readPublisherOptionOrDefault(getDesignContext().getDesignDB(), WGACore.DBATTRIB_PERSMODE));
    if (persMode.intValue() != Constants.PERSMODE_CUSTOM) {
      return TMLUserProfile.RC_WRONG_PERSMODE;
    }

    // Ensure, there is no profile yet with this name
    WGUserProfile profile = persDB.getUserProfile(name);
    if (profile != null) {
      return TMLUserProfile.RC_PROFILE_EXISTS;
    }

    // Try to create the profile
    try {
      profile = persDB.createUserProfile(name, Constants.PERSMODE_CUSTOM);
    }
    catch (WGException e) {
      this.addwarning("Exception creating user profile: " + e.getMessage(), true);
    }
    if (profile == null) {
View Full Code Here

    HttpSession session = getEnvironment().getPageContext().getSession();
    if (session == null) {
      return TMLUserProfile.RC_NO_SESSION;
    }
    WGDatabase persDB = getwgacore().openPersonalisationDB(domain, session);
    if (persDB == null) {
      return TMLUserProfile.RC_NOT_PERSONALIZED;
    }

    //  ensure database is in correct mode (custom)
    Integer persMode = Integer.valueOf((String) getwgacore().readPublisherOptionOrDefault(getDesignContext().getDesignDB(), WGACore.DBATTRIB_PERSMODE));
    if (persMode.intValue() != Constants.PERSMODE_CUSTOM) {
      return TMLUserProfile.RC_WRONG_PERSMODE;
    }

    // Try to fetch profile
    WGUserProfile profile = persDB.getUserProfile(name);
    if (profile == null) {
      return TMLUserProfile.RC_NO_PROFILE;
    }

    // Test password
View Full Code Here

TOP

Related Classes of de.innovationgate.webgate.api.WGDatabase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.