/**
  * Return current user locale.
  *
  * @return user's Locale object
  */
 private Locale getCurrentUserLocale() {
   Locale loc = null;
   try {
     // check if locale is requested for specific user
     String userId = M_sm.getCurrentSessionUserId();
     if (userId != null) {
       Preferences prefs = M_ps.getPreferences(userId);
       ResourceProperties locProps = prefs.getProperties(ResourceLoader.APPLICATION_ID);
       String localeString = locProps.getProperty(ResourceLoader.LOCALE_KEY);
       // Parse user locale preference if set
       if (localeString != null) {
         String[] locValues = localeString.split("_");
         if (locValues.length > 1)
           // language, country
           loc = new Locale(locValues[0], locValues[1]);
         else if (locValues.length == 1)
           // language
           loc = new Locale(locValues[0]);
       }
       if (loc == null) loc = Locale.getDefault();
     } else {
       loc =
           (Locale)
               M_sm.getCurrentSession()
                   .getAttribute(ResourceLoader.LOCALE_KEY + M_sm.getCurrentSessionUserId());
     }
   } catch (NullPointerException e) {
     loc = Locale.getDefault();
   }
   return loc;
 }
Example #2
0
  private Map<String, String> getPermissions(ContentEntity n) throws SDataException {
    Map<String, String> map = new HashMap<String, String>();

    if (n instanceof ContentCollection) {
      map.put("read", String.valueOf(contentHostingService.allowGetCollection(n.getId())));
      map.put("remove", String.valueOf(contentHostingService.allowRemoveCollection(n.getId())));
      map.put("write", String.valueOf(contentHostingService.allowUpdateCollection(n.getId())));

      String ref = n.getReference();

      Reference reference = entityManager.newReference(n.getReference());
      if (log.isDebugEnabled()) {
        log.debug("Got Reference " + reference + " for " + n.getReference());
      }

      Collection<?> groups = reference.getAuthzGroups();
      String user = sessionManager.getCurrentSessionUserId();
      map.put(
          "admin",
          String.valueOf(
              authZGroupService.isAllowed(
                  sessionManager.getCurrentSessionUserId(),
                  AuthzGroupService.SECURE_UPDATE_AUTHZ_GROUP,
                  groups)));
    } else {
      map.put("read", String.valueOf(contentHostingService.allowGetResource(n.getId())));
      map.put("remove", String.valueOf(contentHostingService.allowRemoveResource(n.getId())));
      map.put("write", String.valueOf(contentHostingService.allowUpdateResource(n.getId())));
    }
    return map;
  }
Example #3
0
  /**
   * @throws SDataException
   * @throws RepositoryException
   */
  public CHSNodeMap(ContentEntity n, int depth, ResourceDefinition rp) throws SDataException {
    String lock = ContentHostingService.AUTH_RESOURCE_HIDDEN;
    sessionManager = Kernel.sessionManager();
    entityManager = Kernel.entityManager();
    String userId = sessionManager.getCurrentSessionUserId();
    String reference = n.getReference();
    Reference referenceObj = entityManager.newReference(reference);
    Collection<?> groups = referenceObj.getAuthzGroups();

    boolean canSeeHidden = Kernel.securityService().unlock(userId, lock, reference, groups);

    if (!canSeeHidden && !n.isAvailable()) {
      throw new SDataAccessException(403, "Permission denied on item");
    }
    contentHostingService = Kernel.contentHostingService();
    authZGroupService = Kernel.authzGroupService();
    depth--;
    put("mixinNodeType", getMixinTypes(n));
    put("properties", getProperties(n));
    put("name", getName(n));
    if (rp != null) {
      put("path", rp.getExternalPath(n.getId()));
    }
    put("permissions", getPermissions(n));

    if (n instanceof ContentResource) {
      put("primaryNodeType", "nt:file");
      addFile((ContentResource) n);
    } else {
      put("primaryNodeType", "nt:folder");
      addFolder((ContentCollection) n, rp, depth);
    }
  }
 public TaggableItem getItem(
     String itemRef, TaggingProvider provider, boolean getMyItemOnly, String taggedItem) {
   TaggableItem item = null;
   if (checkReference(itemRef)) {
     // Only return item to a specified rating (evalutation) provider
     if (ratingProviderIds.contains(provider.getId())) {
       WizardReference reference = WizardReference.getReference(itemRef);
       if (reference != null) {
         WizardPage page = matrixManager.getWizardPage(idManager.getId(reference.getId()));
         if (page != null
             && (page.getStatus().equals(MatrixFunctionConstants.PENDING_STATUS)
                 || page.getStatus().equals(MatrixFunctionConstants.COMPLETE_STATUS))
             && (page.getOwner()
                     .getId()
                     .getValue()
                     .equals(sessionManager.getCurrentSessionUserId())
                 || (!getMyItemOnly && canEvaluate(page)))) {
           item = getItem(page);
         }
       }
     } else {
       // Notify other tagging providers that they aren't accepted here
       // yet
       logger.warn(this + ".getItem(): Provider with id " + provider.getId() + " not allowed!");
     }
   }
   return item;
 }
Example #5
0
  private static void setPreferenceList(String name, Collection values) throws Exception {
    PreferencesEdit prefsEdit = null;
    String userId = M_sm.getCurrentSessionUserId();
    try {
      prefsEdit = M_ps.edit(userId);
    } catch (IdUnusedException e) {
      prefsEdit = M_ps.add(userId);
    }
    try {
      ResourcePropertiesEdit props = prefsEdit.getPropertiesEdit(PREFS_KEY);

      if (values == null) {
        props.removeProperty(name);
      } else {
        List existing = props.getPropertyList(name);
        Iterator it = values.iterator();
        while (it.hasNext()) {
          String value = (String) it.next();
          if (existing == null || !existing.contains(value))
            props.addPropertyToList(name, value.toString());
        }
      }
    } catch (Exception e) {
      if (prefsEdit != null) M_ps.cancel(prefsEdit);
      M_ps.cancel(prefsEdit);
      throw e;
    }
    M_ps.commit(prefsEdit);
  }
Example #6
0
  private static void clearPreferenceList(String name) throws Exception {
    PreferencesEdit prefsEdit = null;
    try {
      prefsEdit = M_ps.edit(M_sm.getCurrentSessionUserId());
      ResourcePropertiesEdit props = prefsEdit.getPropertiesEdit(PREFS_KEY);

      props.removeProperty(name);
    } catch (Exception e) {
      M_ps.cancel(prefsEdit);
      throw e;
    }
    M_ps.commit(prefsEdit);
  }
Example #7
0
  private static void setPreferenceString(String name, String value) throws Exception {
    PreferencesEdit prefsEdit = null;
    String userId = M_sm.getCurrentSessionUserId();
    try {
      prefsEdit = M_ps.edit(userId);
    } catch (IdUnusedException e) {
      prefsEdit = M_ps.add(userId);
    }
    try {
      ResourcePropertiesEdit props = prefsEdit.getPropertiesEdit(PREFS_KEY);

      if (value == null) {
        props.removeProperty(name);
      } else {
        props.addProperty(name, value.toString());
      }
    } catch (Exception e) {
      if (prefsEdit != null) M_ps.cancel(prefsEdit);
      throw e;
    }
    M_ps.commit(prefsEdit);
  }
 public boolean allowRemoveTags(TaggableActivity activity) {
   WizardPageDefinition pageDef = (WizardPageDefinition) activity.getObject();
   // Try to get a wizard page sequence
   WizardPageSequence ps = wizardManager.getWizardPageSeqByDef(pageDef.getId());
   boolean authorized = false;
   if (ps != null) {
     Wizard wizard = ps.getCategory().getWizard();
     /*
      * If you own the wizard, or if you can delete wizards, or if you
      * can revise wizards, then you are able to delete page definitions
      * and can, therefore, remove tags.
      */
     authorized =
         sessionManager
                 .getCurrentSessionUserId()
                 .equalsIgnoreCase(wizard.getOwner().getId().getValue())
             || authzManager.isAuthorized(WizardFunctionConstants.EDIT_WIZARD, wizard.getId())
             || authzManager.isAuthorized(WizardFunctionConstants.DELETE_WIZARD, wizard.getId());
   } else {
     ScaffoldingCell cell = matrixManager.getScaffoldingCellByWizardPageDef(pageDef.getId());
     /*
      * If you can create or delete scaffolding, then you are able to
      * delete scaffolding cells and can, therefore, remove tags.
      */
     authorized =
         authzManager.isAuthorized(
                 MatrixFunctionConstants.CREATE_SCAFFOLDING, cell.getScaffolding().getId())
             || authzManager.isAuthorized(
                 MatrixFunctionConstants.DELETE_SCAFFOLDING_ANY, cell.getScaffolding().getId())
             || (authzManager.isAuthorized(
                     MatrixFunctionConstants.DELETE_SCAFFOLDING_OWN, cell.getScaffolding().getId())
                 && cell.getScaffolding()
                     .getOwner()
                     .getId()
                     .equals(getAuthnManager().getAgent().getId()));
   }
   return authorized;
 }
  /** {@inheritDoc} */
  public String getUserHomeUrl() {
    // get the configured URL (the text "#UID#" will be repalced with the current logged in user id
    // NOTE: this is relative to the server root
    String rv = (String) properties.get("userHomeUrl");

    // form a site based portal id if not configured
    if (rv == null) {
      rv = (String) properties.get("portalPath") + "/site/~#UID#";
    }

    // check for a logged in user
    String user = sessionManager.getCurrentSessionUserId();
    boolean loggedIn = (user != null);

    // if logged in, replace the UID in the pattern
    if (loggedIn) {
      rv = rv.replaceAll("#UID#", user);
    }

    // make it full, adding the server root
    rv = getServerUrl() + rv;

    return rv;
  }
 private String getCurrentUser() {
   if (TestUtil.isRunningTests()) {
     return "test-user";
   }
   return sessionManager.getCurrentSessionUserId();
 }
Example #11
0
 /**
  * Get the current user preference list value. First attempt Preferences, then defaults from
  * sakai.properties.
  *
  * @param name The property name.
  * @return The preference list value or null if not set.
  */
 private static List getPreferenceList(String name) {
   Preferences prefs = M_ps.getPreferences(M_sm.getCurrentSessionUserId());
   ResourceProperties rp = prefs.getProperties(PREFS_KEY);
   List l = rp.getPropertyList(name);
   return l;
 }
Example #12
0
 /**
  * Get the current user preference value. First attempt Preferences, then defaults from
  * sakai.properties.
  *
  * @param name The property name.
  * @return The preference value or null if not set.
  */
 private static String getPreferenceString(String name) {
   Preferences prefs = M_ps.getPreferences(M_sm.getCurrentSessionUserId());
   ResourceProperties rp = prefs.getProperties(PREFS_KEY);
   String value = rp.getProperty(name);
   return value;
 }