Package com.anthonyeden.lib.config

Examples of com.anthonyeden.lib.config.Configuration


    // Set logAnonymous with value from olat_config.xml
    String _logAnonymous = moduleConfig.getChildValue(CONFIG_LOG_ANONYMOUS);
    logAnonymous = _logAnonymous.equalsIgnoreCase("true") ? true : false;
    log.info("Log Module set logAnonymous to: " + new Boolean(logAnonymous));
    // Set operators with values from olat_config.xml
    Configuration operatorConfiguration = moduleConfig.getChild(CONFIG_LOG_OPERATORS);
    if (operatorConfiguration != null) {
      List operatorList = operatorConfiguration.getChildren();
      for (Iterator iter = operatorList.iterator(); iter.hasNext();) {
        Configuration operator = (Configuration) iter.next();
        operators.add(operator.getValue());
      }
    }
  }
View Full Code Here


  public void init(Configuration moduleConfig) {
    try {
      DBModule.setActivated(true);
      // process database configuration
   
      Configuration databaseConfig = moduleConfig.getChild("database");
      // get database identificator
      String dbmsName = databaseConfig.getAttribute("dbms");
      if (dbmsName == null) throw new AssertException("Missing attribute 'dbms' in element 'database' in olat_config.xml");
 
      // load hibernate configuration for this database identificator
      Configuration databaseElement = databaseConfig.getChild(dbmsName);
      List parameterlist = databaseElement.getChildren();
      Iterator iter = parameterlist.iterator();
      Properties dbProperties = new Properties();
      boolean logDebug = Tracing.isDebugEnabled(DBModule.class);
      while (iter.hasNext()) {
        Configuration conf = (Configuration) iter.next();
        if(logDebug) Tracing.logDebug("Hibernate config: " + conf.getName() + " = " + conf.getValue(), DBModule.class);
        dbProperties.setProperty(conf.getName(), conf.getValue());
      }
      dbPropertiesMap.put(HIBERNATE_CONFIG_PRODUCTIONDB, dbProperties);
     
      // add configuration for junit tests
      if (Settings.isJUnitTest()) {
        Tracing.logInfo("Configuring database for jUnit mode", DBModule.class);
        // copy configuration from production database
        Properties testProperties = (Properties) ObjectCloner.deepCopy(dbProperties);
        // and add override properties for testdb
        Configuration testdboverride = databaseConfig.getChild("hibernate.overridefortestdb");
        List overridelist = testdboverride.getChildren();
        Iterator iterator = overridelist.iterator();
        while (iterator.hasNext()) {
          Configuration conf = (Configuration) iterator.next();
          if(logDebug) Tracing.logDebug("Junit mode, overriding hibernate config: " + conf.getName() + " = " + conf.getValue(), DBModule.class);
          testProperties.setProperty(conf.getName(), conf.getValue());
        }
        dbPropertiesMap.put(HIBERNATE_CONFIG_TESTDB, testProperties);
        // TODO: cg: Workaround to clear database for each test
        Tracing.logInfo("In Junit test mode : Clear database", this.getClass());
        DBJunitImpl.getJunitInstance().clearDatabase();
View Full Code Here

  /**
   * @see org.olat.core.configuration.OLATModule#init(com.anthonyeden.lib.config.Configuration)
   */
  public void init(Configuration configuration) {
    Configuration pwdch = configuration.getChild("pwdchange");
    pwdchangeallowed = Boolean.valueOf(pwdch.getAttribute("allowed")).booleanValue();
   
    // Pre-load login blacklist
    File fBlacklist = new File(WebappHelper.getContextRoot() + "/WEB-INF/blacklist.txt");
    if (fBlacklist.exists()) {
      BufferedReader fReader = null;
      try {
        fReader = new BufferedReader(new FileReader(fBlacklist));
        int count = 0;
        while (fReader.ready()) {
          String regexp = fReader.readLine();
          if (regexp.startsWith("##")) continue;
          else {
            try {
              Pattern.compile(regexp);
            } catch (PatternSyntaxException pse) {
              throw new StartupException("Invalid pattern syntax in blacklist. Pattern: " + regexp);
            }
            loginBlacklist.add(regexp);
            count++;
          }
        }
        Tracing.logInfo("Successfully added " + count + " entries to login blacklist.", UserModule.class);
      } catch (Exception e) {
        throw new StartupException("Unable to read blacklist. Please fix.");
      } finally {
        if (fReader != null) try {
          fReader.close();
        } catch (Exception e) {
          // ok in finally block.
        }
      }
    }

    // Autogeneration of test users
    String generateTestUsers = configuration.getChildValue("generateTestUsers");
    if (generateTestUsers == null) hasTestUsers = false;
    else {
      if (generateTestUsers.equals("true")) {
        hasTestUsers = true;
      } else if (generateTestUsers.equals("false")) {
        hasTestUsers = false;
      } else {
        throw new StartupException("UserModule configuration Element 'generateTestUsers' was set to '" + generateTestUsers
            + "' but only value 'true' or 'false' is allowed.");
      }
    }
    // Check if default users exists, if not create them
    securityManager = ManagerFactory.getManager();
    adminGroup = securityManager.findSecurityGroupByName(Constants.GROUP_ADMIN);
    authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
    olatuserGroup = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
    anonymousGroup = securityManager.findSecurityGroupByName(Constants.GROUP_ANONYMOUS);
    groupmanagerGroup = securityManager.findSecurityGroupByName(Constants.GROUP_GROUPMANAGERS);
    usermanagerGroup = securityManager.findSecurityGroupByName(Constants.GROUP_USERMANAGERS);

    // read user editable fields configuration
    Configuration defaultUsers = configuration.getChild("defaultUsers");
    if (defaultUsers != null) {
      List usersList = defaultUsers.getChildren();
      for (Iterator iter = usersList.iterator(); iter.hasNext();) {
        Configuration user = (Configuration) iter.next();
        createUser(user);
      }
    }
    if (hasTestUsers) {
      // read user editable fields configuration
      Configuration testUsers = configuration.getChild("testUsers");
      if (testUsers != null) {
        List usersList = testUsers.getChildren();
        for (Iterator iter = usersList.iterator(); iter.hasNext();) {
          Configuration user = (Configuration) iter.next();
          createUser(user);
        }
      }
    }
    // Cleanup, otherwhise this subjects will have problems in normal OLAT
View Full Code Here

       
    // initialize user mapping
    OLATUserfieldsMapper.setMapping(moduleConfig.getChild(CONF_OLATUSERMAPPING));
   
    // Set operators
    Configuration operatorConfiguration = moduleConfig.getChild(CONF_LOG_OPERATORS);
    if (operatorConfiguration != null) {
      List operatorList = operatorConfiguration.getChildren();
      for (Iterator iter = operatorList.iterator(); iter.hasNext();) {
        Configuration operator = (Configuration) iter.next();
        operators.add(operator.getValue());
      }
    }
  }
View Full Code Here

    attributeTranslations = new HashMap<String, String>();
    attributeSelectableValues = new HashMap<String, String[]>();
    if (attrTransConfig != null) {
      List transList = attrTransConfig.getChildren();
      for (Iterator iter = transList.iterator(); iter.hasNext();) {
        Configuration attributeTranslation = (Configuration)iter.next();
        if (!attributeTranslation.getName().equals(CONF_ATTRIBUTE)) {
          throw new StartupException("Invalid child config element: " + attributeTranslation);
        }
        String inname = attributeTranslation.getAttribute(CONF_ATTRIBUTE_INNAME);
        String outname = attributeTranslation.getAttribute(CONF_ATTRIBUTE_OUTNAME);
        attributeTranslations.put(inname, outname);
        // check if this attribute has predefined values
        List selectableValues = attributeTranslation.getChildren(CONF_ATTRIBUTE_SELECTABLE_VALUE);
        if (selectableValues != null && selectableValues.size() != 0) {
          // collect selectable values and add them to map
          String[] values = new String[selectableValues.size()];
          for (int i = 0; i < selectableValues.size(); i++) {
            Configuration config = (Configuration) selectableValues.get(i);
            values[i] = config.getValue();
          }
          // key is the translated name to make code simpler
          attributeSelectableValues.put(outname, values);
        }
      }
View Full Code Here

  private static String defaultUniqueIdentifier;
  private static Map uniqueIdentifierMap;

  public UniqueIdentifierMapper(Configuration uidConfig) {
    uniqueIdentifierMap = new HashMap();
    Configuration defaultUidConfig = uidConfig.getChild(CONF_UNIQUEIDENTIFIERS_DEFAULT);
    if (defaultUidConfig == null)
      throw new StartupException("Missing default unique identifier. Please fix!");
    defaultUniqueIdentifier = defaultUidConfig.getAttribute(CONF_UNIQUEIDENTIFIERS_UIDATTRIBUTE);
    List originUidConfig = uidConfig.getChildren(CONF_UNIQUEIDENTIFIERS_ORIGINSITE);
    if (originUidConfig != null) { // fetch origin specific uidAttributes
      for (Iterator iter = originUidConfig.iterator(); iter.hasNext();) {
        Configuration originSite = (Configuration) iter.next();
        uniqueIdentifierMap.put(originSite.getAttribute(CONF_UNIQUEIDENTIFIERS_SITENAME), originSite.getAttribute(CONF_UNIQUEIDENTIFIERS_UIDATTRIBUTE));
      }
    }
  }
View Full Code Here

   */
  public void init(Configuration configuration) {
    // Initialize handlers
    Iterator paths = configuration.getChildren("path").iterator();
    while (paths.hasNext()) {
      Configuration path = (Configuration) paths.next();
      String name = path.getAttribute("name");
      String classname = path.getAttribute("classname");
      if (name != null && classname != null) {
        try {
          Class pathHandler = Class.forName(classname);
          PathHandler o = (PathHandler)pathHandler.newInstance();
          o.init(path);
View Full Code Here

    // fetch authentication providers
    List authProviders = moduleConfig.getChildren(CONF_AUTHPROVIDER);
    Iterator iter = authProviders.iterator();
    authenticationProviders = new HashMap(authProviders.size());
    while (iter.hasNext()) {
      Configuration authProviderConfig = (Configuration)iter.next();
      AuthenticationProvider authProvider = new AuthenticationProvider(authProviderConfig);
      if (!authProvider.isEnabled()) continue;
      authenticationProviders.put(authProvider.getName(), authProvider);
      Tracing.logInfo("Added authentication Provider: name='"
        + authProvider.getName() + "' enabled='" + (authProvider.isEnabled() ? "yes" : "no") + "'.", LoginModule.class);
    }
    Configuration defProviderConf = moduleConfig.getChild("DefaultAuthProvider");
    if (defProviderConf == null)
      throw new StartupException("No DefaultAuthProvider defined. Please fix.");
    defaultProviderName = defProviderConf.getAttribute("name");
    if (defaultProviderName == null)
      throw new StartupException("No DefaultAuthProvider defined. Please fix.");
   
    AuthenticationProvider defaultProvider = getAuthenticationProvider(defaultProviderName);
    if (defaultProvider == null || !defaultProvider.isEnabled())
      throw new StartupException("Defined DefaultAuthProvider::" + defaultProviderName + " not existent or not enabled. Please fix.");
    Tracing.logInfo("Using default authentication provider '" + defaultProviderName + "'.", LoginModule.class);
   
    // check attack prevention
    Configuration attack_conf = moduleConfig.getChild(CONF_ATTACK);
    if (attack_conf != null) {
      String attack_enabled = attack_conf.getAttribute(CONF_ATTACK_ENABLED);
      if (attack_enabled != null &&
          (attack_enabled.toLowerCase().equals("true") || attack_enabled.toLowerCase().equals("yes"))) {
        attackPreventionEnabled = true;
        String attack_maxattempts = attack_conf.getAttribute(CONF_ATTACK_MAXATTEMPTS);
        String attack_timeoutmin = attack_conf.getAttribute(CONF_ATTACK_TIMEOUTMIN);
        try {
          attackPreventionMaxAttempts = Integer.parseInt(attack_maxattempts);
          attackPreventionTimeout = Integer.parseInt(attack_timeoutmin);
        } catch (NumberFormatException nfe) {
          throw new StartupException("Attribute 'attempts' and/or 'timeoutmin' of config Parameter AttackPrevention are either missing or not a number. Please fix!");
        }
        // configure timed cache default params: refresh 1 minute, timeout according to configuration
        failedLoginCache = CoordinatorManager.getCoordinator().getCacher().getOrCreateCache(this.getClass(), "blockafterfailedattempts");
       
        Tracing.logInfo("Attack prevention enabled. Max number of attempts: " + attack_maxattempts + ", timeout: " + attack_timeoutmin + " minutes.", LoginModule.class);
      } else {
        attackPreventionEnabled = false;
        Tracing.logInfo("Attack prevention is disabled.", LoginModule.class);
      }
    }
   
    Configuration guestLinkConf = moduleConfig.getChild(CONF_GUESTLINKS);
    if (guestLinkConf != null) {
      String enabled = guestLinkConf.getAttribute(CONF_GUESTLINKS_ENABLED);
      if (enabled != null &&   (enabled.toLowerCase().equals("true") || enabled.toLowerCase().equals("yes"))) {
        guestLoginLinksEnabled = true;
        Tracing.logInfo("Guest login links on login page enabled", LoginModule.class);
      } else {
        guestLoginLinksEnabled = false;
View Full Code Here

   *      java.io.File)
   */
  public void importGroups(BGContext context, File fGroupExportXML) {
    if (!fGroupExportXML.exists()) return;

    Configuration groupConfig = null;
    try {
      groupConfig = new XMLConfiguration(fGroupExportXML);
    } catch (ConfigurationException ce) {
      throw new OLATRuntimeException("Error importing group config.", ce);
    }
    if (!groupConfig.getName().equals(EXPORT_KEY_ROOT)) throw new AssertException("Invalid group export file. Root does not match.");

    // get areas
    BGAreaManager am = BGAreaManagerImpl.getInstance();
    Configuration confAreas = groupConfig.getChild(EXPORT_KEY_AREA_COLLECTION);
    if (confAreas != null) {
      List areas = confAreas.getChildren(EXPORT_KEY_AREA);
      for (Iterator iter = areas.iterator(); iter.hasNext();) {
        Configuration area = (Configuration) iter.next();
        String areaName = area.getAttribute(EXPORT_ATTR_NAME);
        String areaDesc = area.getChildValue(EXPORT_KEY_DESCRIPTION);
        am.createAndPersistBGAreaIfNotExists(areaName, areaDesc, context);
      }
    }

    // TODO fg: import group rights

    // get groups
    Configuration confGroups = groupConfig.getChild(EXPORT_KEY_GROUP_COLLECTION);
    if (confGroups != null) {
      BusinessGroupManager gm = BusinessGroupManagerImpl.getInstance();
      List groups = confGroups.getChildren(EXPORT_KEY_GROUP);
      for (Iterator iter = groups.iterator(); iter.hasNext();) {
        // create group
        Configuration group = (Configuration) iter.next();
        String groupName = group.getAttribute(EXPORT_ATTR_NAME);
        String groupDesc = group.getChildValue(EXPORT_KEY_DESCRIPTION);

        // get min/max participants
        Integer groupMinParticipants = null;
        String sMinParticipants = group.getAttribute(EXPORT_ATTR_MIN_PARTICIPATS);
        if (sMinParticipants != null) groupMinParticipants = new Integer(sMinParticipants);
        Integer groupMaxParticipants = null;
        String sMaxParticipants = group.getAttribute(EXPORT_ATTR_MAX_PARTICIPATS);
        if (sMaxParticipants != null) groupMaxParticipants = new Integer(sMaxParticipants);

        // waiting list configuration
        String waitingListConfig = group.getAttribute(EXPORT_ATTR_WAITING_LIST);
        Boolean waitingList = null;
        if (waitingListConfig == null) {
          waitingList = Boolean.FALSE;
        } else {
          waitingList = Boolean.valueOf(waitingListConfig);
        }
        String enableAutoCloseRanksConfig = group.getAttribute(EXPORT_ATTR_AUTO_CLOSE_RANKS);
        Boolean enableAutoCloseRanks = null;
        if (enableAutoCloseRanksConfig == null) {
          enableAutoCloseRanks = Boolean.FALSE;
        } else {
          enableAutoCloseRanks = Boolean.valueOf(enableAutoCloseRanksConfig);
        }
       
        BusinessGroup newGroup = gm.createAndPersistBusinessGroup(context.getGroupType(), null, groupName, groupDesc, groupMinParticipants,
            groupMaxParticipants, waitingList, enableAutoCloseRanks, context);

        // get tools config
        Configuration toolsConfig = group.getChild(EXPORT_KEY_COLLABTOOLS);
        CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(newGroup);
        for (int i = 0; i < CollaborationTools.TOOLS.length; i++) {
          String sTool = toolsConfig.getAttribute(CollaborationTools.TOOLS[i]);
          if (sTool != null) ct.setToolEnabled(CollaborationTools.TOOLS[i], sTool.equals("true") ? true : false);
        }
        if(group.getAttribute(EXPORT_KEY_CALENDAR_ACCESS)!=null) {
          Long calendarAccess = Long.valueOf(group.getAttribute(EXPORT_KEY_CALENDAR_ACCESS));
          ct.saveCalendarAccess(calendarAccess);         
        }
        if(group.getAttribute(EXPORT_KEY_NEWS)!=null) {
          String info = group.getAttribute(EXPORT_KEY_NEWS);
          ct.saveNews(info);        
        }

        // get memberships
        List memberships = group.getChildren(EXPORT_KEY_AREA_RELATION);
        for (Iterator iterator = memberships.iterator(); iterator.hasNext();) {
          Configuration areaRelation = (Configuration) iterator.next();
          BGArea area = am.findBGArea(areaRelation.getValue(), context);
          if (area == null) throw new AssertException("Group-Area-Relationship in export, but area was not created during import.");
          am.addBGToBGArea(newGroup, area);
        }
       
        //get properties
View Full Code Here

   * @see org.olat.core.configuration.OLATModule#init(com.anthonyeden.lib.config.Configuration)
   */
  public void init(Configuration moduleConfig) {   
    // get generic configuration, put it to configuration hash map
    // for later retrieval 
    Configuration config = moduleConfig.getChild("configuration");
    List properties = config.getChildren();
    Iterator iter = properties.iterator();
    while (iter.hasNext()) {
      Configuration property = (Configuration) iter.next();
      String name = property.getAttribute("name");
      // Do not parse for correct true/false values. Assume false if anything else
      // than "true" is given.
      Boolean value = Boolean.valueOf(property.getAttribute("value"));
      configuration.put(name, value);
    }
    // initialize the secutrity manager
    Manager mgr = ManagerFactory.getManager();
    mgr.init();
View Full Code Here

TOP

Related Classes of com.anthonyeden.lib.config.Configuration

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.