Exemplo n.º 1
0
  public static Document createDocument(
      final SearchResourceContext searchResourceContext, final WikiPage wikiPage) {
    final WikiPageDocument wikiPageDocument = new WikiPageDocument();

    final long userId = wikiPage.getInitalAuthor();
    if (userId != 0) {
      final Identity identity = identityManager.loadIdentityByKey(Long.valueOf(userId));
      wikiPageDocument.setAuthor(identity.getName());
    }
    wikiPageDocument.setTitle(wikiPage.getPageName());
    wikiPageDocument.setContent(getContent(wikiPage));
    wikiPageDocument.setCreatedDate(new Date(wikiPage.getCreationTime()));
    wikiPageDocument.setLastChange(new Date(wikiPage.getModificationTime()));
    wikiPageDocument.setResourceUrl(searchResourceContext.getResourceUrl());
    wikiPageDocument.setDocumentType(searchResourceContext.getDocumentType());
    wikiPageDocument.setCssIcon("o_wiki_icon");
    wikiPageDocument.setParentContextType(searchResourceContext.getParentContextType());
    wikiPageDocument.setParentContextName(searchResourceContext.getParentContextName());

    if (log.isDebugEnabled()) {
      log.debug(wikiPageDocument.toString());
    }
    return wikiPageDocument.getLuceneDocument();
  }
Exemplo n.º 2
0
  @Override
  public void init() {
    // Check if LDAP is enabled
    if (!isLDAPEnabled()) {
      log.info("LDAP login is disabled");
      return;
    }
    // Create LDAP Security Group if not existing. Used to identify users that
    // have to be synced with LDAP
    SecurityGroup ldapGroup =
        securityManager.findSecurityGroupByName(LDAPConstants.SECURITY_GROUP_LDAP);
    if (ldapGroup == null) {
      ldapGroup =
          securityManager.createAndPersistNamedSecurityGroup(LDAPConstants.SECURITY_GROUP_LDAP);
    }
    // check for valid configuration
    if (!checkConfigParameterIsNotEmpty(ldapUrl)) {
      return;
    }
    if (!checkConfigParameterIsNotEmpty(systemDN)) {
      return;
    }
    if (!checkConfigParameterIsNotEmpty(systemPW)) {
      return;
    }
    if (ldapBases == null || ldapBases.size() == 0) {
      log.error(
          "Missing configuration 'ldapBases'. Add at least one LDAP Base to the this configuration in olatextconfig.xml first. Disabling LDAP");
      setEnableLDAPLogins(false);
      return;
    }
    if (!checkConfigParameterIsNotEmpty(ldapUserObjectClass)) {
      return;
    }
    if (!checkConfigParameterIsNotEmpty(ldapUserCreatedTimestampAttribute)) {
      return;
    }
    if (!checkConfigParameterIsNotEmpty(ldapUserLastModifiedTimestampAttribute)) {
      return;
    }
    if (userAttrMap == null || userAttrMap.size() == 0) {
      log.error(
          "Missing configuration 'userAttrMap'. Add at least the email propery to the this configuration in olatextconfig.xml first. Disabling LDAP");
      setEnableLDAPLogins(false);
      return;
    }
    if (reqAttr == null || reqAttr.size() == 0) {
      log.error(
          "Missing configuration 'reqAttr'. Add at least the email propery to the this configuration in olatextconfig.xml first. Disabling LDAP");
      setEnableLDAPLogins(false);
      return;
    }
    // check if OLAT user properties is defined in olat_userconfig.xml, if not disable the LDAP
    // module
    if (!checkIfOlatPropertiesExists(userAttrMap)) {
      log.error("Invalid LDAP OLAT properties mapping configuration (userAttrMap). Disabling LDAP");
      setEnableLDAPLogins(false);
      return;
    }
    if (!checkIfOlatPropertiesExists(reqAttr)) {
      log.error("Invalid LDAP OLAT properties mapping configuration (reqAttr). Disabling LDAP");
      setEnableLDAPLogins(false);
      return;
    }
    if (syncOnlyOnCreateProperties != null
        && !checkIfStaticOlatPropertiesExists(syncOnlyOnCreateProperties)) {
      log.error("Invalid LDAP OLAT syncOnlyOnCreateProperties configuration. Disabling LDAP");
      setEnableLDAPLogins(false);
      return;
    }
    if (staticUserProperties != null
        && !checkIfStaticOlatPropertiesExists(staticUserProperties.keySet())) {
      log.error(
          "Invalid static OLAT properties configuration (staticUserProperties). Disabling LDAP");
      setEnableLDAPLogins(false);
      return;
    }

    // check SSL certifications, throws Startup Exception if certificate is not found
    if (isSslEnabled()) {
      if (!checkServerCertValidity(0)) {
        throw new StartupException(
            "LDAP enabled but no valid server certificate found. Please fix!");
      }
      if (!checkServerCertValidity(30)) {
        log.warn("Server Certificate will expire in less than 30 days.");
      }
    }

    // Check ldap connection
    if (ldapManager.bindSystem() == null) {
      // don't disable ldap, maybe just a temporary problem, but still report
      // problem in logfile
      log.warn(
          "LDAP connection test failed during module initialization, edit config or contact network administrator");
    }
    // OK, everything finished checkes passed
    log.info("LDAP login is enabled");

    /*
     *
     */

    // Sync LDAP Users on Startup
    if (isLdapSyncOnStartup()) {
      initStartSyncJob();
    } else {
      log.info("LDAP start sync is disabled");
    }

    // Start LDAP cron sync job
    if (isLdapSyncCronSync()) {
      initCronSyncJob();
    } else {
      log.info("LDAP cron sync is disabled");
    }

    // OK, everything finished checkes passed
    log.info("LDAP login is enabled");
  }
  @Override
  protected void event(final UserRequest ureq, final Controller source, final Event event) {
    if (source == usersForm) {
      if (event == Event.DONE_EVENT) {
        // calc stuff, preview

        final List existIdents = securityManager.getIdentitiesOfSecurityGroup(securityGroup);
        oks = new ArrayList<Identity>();
        final List<String> anonymous = new ArrayList<String>();
        final List<String> notFounds = new ArrayList<String>();
        final List<String> alreadyIn = new ArrayList<String>();

        // get the logins
        final String inp = usersForm.getLoginsString();
        final String[] lines = inp.split("\r?\n");
        for (int i = 0; i < lines.length; i++) {
          final String username = lines[i].trim();
          if (!username.equals("")) { // skip empty lines
            final Identity ident = securityManager.findIdentityByName(username);
            if (ident == null) { // not found, add to not-found-list
              notFounds.add(username);
            } else if (getBaseSecurityEBL().isAnonymous(ident)) {
              anonymous.add(username);
            } else {
              // check if already in group
              final boolean inGroup = containsIdentity(existIdents, ident);
              if (inGroup) {
                // added to warning: already in group
                alreadyIn.add(ident.getName());
              } else {
                // ok to add -> preview (but filter duplicate entries)
                if (!containsIdentity(oks, ident)) {
                  oks.add(ident);
                }
              }
            }
          }
        }
        // push table and other infos to velocity
        removeAsListenerAndDispose(newTableC);
        newTableC =
            UserControllerFactory.createTableControllerFor(
                null, oks, ureq, getWindowControl(), null);
        listenTo(newTableC);

        mainVc.put("table", newTableC.getInitialComponent());
        mainVc.contextPut("isanonymous", listNames(anonymous));
        mainVc.contextPut("notfound", listNames(notFounds));
        mainVc.contextPut("alreadyin", listNames(alreadyIn));
        mainVc.contextPut("usercount", new Integer(oks.size()));
        // set table page as next wizard step
        setNextWizardStep(translate("import.title.finish"), mainVc);
      }

    } else if (source == mailCtr) {
      if (event == Event.DONE_EVENT) {
        final MultiIdentityChosenEvent multiEvent = new MultiIdentityChosenEvent(this.oks);
        multiEvent.setMailTemplate(mailCtr.getMailTemplate());
        fireEvent(ureq, multiEvent);
      }
    }
  }