示例#1
0
 /** {@inheritDoc} */
 @Override
 protected void formOK(UserRequest ureq) {
   // read data from form elements
   for (int i = 0; i < lTargetInputList.size(); i++) {
     LLModel link = (LLModel) lTargetInputList.get(i).getUserObject();
     String linkValue = lTargetInputList.get(i).getValue();
     if (link.isIntern()) {
       if (!linkValue.contains("://") && !linkValue.startsWith("/")) {
         linkValue = "/".concat(linkValue.trim());
         lTargetInputList.get(i).setValue(linkValue);
       }
     } else if (!linkValue.contains("://")) {
       linkValue = "http://".concat(linkValue.trim());
       lTargetInputList.get(i).setValue(linkValue);
     }
     link.setTarget(linkValue);
     boolean blank = lHtmlTargetInputList.get(i).isSelected(0);
     if (linkValue.startsWith(Settings.getServerContextPathURI())) {
       // links to OO pages open in same window
       blank = false;
       lHtmlTargetInputList.get(i).select(SELF_KEY, true);
     }
     link.setHtmlTarget(blank ? BLANK_KEY : SELF_KEY);
     link.setDescription(lDescriptionInputList.get(i).getValue());
     link.setComment(lCommentInputList.get(i).getValue());
   }
   moduleConfig.set(LLCourseNode.CONF_LINKLIST, linkList);
   // Inform all listeners about the changes
   fireEvent(ureq, NodeEditController.NODECONFIG_CHANGED_EVENT);
 }
示例#2
0
 /**
  * Return a lock info base on the VFS lock
  *
  * @param resource
  * @return
  */
 public LockInfo getVFSLock(WebResource resource) {
   VFSItem item = extractItem(resource);
   MetaInfoFileImpl info = getMetaInfo(item);
   if (info != null && info.isLocked()) {
     File file = extractFile(item);
     LockInfo lock = null;
     if (fileLocks.containsKey(file)) {
       lock = fileLocks.get(file);
       if (lock != null) {
         lock.setVfsLock(true);
       }
     }
     if (lock == null) {
       lock = new LockInfo(info.getLockedBy(), false, true);
       lock.setWebResource(resource);
       lock.setCreationDate(info.getLockedDate());
       lock.setOwner(Settings.getServerContextPathURI() + "/Identity/" + info.getLockedBy());
       lock.setDepth(1);
       lock.addToken(generateLockToken(lock, info.getLockedBy()));
       fileLocks.put(file, lock);
     }
     return lock;
   }
   return null;
 }
示例#3
0
  /** {@inheritDoc} */
  @Override
  protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source instanceof TextElement) {
      int i = lTargetInputList.indexOf(source);
      if (i >= 0) {
        String linkValue = ((TextElement) source).getValue();
        if (!linkValue.contains("://")) {
          linkValue = "http://".concat(linkValue.trim());
        }
        boolean selected = lHtmlTargetInputList.get(i).isSelected(0);
        if (selected && linkValue.startsWith(Settings.getServerContextPathURI())) {
          lHtmlTargetInputList.get(i).select(BLANK_KEY, false);
        }
      }
    } else if (source.getComponent() instanceof Link) {
      if (lAddButtonList.contains(source)) {
        // add a new form link
        final LLModel link = (LLModel) ((FormLink) source).getUserObject();
        final LLModel newLink = new LLModel();
        linkList.add(linkList.indexOf(link) + 1, newLink);
        addNewFormLink(linkList.indexOf(link) + 1, newLink);
      } else if (lDelButtonList.contains(source)) {
        // special case: only one line existent
        if (linkList.size() == 1) {
          // clear this line
          lTargetInputList.get(0).setValue("");
          lTargetInputList.get(0).setEnabled(true);
          lDescriptionInputList.get(0).setValue("");
          lCommentInputList.get(0).setValue("");
        } else {
          final LLModel link = (LLModel) ((FormLink) source).getUserObject();
          removeFormLink(link);
        }
      } else if (lCustomMediaButtonList.contains(source)) {
        currentLink = (LLModel) ((FormLink) source).getUserObject();

        removeAsListenerAndDispose(mediaDialogBox);
        removeAsListenerAndDispose(mediaChooserController);

        VFSContainer courseContainer = courseEnv.getCourseFolderContainer();
        mediaChooserController =
            new MediaChooserController(
                ureq, getWindowControl(), courseContainer, null, null, "", null);
        listenTo(mediaChooserController);

        mediaDialogBox =
            new CloseableModalController(
                getWindowControl(),
                translate("choose"),
                mediaChooserController.getInitialComponent());
        mediaDialogBox.activate();
        listenTo(mediaDialogBox);
      }
    }
    super.formInnerEvent(ureq, source, event);
    fireEvent(ureq, NodeEditController.NODECONFIG_CHANGED_EVENT);
  }
示例#4
0
  @Override
  protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == mediaDialogBox) {
      removeAsListenerAndDispose(mediaDialogBox);
      removeAsListenerAndDispose(mediaChooserController);
      mediaDialogBox = null;
      mediaChooserController = null;
    } else if (source == mediaChooserController) {
      if (event instanceof URLChoosenEvent) {
        URLChoosenEvent choosenEvent = (URLChoosenEvent) event;
        String url = choosenEvent.getURL();
        if (url.startsWith(Settings.getServerContextPathURI())) {
          // doesn't allow absolute path -> the mapper check if the link is in the list!
          url = url.substring(Settings.getServerContextPathURI().length());
        }
        currentLink.setTarget(url);
        currentLink.setIntern(true);
        currentLink.setHtmlTarget(SELF_KEY);
        if (StringHelper.containsNonWhitespace(choosenEvent.getDisplayName())) {
          currentLink.setDescription(choosenEvent.getDisplayName());
        }

        int index = 0;
        for (TextElement targetEl : lTargetInputList) {
          if (currentLink.equals(targetEl.getUserObject())) {
            targetEl.setValue(url);
            targetEl.setEnabled(false);
            lDescriptionInputList.get(index).setValue(currentLink.getDescription());
            lHtmlTargetInputList.get(index).select(SELF_KEY, true);
            break;
          }
          index++;
        }
      }
      mediaDialogBox.deactivate();
      removeAsListenerAndDispose(mediaDialogBox);
      removeAsListenerAndDispose(mediaChooserController);
      mediaDialogBox = null;
      mediaChooserController = null;
    }

    super.event(ureq, source, event);
  }
  @Override
  protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("rest.title");
    setFormContextHelp("REST API");

    if (formLayout instanceof FormLayoutContainer) {
      FormLayoutContainer layoutContainer = (FormLayoutContainer) formLayout;

      boolean restEnabled = restModule.isEnabled();
      docLinkFlc =
          FormLayoutContainer.createCustomFormLayout(
              "doc_link", getTranslator(), velocity_root + "/docLink.html");
      layoutContainer.add(docLinkFlc);
      docLinkFlc.setVisible(restEnabled);

      String link =
          Settings.getServerContextPathURI() + RestSecurityHelper.SUB_CONTEXT + "/api/doc";
      docLinkFlc.contextPut("docLink", link);

      FormLayoutContainer accessDataFlc =
          FormLayoutContainer.createDefaultFormLayout("flc_access_data", getTranslator());
      layoutContainer.add(accessDataFlc);

      String[] values = new String[] {getTranslator().translate("rest.on")};
      enabled = uifactory.addCheckboxesHorizontal("rest.enabled", accessDataFlc, keys, values);
      enabled.select(keys[0], restEnabled);
      enabled.addActionListener(FormEvent.ONCHANGE);

      accessDataFlc.setVisible(true);
      formLayout.add(accessDataFlc);

      FormLayoutContainer managedFlc =
          FormLayoutContainer.createDefaultFormLayout("flc_managed", getTranslator());
      layoutContainer.add(managedFlc);

      String[] valueGrps = new String[] {getTranslator().translate("rest.on")};
      managedGroupsEl =
          uifactory.addCheckboxesHorizontal("managed.group", managedFlc, keys, valueGrps);
      managedGroupsEl.addActionListener(FormEvent.ONCHANGE);
      managedGroupsEl.select(keys[0], groupModule.isManagedBusinessGroups());

      String[] valueRes = new String[] {getTranslator().translate("rest.on")};
      managedRepoEl = uifactory.addCheckboxesHorizontal("managed.repo", managedFlc, keys, valueRes);
      managedRepoEl.addActionListener(FormEvent.ONCHANGE);
      managedRepoEl.select(keys[0], repositoryModule.isManagedRepositoryEntries());

      String[] valueCal = new String[] {getTranslator().translate("rest.on")};
      managedCalendarEl =
          uifactory.addCheckboxesHorizontal("managed.cal", managedFlc, keys, valueCal);
      managedCalendarEl.addActionListener(FormEvent.ONCHANGE);
      managedCalendarEl.select(keys[0], calendarModule.isManagedCalendars());
    }
  }
示例#6
0
  private UserSession doAuthentication(HttpServletRequest request, HttpServletResponse response) {
    // Get the Authorization header, if one was supplied
    String authHeader = request.getHeader("Authorization");
    if (authHeader != null) {
      // fetch user session from a previous authentication

      UserSession usess = null;

      StringTokenizer st = new StringTokenizer(authHeader);
      if (st.hasMoreTokens()) {
        String basic = st.nextToken();

        // We only handle HTTP Basic authentication
        if (basic.equalsIgnoreCase("Basic")) {
          String credentials = st.nextToken();
          usess = handleBasicAuthentication(credentials, request);
        } else if (basic.equalsIgnoreCase("Digest")) {
          DigestAuthentication digestAuth = DigestAuthentication.parse(authHeader);
          usess = handleDigestAuthentication(digestAuth, request);
        }
      }

      if (usess != null) {
        return usess;
      }
    }

    // If the user was not validated or the browser does not know about the realm yet, fail with a
    // 401 status code (UNAUTHORIZED) and
    // pass back a WWW-Authenticate header for
    // this servlet.
    //
    // Note that this is the normal situation the
    // first time you access the page. The client
    // web browser will prompt for userID and password
    // and cache them so that it doesn't have to
    // prompt you again.

    if (request.isSecure() || Settings.isJUnitTest()) {
      response.addHeader("WWW-Authenticate", "Basic realm=\"" + BASIC_AUTH_REALM + "\"");
    }
    if (webdavModule.isDigestAuthenticationEnabled()) {
      String nonce = UUID.randomUUID().toString().replace("-", "");
      response.addHeader(
          "WWW-Authenticate",
          "Digest realm=\"" + BASIC_AUTH_REALM + "\", qop=\"auth\", nonce=\"" + nonce + "\"");
    }
    response.setStatus(401);
    return null;
  }
  public JSRedirectWindowController(UserRequest ureq) {
    Translator trans =
        Util.createPackageTranslator(JSRedirectWindowController.class, ureq.getLocale());
    VelocityContainer msg =
        new VelocityContainer("jsredirect", VELOCITY_ROOT + "/js_redirect.html", trans, this);

    String callbackUrl = Settings.getServerContextPathURI() + OAuthConstants.CALLBACK_PATH;
    msg.contextPut("callbackUrl", callbackUrl);

    Windows ws = Windows.getWindows(ureq);
    WindowBackOffice wbo =
        ws.getWindowManager()
            .createWindowBackOffice("jsredirectwindow", this, new WindowSettings());
    Window w = wbo.getWindow();
    msg.contextPut("theme", w.getGuiTheme());
    w.setContentPane(msg);
    setWindow(w);
  }
示例#8
0
  @Override
  public LockInfo getLock(VFSItem item) {
    File file = extractFile(item);
    if (file != null && fileLocks.containsKey(file)) {
      LockInfo lock = fileLocks.get(file);
      if (lock != null) {
        return lock;
      }
    }

    MetaInfoFileImpl info = getMetaInfo(item);
    if (info != null && info.isLocked()) {
      LockInfo lock = new LockInfo(info.getLockedBy(), false, true);
      lock.setCreationDate(info.getLockedDate());
      lock.setOwner(Settings.getServerContextPathURI() + "/Identity/" + info.getLockedBy());
      lock.setDepth(1);
      lock.addToken(generateLockToken(lock, info.getLockedBy()));
      fileLocks.put(file, lock);
      return lock;
    }
    return null;
  }
示例#9
0
 /** @see junit.framework.TestCase#setUp() */
 @Before
 public void setup() throws Exception {
   // see prepareDevToolTests() !
   Settings.setJUnitTest(true);
 }
 public String getVersion() {
   return Settings.getVersion();
 }
 /**
  * Returns true when debug mode is configured, false otherwhise
  *
  * @return
  */
 public boolean isDebuging() {
   return Settings.isDebuging();
 }
示例#12
0
public class GUIInterna {

  private static Boolean allowed = Settings.isAllowLoadtestMode();
  private static ThreadLocalData tld = new ThreadLocalData();

  private static Map<String, Map<Object, Object>> loadtestClients =
      new HashMap<String, Map<Object, Object>>();

  public static void begin(HttpServletRequest req) {

    if (!allowed) return;
    if (req == null) return;
    String key = getCookie(req);
    if (key == null) return;

    String q = req.getQueryString();

    synchronized (loadtestClients) {
      if (q != null) {
        if (q.endsWith("noloadtest")) {
          if (loadtestClients.containsKey(key)) {
            loadtestClients.remove(key);
          }
        } else if (q.endsWith("loadtest")) {
          if (loadtestClients.containsKey(key)) {
            loadtestClients.remove(key);
          }
          loadtestClients.put(key, new HashMap<Object, Object>());
        } else if (q.equals("clearloadtests")) {
          loadtestClients.clear();
        }
      }

      if (loadtestClients.containsKey(key)) {
        tld.setBoolean(Boolean.TRUE);
        tld.setMap(loadtestClients.get(key));
      } else {
        tld.setBoolean(Boolean.FALSE);
      }
    }
  }

  public static boolean isLoadPerformanceMode() {
    return allowed && tld.getBoolean();
  }

  public static void end(HttpServletRequest req) {
    if (!allowed) return;
    if (req == null) return;

    if (tld.getBoolean()) {
      String c = getCookie(req);

      if (c != null) {
        synchronized (loadtestClients) {
          loadtestClients.put(c, tld.getMap());
        }
      }
    }

    tld.remove();
  }

  private static String getCookie(HttpServletRequest req) {
    Cookie c[] = req.getCookies();
    for (int i = 0; c != null && i < c.length; i++) {
      if (c[i].getName().equals("JSESSIONID")) {
        return c[i].getValue();
      }
    }
    return null;
  }

  public static Map<Object, Object> getReplayModeData() {
    return tld.getMap();
  }

  private static class ValueContainer {

    Boolean b = null;
    Map<Object, Object> m = null;

    ValueContainer() {
      // nothing to be done here
    }
  }

  private static class ThreadLocalData extends ThreadLocal<ValueContainer> {

    Boolean getBoolean() {
      ValueContainer vc = get();
      if (vc != null && vc.b != null) {
        return vc.b;
      }
      return Boolean.FALSE;
    }

    Map<Object, Object> getMap() {
      ValueContainer vc = get();
      if (vc != null && vc.m != null) {
        return vc.m;
      }
      return null;
    }

    void setBoolean(Boolean b) {
      ValueContainer vc = get();
      if (vc == null) {
        vc = new ValueContainer();
        set(vc);
      }
      vc.b = b;
    }

    void setMap(Map<Object, Object> m) {
      ValueContainer vc = get();
      if (vc == null) {
        vc = new ValueContainer();
        set(vc);
      }
      vc.m = m;
    }
  }
}