Remove deprecated APIs
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 1 Oct 2016 17:07:19 +0000 (17:07 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 1 Oct 2016 17:07:19 +0000 (17:07 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@9234 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

34 files changed:
org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/NodeContentProvider.java
org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/NodeLabelProvider.java
org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/jcr/commands/AddRemoteRepository.java
org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/useradmin/parts/DefaultUserMainPage.java [deleted file]
org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/useradmin/parts/UserBatchUpdateWizard.java
org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/jcr/JcrPreferenceStore.java [deleted file]
org.argeo.cms.ui/src/org/argeo/cms/maintenance/DataDeploymentUi.java
org.argeo.cms.ui/src/org/argeo/cms/util/CmsUtils.java
org.argeo.cms/src/org/argeo/cms/internal/kernel/CmsDeployment.java
org.argeo.cms/src/org/argeo/cms/internal/kernel/CmsInstance.java
org.argeo.cms/src/org/argeo/cms/internal/kernel/DataHttp.java
org.argeo.cms/src/org/argeo/cms/internal/kernel/DeployConfig.java
org.argeo.cms/src/org/argeo/cms/internal/kernel/FirstInitProperties.java
org.argeo.cms/src/org/argeo/cms/internal/kernel/HomeRepository.java
org.argeo.cms/src/org/argeo/cms/internal/kernel/KernelUtils.java
org.argeo.cms/src/org/argeo/cms/internal/kernel/LocalRepository.java
org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeHttp.java
org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeRepositoryFactory.java
org.argeo.cms/src/org/argeo/cms/internal/kernel/RepositoryServiceFactory.java
org.argeo.enterprise/src/org/argeo/osgi/metatype/EnumAD.java
org.argeo.enterprise/src/org/argeo/osgi/useradmin/AbstractUserDirectory.java
org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdapUserAdmin.java
org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdifAuthorization.java
org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdifName.java
org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdifUser.java
org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdifUserAdmin.java
org.argeo.jcr/src/org/argeo/jcr/JcrRepositoryWrapper.java
org.argeo.node.api/src/org/argeo/node/ArgeoNames.java
org.argeo.node.api/src/org/argeo/node/ArgeoTypes.java
org.argeo.node.api/src/org/argeo/node/NodeConstants.java
org.argeo.node.api/src/org/argeo/node/NodeNames.java [new file with mode: 0644]
org.argeo.node.api/src/org/argeo/node/NodeTypes.java [new file with mode: 0644]
org.argeo.node.api/src/org/argeo/node/NodeUtils.java
org.argeo.node.api/src/org/argeo/node/node.cnd

index 6b2bbfd28ae48dff750227a88c65a5e0fbac464d..77ef938819ebcc5aab21e7e7ad2b2692c084d7ce 100644 (file)
@@ -78,7 +78,7 @@ public class NodeContentProvider implements ITreeContentProvider {
                                if (homeNode != null)
                                        homeNode.dispose();
                                homeNode = new SingleJcrNodeElem(null, userHome,
-                                               userSession.getUserID(), NodeConstants.ALIAS_NODE);
+                                               userSession.getUserID(), NodeConstants.NODE);
                        }
                }
                if (repositoryRegister != null) {
index be4f5a0d76c4e23c4eeb957a72036d88a5eaf878..77ca798fe98a9b6f006ec8ec040b176c1643c084 100644 (file)
@@ -28,7 +28,7 @@ import org.argeo.cms.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
 import org.argeo.cms.ui.workbench.internal.jcr.model.WorkspaceElem;
 import org.argeo.cms.ui.workbench.jcr.JcrImages;
 import org.argeo.eclipse.ui.EclipseUiException;
-import org.argeo.node.ArgeoTypes;
+import org.argeo.node.NodeTypes;
 import org.eclipse.jface.viewers.ColumnLabelProvider;
 import org.eclipse.swt.graphics.Image;
 
@@ -110,7 +110,7 @@ public class NodeLabelProvider extends ColumnLabelProvider {
                                return JcrImages.FOLDER;
                        else if (node.getPrimaryNodeType().isNodeType(NodeType.NT_RESOURCE))
                                return JcrImages.BINARY;
-                       else if (node.isNodeType(ArgeoTypes.ARGEO_USER_HOME))
+                       else if (node.isNodeType(NodeTypes.NODE_USER_HOME))
                                return JcrImages.HOME;
                        else
                                return JcrImages.NODE;
index c8a8738a25ade5dd6678e562de5a25728698f6aa..1f572b304d1b9fe8e69a0c15f1e93fa98acbcbf8 100644 (file)
@@ -143,7 +143,7 @@ public class AddRemoteRepository extends AbstractHandler implements
                                String checkedUriStr = checkedUri.toString();
 
                                Hashtable<String, String> params = new Hashtable<String, String>();
-                               params.put(NodeConstants.JCR_REPOSITORY_URI, checkedUriStr);
+                               params.put(NodeConstants.LABELED_URI, checkedUriStr);
                                Repository repository = repositoryFactory.getRepository(params);
                                if (username.getText().trim().equals("")) {// anonymous
                                        session = repository.login();
diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/useradmin/parts/DefaultUserMainPage.java b/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/internal/useradmin/parts/DefaultUserMainPage.java
deleted file mode 100644 (file)
index 6d7f2bf..0000000
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.cms.ui.workbench.internal.useradmin.parts;
-
-import java.util.Arrays;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.RepositoryException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.cms.CmsException;
-import org.argeo.node.ArgeoNames;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.forms.AbstractFormPart;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.SectionPart;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-import org.eclipse.ui.forms.widgets.Section;
-
-/** Display/edit the properties common to all Argeo users */
-public class DefaultUserMainPage extends FormPage implements ArgeoNames {
-       final static String ID = "argeoUserEditor.mainPage";
-
-       private final static Log log = LogFactory.getLog(DefaultUserMainPage.class);
-       private Node userProfile;
-
-       private char[] newPassword;
-
-       public DefaultUserMainPage(FormEditor editor, Node userProfile) {
-               super(editor, ID, "Main");
-               this.userProfile = userProfile;
-       }
-
-       protected void createFormContent(final IManagedForm mf) {
-               try {
-                       ScrolledForm form = mf.getForm();
-                       refreshFormTitle(form);
-                       GridLayout mainLayout = new GridLayout(1, true);
-                       form.getBody().setLayout(mainLayout);
-
-                       createGeneralPart(form.getBody());
-                       createPassworPart(form.getBody());
-               } catch (RepositoryException e) {
-                       throw new CmsException("Cannot create form content", e);
-               }
-       }
-
-       /** Creates the general section */
-       protected void createGeneralPart(Composite parent)
-                       throws RepositoryException {
-               FormToolkit tk = getManagedForm().getToolkit();
-               Section section = tk.createSection(parent, Section.TITLE_BAR);
-               section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-               section.setText("General");
-               Composite body = tk.createComposite(section, SWT.WRAP);
-               section.setClient(body);
-               GridLayout layout = new GridLayout(2, false);
-               body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-               body.setLayout(layout);
-
-               final Text commonName = createLT(body, "Displayed Name",
-                               getProperty(Property.JCR_TITLE));
-               final Text firstName = createLT(body, "First name",
-                               getProperty(ARGEO_FIRST_NAME));
-               final Text lastName = createLT(body, "Last name",
-                               getProperty(ARGEO_LAST_NAME));
-               final Text email = createLT(body, "Email",
-                               getProperty(ARGEO_PRIMARY_EMAIL));
-               final Text description = createLMT(body, "Description",
-                               getProperty(Property.JCR_DESCRIPTION));
-
-               // create form part (controller)
-               AbstractFormPart part = new SectionPart(section) {
-                       public void commit(boolean onSave) {
-                               try {
-                                       userProfile.getSession().getWorkspace().getVersionManager()
-                                                       .checkout(userProfile.getPath());
-                                       userProfile.setProperty(Property.JCR_TITLE,
-                                                       commonName.getText());
-                                       userProfile.setProperty(ARGEO_FIRST_NAME,
-                                                       firstName.getText());
-                                       userProfile
-                                                       .setProperty(ARGEO_LAST_NAME, lastName.getText());
-                                       userProfile.setProperty(ARGEO_PRIMARY_EMAIL,
-                                                       email.getText());
-                                       userProfile.setProperty(Property.JCR_DESCRIPTION,
-                                                       description.getText());
-                                       userProfile.getSession().save();
-                                       userProfile.getSession().getWorkspace().getVersionManager()
-                                                       .checkin(userProfile.getPath());
-                                       super.commit(onSave);
-                                       refreshFormTitle(getManagedForm().getForm());
-                                       if (log.isTraceEnabled())
-                                               log.trace("General part committed");
-                               } catch (RepositoryException e) {
-                                       throw new CmsException("Cannot commit", e);
-                               }
-                       }
-               };
-               // if (username != null)
-               // username.addModifyListener(new FormPartML(part));
-               commonName.addModifyListener(new FormPartML(part));
-               firstName.addModifyListener(new FormPartML(part));
-               lastName.addModifyListener(new FormPartML(part));
-               email.addModifyListener(new FormPartML(part));
-               description.addModifyListener(new FormPartML(part));
-               getManagedForm().addPart(part);
-       }
-
-       private void refreshFormTitle(ScrolledForm form) throws RepositoryException {
-               form.setText(getProperty(Property.JCR_TITLE)
-                               + (userProfile.getProperty(ARGEO_ENABLED).getBoolean() ? ""
-                                               : " [DISABLED]"));
-       }
-
-       /** @return the property, or the empty string if not set */
-       protected String getProperty(String name) throws RepositoryException {
-               return userProfile.hasProperty(name) ? userProfile.getProperty(name)
-                               .getString() : "";
-       }
-
-       /** Creates the password section */
-       protected void createPassworPart(Composite parent) {
-               FormToolkit tk = getManagedForm().getToolkit();
-               Section section = tk.createSection(parent, Section.TITLE_BAR);
-               section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-               section.setText("Password");
-
-               Composite body = tk.createComposite(section, SWT.WRAP);
-               section.setClient(body);
-               GridLayout layout = new GridLayout(2, false);
-               body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-               body.setLayout(layout);
-
-               // add widgets (view)
-               final Text password1 = createLP(body, "New password", "");
-               final Text password2 = createLP(body, "Repeat password", "");
-               // create form part (controller)
-               AbstractFormPart part = new SectionPart(section) {
-
-                       public void commit(boolean onSave) {
-                               if (!password1.getText().equals("")
-                                               || !password2.getText().equals("")) {
-                                       if (password1.getText().equals(password2.getText())) {
-                                               newPassword = password1.getText().toCharArray();
-                                               password1.setText("");
-                                               password2.setText("");
-                                               super.commit(onSave);
-                                       } else {
-                                               password1.setText("");
-                                               password2.setText("");
-                                               throw new CmsException("Passwords are not equals");
-                                       }
-                               }
-                       }
-
-               };
-               password1.addModifyListener(new FormPartML(part));
-               password2.addModifyListener(new FormPartML(part));
-               getManagedForm().addPart(part);
-       }
-
-       /** Creates label and text. */
-       protected Text createLT(Composite body, String label, String value) {
-               FormToolkit toolkit = getManagedForm().getToolkit();
-               Label lbl = toolkit.createLabel(body, label);
-               lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
-               Text text = toolkit.createText(body, value, SWT.BORDER);
-               text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-               return text;
-       }
-
-       /** Creates label and multiline text. */
-       protected Text createLMT(Composite body, String label, String value) {
-               FormToolkit toolkit = getManagedForm().getToolkit();
-               Label lbl = toolkit.createLabel(body, label);
-               lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
-               Text text = toolkit.createText(body, value, SWT.BORDER | SWT.MULTI);
-               text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
-               return text;
-       }
-
-       /** Creates label and password. */
-       protected Text createLP(Composite body, String label, String value) {
-               FormToolkit toolkit = getManagedForm().getToolkit();
-               Label lbl = toolkit.createLabel(body, label);
-               lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
-               Text text = toolkit.createText(body, value, SWT.BORDER | SWT.PASSWORD);
-               text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-               return text;
-       }
-
-       private class FormPartML implements ModifyListener {
-               private static final long serialVersionUID = 6299808129505381333L;
-               private AbstractFormPart formPart;
-
-               public FormPartML(AbstractFormPart generalPart) {
-                       this.formPart = generalPart;
-               }
-
-               public void modifyText(ModifyEvent e) {
-                       formPart.markDirty();
-               }
-       }
-
-       public String getNewPassword() {
-               if (newPassword != null)
-                       return new String(newPassword);
-               else
-                       return null;
-       }
-
-       public void resetNewPassword() {
-               if (newPassword != null)
-                       Arrays.fill(newPassword, 'x');
-               newPassword = null;
-       }
-}
index 29ff106ee8a9667522a3579371cfcfb0d3a47acc..ff113d1dd0a41f583df8bcedf2435250d60db840 100644 (file)
@@ -358,7 +358,7 @@ public class UserBatchUpdateWizard extends Wizard {
                @SuppressWarnings("unused")
                protected boolean getBoleanValue() {
                        // FIXME this is not consistent and will lead to errors.
-                       if (ArgeoNames.ARGEO_ENABLED.equals(getCommand()))
+                       if ("argeo:enabled".equals(getCommand()))
                                return trueChk.getSelection();
                        else
                                return !trueChk.getSelection();
diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/jcr/JcrPreferenceStore.java b/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/jcr/JcrPreferenceStore.java
deleted file mode 100644 (file)
index d1917d9..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.cms.ui.workbench.jcr;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.Properties;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.version.VersionManager;
-
-import org.apache.commons.io.IOUtils;
-import org.argeo.eclipse.ui.EclipseUiException;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.node.ArgeoNames;
-import org.argeo.node.ArgeoTypes;
-import org.argeo.node.NodeUtils;
-import org.eclipse.jface.preference.PreferenceStore;
-import org.osgi.framework.BundleContext;
-
-/**
- * Persist preferences as key/value pairs under ~/argeo:preferences.<br>
- * TODO: better integrate JCR and Eclipse:<br>
- * - typing<br>
- * - use eclipse preferences<br>
- * - better integrate with <code>ScopedPreferenceStore</code> provided by RAP
- */
-public class JcrPreferenceStore extends PreferenceStore implements ArgeoNames {
-       private static final long serialVersionUID = 1854011367784598758L;
-
-       private Session session;
-       private BundleContext bundleContext;
-
-       /** Retrieves the preference node */
-       protected Node getPreferenceNode() {
-               try {
-                       if (session.hasPendingChanges())
-                               session.save();
-                       Node userHome = NodeUtils.getUserHome(session);
-                       if (userHome == null)
-                               throw new EclipseUiException("No user home for "
-                                               + session.getUserID());
-                       Node preferences;
-                       if (!userHome.hasNode(ARGEO_PREFERENCES)) {
-                               preferences = userHome.addNode(ARGEO_PREFERENCES);
-                               preferences.addMixin(ArgeoTypes.ARGEO_PREFERENCE_NODE);
-                               session.save();
-                       } else
-                               preferences = userHome.getNode(ARGEO_PREFERENCES);
-
-                       String pluginPreferencesName = bundleContext.getBundle()
-                                       .getSymbolicName();
-                       Node pluginPreferences;
-                       if (!preferences.hasNode(pluginPreferencesName)) {
-                               VersionManager vm = session.getWorkspace().getVersionManager();
-                               vm.checkout(preferences.getPath());
-                               pluginPreferences = preferences.addNode(pluginPreferencesName);
-                               pluginPreferences.addMixin(ArgeoTypes.ARGEO_PREFERENCE_NODE);
-                               session.save();
-                               vm.checkin(preferences.getPath());
-                       } else
-                               pluginPreferences = preferences.getNode(pluginPreferencesName);
-                       return pluginPreferences;
-               } catch (RepositoryException e) {
-                       e.printStackTrace();
-                       JcrUtils.discardQuietly(session);
-                       throw new EclipseUiException("Cannot retrieve preferences", e);
-               }
-
-       }
-
-       @Override
-       public void load() throws IOException {
-               ByteArrayOutputStream out = null;
-               ByteArrayInputStream in = null;
-               try {
-                       Properties props = new Properties();
-                       PropertyIterator it = getPreferenceNode().getProperties();
-                       while (it.hasNext()) {
-                               Property p = it.nextProperty();
-                               if (!p.isMultiple() && !p.getDefinition().isProtected()) {
-                                       props.setProperty(p.getName(), p.getValue().getString());
-                               }
-                       }
-                       out = new ByteArrayOutputStream();
-                       props.store(out, "");
-                       in = new ByteArrayInputStream(out.toByteArray());
-                       load(in);
-               } catch (Exception e) {
-                       e.printStackTrace();
-                       throw new EclipseUiException("Cannot load preferences", e);
-               } finally {
-                       IOUtils.closeQuietly(in);
-                       IOUtils.closeQuietly(out);
-               }
-       }
-
-       @Override
-       public void save() throws IOException {
-               ByteArrayOutputStream out = null;
-               ByteArrayInputStream in = null;
-               Node pluginPreferences = null;
-               try {
-                       out = new ByteArrayOutputStream();
-                       save(out, "");
-                       in = new ByteArrayInputStream(out.toByteArray());
-                       Properties props = new Properties();
-                       props.load(in);
-                       pluginPreferences = getPreferenceNode();
-                       VersionManager vm = pluginPreferences.getSession().getWorkspace()
-                                       .getVersionManager();
-                       vm.checkout(pluginPreferences.getPath());
-                       for (Object key : props.keySet()) {
-                               String name = key.toString();
-                               String value = props.getProperty(name);
-                               pluginPreferences.setProperty(name, value);
-                       }
-                       JcrUtils.updateLastModified(pluginPreferences);
-                       pluginPreferences.getSession().save();
-                       vm.checkin(pluginPreferences.getPath());
-               } catch (Exception e) {
-                       JcrUtils.discardUnderlyingSessionQuietly(pluginPreferences);
-                       throw new EclipseUiException("Cannot save preferences", e);
-               } finally {
-                       IOUtils.closeQuietly(in);
-                       IOUtils.closeQuietly(out);
-               }
-       }
-
-       public void init() {
-               try {
-                       load();
-               } catch (IOException e) {
-                       throw new EclipseUiException("Cannot initialize preference store", e);
-               }
-       }
-
-       public void setSession(Session session) {
-               this.session = session;
-       }
-
-       public void setBundleContext(BundleContext bundleContext) {
-               this.bundleContext = bundleContext;
-       }
-
-}
index 12539a597666fecc6a8be0a73976cd31286552fe..613e3cb6446e5401114cf508d389ac42300e8dc2 100644 (file)
@@ -82,12 +82,12 @@ class DataDeploymentUi extends AbstractOsgiComposite {
        private void initCurrentUi(Composite parent) {
                parent.setLayout(new GridLayout());
                Collection<ServiceReference<RepositoryContext>> contexts = getServiceReferences(RepositoryContext.class,
-                               "(" + NodeConstants.JCR_REPOSITORY_ALIAS + "=*)");
+                               "(" + NodeConstants.CN + "=*)");
                StringBuffer text = new StringBuffer();
                text.append("<span style='font-variant: small-caps;'>Jackrabbit Repositories</span><br/>");
                for (ServiceReference<RepositoryContext> sr : contexts) {
                        RepositoryContext repositoryContext = bc.getService(sr);
-                       String alias = sr.getProperty(NodeConstants.JCR_REPOSITORY_ALIAS).toString();
+                       String alias = sr.getProperty(NodeConstants.CN).toString();
                        String rootNodeId = repositoryContext.getRootNodeId().toString();
                        RepositoryConfig repositoryConfig = repositoryContext.getRepositoryConfig();
                        Path repoHomePath = new File(repositoryConfig.getHomeDir()).toPath().toAbsolutePath();
index 665c4c6140f960eee4a418fb879c6871f9f36b51..108dd3a95b8b28840c521f7baf54841547e0ea3e 100644 (file)
@@ -7,7 +7,9 @@ import java.net.URL;
 import javax.jcr.Item;
 import javax.jcr.Node;
 import javax.jcr.Property;
+import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.io.IOUtils;
@@ -59,7 +61,8 @@ public class CmsUtils implements CmsConstants {
                        throw new CmsException("Cannot extract server base URL from " + request.getRequestURL(), e);
                }
        }
-//
+
+       //
        public static String getDataUrl(Node node, HttpServletRequest request) throws RepositoryException {
                try {
                        StringBuilder buf = getServerBaseUrl(request);
@@ -69,10 +72,12 @@ public class CmsUtils implements CmsConstants {
                        throw new CmsException("Cannot build data URL for " + node, e);
                }
        }
-// FIXME
+
+       // FIXME
        private final static String PATH_DATA = "/data";
        private final static String WEBDAV_PUBLIC = PATH_DATA + "/public";
        private final static String WEBDAV_PRIVATE = PATH_DATA + "/files";
+
        public static String getDataPath(Node node) throws RepositoryException {
                assert node != null;
                String userId = node.getSession().getUserID();
@@ -84,22 +89,31 @@ public class CmsUtils implements CmsConstants {
                        buf.append(WEBDAV_PUBLIC);
                else
                        buf.append(WEBDAV_PRIVATE);
-               // TODO convey repo alias vie repository properties
-               return buf.append('/').append(NodeConstants.ALIAS_NODE).append('/').append(node.getSession().getWorkspace().getName())
-                               .append(node.getPath()).toString();
-       }
-//
-//     public static String getCanonicalUrl(Node node, HttpServletRequest request) throws RepositoryException {
-//             try {
-//                     StringBuilder buf = getServerBaseUrl(request);
-//                     buf.append('/').append('!').append(node.getPath());
-//                     return new URL(buf.toString()).toString();
-//             } catch (MalformedURLException e) {
-//                     throw new CmsException("Cannot build data URL for " + node, e);
-//             }
-//             // return request.getRequestURL().append('!').append(node.getPath())
-//             // .toString();
-//     }
+               Session session = node.getSession();
+               Repository repository = session.getRepository();
+               String cn;
+               if (repository.isSingleValueDescriptor(NodeConstants.CN)) {
+                       cn = repository.getDescriptor(NodeConstants.CN);
+               } else {
+                       log.warn("No cn defined in repository, using " + NodeConstants.NODE);
+                       cn = NodeConstants.NODE;
+               }
+               return buf.append('/').append(cn).append('/').append(session.getWorkspace().getName()).append(node.getPath())
+                               .toString();
+       }
+       //
+       // public static String getCanonicalUrl(Node node, HttpServletRequest
+       // request) throws RepositoryException {
+       // try {
+       // StringBuilder buf = getServerBaseUrl(request);
+       // buf.append('/').append('!').append(node.getPath());
+       // return new URL(buf.toString()).toString();
+       // } catch (MalformedURLException e) {
+       // throw new CmsException("Cannot build data URL for " + node, e);
+       // }
+       // // return request.getRequestURL().append('!').append(node.getPath())
+       // // .toString();
+       // }
 
        /** @deprecated Use rowData16px() instead. GridData should not be reused. */
        @Deprecated
index d2d89522fec99aff5a642a7b5191f00a4df98494..e30249f3c63fcbbe751b4ea2ed4923558952c946 100644 (file)
@@ -43,6 +43,8 @@ import org.osgi.service.useradmin.UserAdmin;
 import org.osgi.util.tracker.ServiceTracker;
 
 public class CmsDeployment implements NodeDeployment {
+       private final static String LEGACY_JCR_REPOSITORY_ALIAS = "argeo.jcr.repository.alias";
+       
        private final Log log = LogFactory.getLog(getClass());
        private final BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
 
@@ -133,10 +135,13 @@ public class CmsDeployment implements NodeDeployment {
 
                // home
                prepareDataModel(KernelUtils.openAdminSession(deployedNodeRepository));
+       }
+
+       private void prepareHomeRepository(Repository deployedRepository) {
                Hashtable<String, String> regProps = new Hashtable<String, String>();
-               regProps.put(NodeConstants.CN, NodeConstants.ALIAS_HOME);
-               regProps.put(NodeConstants.JCR_REPOSITORY_ALIAS, NodeConstants.ALIAS_HOME);
-               homeRepository = new HomeRepository(deployedNodeRepository);
+               regProps.put(NodeConstants.CN, NodeConstants.HOME);
+               regProps.put(LEGACY_JCR_REPOSITORY_ALIAS, NodeConstants.HOME);
+               homeRepository = new HomeRepository(deployedRepository);
                // register
                bc.registerService(Repository.class, homeRepository, regProps);
 
@@ -204,9 +209,9 @@ public class CmsDeployment implements NodeDeployment {
 
                if (!asBoolean((String) attrs.get(DataModelNamespace.CAPABILITY_ABSTRACT_ATTRIBUTE))) {
                        Hashtable<String, Object> properties = new Hashtable<>();
-                       properties.put(NodeConstants.JCR_REPOSITORY_ALIAS, name);
+                       properties.put(LEGACY_JCR_REPOSITORY_ALIAS, name);
                        properties.put(NodeConstants.CN, name);
-                       if (name.equals(NodeConstants.ALIAS_NODE))
+                       if (name.equals(NodeConstants.NODE))
                                properties.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
                        LocalRepository localRepository = new LocalRepository(adminSession.getRepository(), capability);
                        bc.registerService(Repository.class, localRepository, properties);
@@ -244,10 +249,15 @@ public class CmsDeployment implements NodeDeployment {
                public RepositoryContext addingService(ServiceReference<RepositoryContext> reference) {
                        RepositoryContext nodeRepo = bc.getService(reference);
                        Object cn = reference.getProperty(NodeConstants.CN);
-                       if (cn != null && cn.equals(NodeConstants.ALIAS_NODE)) {
-                               prepareNodeRepository(nodeRepo.getRepository());
-                               nodeAvailable = true;
-                               checkReadiness();
+                       if (cn != null) {
+                               if (cn.equals(NodeConstants.NODE)) {
+                                       prepareNodeRepository(nodeRepo.getRepository());
+                                       prepareHomeRepository(nodeRepo.getRepository());
+                                       nodeAvailable = true;
+                                       checkReadiness();
+                               }else{
+                                       // TODO standalone
+                               }
                        }
                        return nodeRepo;
                }
index fb3e6ad4d88c5f6b531edf45182c2a4fe577bf40..5fedd1d314d2a3b6fe9aea5df884b897f8c58f3d 100644 (file)
@@ -26,7 +26,7 @@ public class CmsInstance implements NodeInstance {
                        @Override
                        public Repository addingService(ServiceReference<Repository> reference) {
                                Object cn = reference.getProperty(NodeConstants.CN);
-                               if (cn != null && cn.equals(NodeConstants.ALIAS_NODE)) {
+                               if (cn != null && cn.equals(NodeConstants.NODE)) {
                                        if (log.isDebugEnabled())
                                                log.debug("Node repository is available");
                                }
index a2202e3095a15130589332d2224ad0d20f3b1061..a1507a5910aaf2392c76a04d317380d266e70cbf 100644 (file)
@@ -158,7 +158,7 @@ class DataHttp implements KernelConstants {
                @Override
                public Repository addingService(ServiceReference<Repository> reference) {
                        Repository repository = bc.getService(reference);
-                       Object jcrRepoAlias = reference.getProperty(NodeConstants.JCR_REPOSITORY_ALIAS);
+                       Object jcrRepoAlias = reference.getProperty(NodeConstants.CN);
                        if (jcrRepoAlias != null) {
                                String alias = jcrRepoAlias.toString();
                                registerRepositoryServlets(alias, repository);
@@ -172,7 +172,7 @@ class DataHttp implements KernelConstants {
 
                @Override
                public void removedService(ServiceReference<Repository> reference, Repository service) {
-                       Object jcrRepoAlias = reference.getProperty(NodeConstants.JCR_REPOSITORY_ALIAS);
+                       Object jcrRepoAlias = reference.getProperty(NodeConstants.CN);
                        if (jcrRepoAlias != null) {
                                String alias = jcrRepoAlias.toString();
                                unregisterRepositoryServlets(alias);
index a9b30681bc32419f2858a7f59b9397f60336ae6d..61e840e3226d1c5c513585a41b1f2ba49915edea 100644 (file)
@@ -67,7 +67,7 @@ class DeployConfig implements ConfigurationListener {
 
                // node repository
                Dictionary<String, Object> nodeConfig = firstInit
-                               .getNodeRepositoryConfig(getProps(NodeConstants.NODE_REPOS_FACTORY_PID, NodeConstants.ALIAS_NODE));
+                               .getNodeRepositoryConfig(getProps(NodeConstants.NODE_REPOS_FACTORY_PID, NodeConstants.NODE));
                // node repository is mandatory
                putFactoryDeployConfig(NodeConstants.NODE_REPOS_FACTORY_PID, nodeConfig);
 
index a1c87cf6be3c9d659210574cebb4d78130e9bdb5..621fe6f14e3dabfe06f444938148c28945eb00fb 100644 (file)
@@ -38,8 +38,8 @@ class FirstInitProperties {
                        if (value != null)
                                props.put(repoConf.name(), value);
                }
-               props.put(NodeConstants.CN, NodeConstants.ALIAS_NODE);
-               props.put(NodeConstants.JCR_REPOSITORY_ALIAS, NodeConstants.ALIAS_NODE);
+               props.put(NodeConstants.CN, NodeConstants.NODE);
+//             props.put(NodeConstants.JCR_REPOSITORY_ALIAS, NodeConstants.NODE);
                return props;
        }
 
index aac2a3d9e6b893be2c7e338178175a4c597265f6..68acd2d62baa9086ceb1c257567fb50699d2f1f5 100644 (file)
@@ -18,9 +18,9 @@ import org.apache.jackrabbit.core.security.SecurityConstants;
 import org.argeo.cms.CmsException;
 import org.argeo.jcr.JcrRepositoryWrapper;
 import org.argeo.jcr.JcrUtils;
-import org.argeo.node.ArgeoNames;
-import org.argeo.node.ArgeoTypes;
 import org.argeo.node.NodeConstants;
+import org.argeo.node.NodeNames;
+import org.argeo.node.NodeTypes;
 import org.argeo.node.NodeUtils;
 
 /**
@@ -29,12 +29,13 @@ import org.argeo.node.NodeUtils;
 class HomeRepository extends JcrRepositoryWrapper implements KernelConstants {
        /** The home base path. */
        private String homeBasePath = "/home";
-       private String peopleBasePath = NodeConstants.PEOPLE_BASE_PATH;
+//     private String peopleBasePath = NodeConstants.PEOPLE_BASE_PATH;
 
        private Set<String> checkedUsers = new HashSet<String>();
 
        public HomeRepository(Repository repository) {
-               setRepository(repository);
+               super(repository);
+               putDescriptor(NodeConstants.CN, NodeConstants.HOME);
                LoginContext lc;
                try {
                        lc = new LoginContext(NodeConstants.LOGIN_CONTEXT_DATA_ADMIN);
@@ -110,13 +111,13 @@ class HomeRepository extends JcrRepositoryWrapper implements KernelConstants {
        private void initJcr(Session adminSession) {
                try {
                        JcrUtils.mkdirs(adminSession, homeBasePath);
-                       JcrUtils.mkdirs(adminSession, peopleBasePath);
+//                     JcrUtils.mkdirs(adminSession, peopleBasePath);
                        adminSession.save();
 
                        JcrUtils.addPrivilege(adminSession, homeBasePath,
                                        NodeConstants.ROLE_USER_ADMIN, Privilege.JCR_READ);
-                       JcrUtils.addPrivilege(adminSession, peopleBasePath,
-                                       NodeConstants.ROLE_USER_ADMIN, Privilege.JCR_ALL);
+//                     JcrUtils.addPrivilege(adminSession, peopleBasePath,
+//                                     NodeConstants.ROLE_USER_ADMIN, Privilege.JCR_ALL);
                        adminSession.save();
                } catch (RepositoryException e) {
                        throw new CmsException("Cannot initialize node user admin", e);
@@ -125,7 +126,7 @@ class HomeRepository extends JcrRepositoryWrapper implements KernelConstants {
                }
        }
 
-       private Node syncJcr(Session session, String username) {
+       private void syncJcr(Session session, String username) {
                try {
                        Node userHome = NodeUtils.getUserHome(session, username);
                        if (userHome == null) {
@@ -136,8 +137,8 @@ class HomeRepository extends JcrRepositoryWrapper implements KernelConstants {
                                else
                                        userHome = JcrUtils.mkdirs(session, homePath);
                                // userHome = JcrUtils.mkfolders(session, homePath);
-                               userHome.addMixin(ArgeoTypes.ARGEO_USER_HOME);
-                               userHome.setProperty(ArgeoNames.ARGEO_USER_ID, username);
+                               userHome.addMixin(NodeTypes.NODE_USER_HOME);
+                               userHome.setProperty(NodeNames.LDAP_UID, username);
                                session.save();
 
                                JcrUtils.clearAccessControList(session, homePath, username);
@@ -145,33 +146,33 @@ class HomeRepository extends JcrRepositoryWrapper implements KernelConstants {
                                                Privilege.JCR_ALL);
                        }
 
-                       Node userProfile = NodeUtils.getUserProfile(session, username);
-                       // new user
-                       if (userProfile == null) {
-                               String personPath = generateUserPath(peopleBasePath, username);
-                               Node personBase;
-                               if (session.itemExists(personPath))// duplicate user id
-                                       personBase = session.getNode(personPath).getParent()
-                                                       .addNode(JcrUtils.lastPathElement(personPath));
-                               else
-                                       personBase = JcrUtils.mkdirs(session, personPath);
-                               userProfile = personBase.addNode(ArgeoNames.ARGEO_PROFILE);
-                               userProfile.addMixin(ArgeoTypes.ARGEO_USER_PROFILE);
-                               userProfile.setProperty(ArgeoNames.ARGEO_USER_ID, username);
-                               // userProfile.setProperty(ArgeoNames.ARGEO_ENABLED, true);
-                               // userProfile.setProperty(ArgeoNames.ARGEO_ACCOUNT_NON_EXPIRED,
-                               // true);
-                               // userProfile.setProperty(ArgeoNames.ARGEO_ACCOUNT_NON_LOCKED,
-                               // true);
-                               // userProfile.setProperty(ArgeoNames.ARGEO_CREDENTIALS_NON_EXPIRED,
-                               // true);
-                               session.save();
-
-                               JcrUtils.clearAccessControList(session, userProfile.getPath(),
-                                               username);
-                               JcrUtils.addPrivilege(session, userProfile.getPath(), username,
-                                               Privilege.JCR_READ);
-                       }
+//                     Node userProfile = NodeUtils.getUserProfile(session, username);
+//                     // new user
+//                     if (userProfile == null) {
+//                             String personPath = generateUserPath(peopleBasePath, username);
+//                             Node personBase;
+//                             if (session.itemExists(personPath))// duplicate user id
+//                                     personBase = session.getNode(personPath).getParent()
+//                                                     .addNode(JcrUtils.lastPathElement(personPath));
+//                             else
+//                                     personBase = JcrUtils.mkdirs(session, personPath);
+//                             userProfile = personBase.addNode(ArgeoNames.ARGEO_PROFILE);
+//                             userProfile.addMixin(ArgeoTypes.ARGEO_USER_PROFILE);
+//                             userProfile.setProperty(ArgeoNames.ARGEO_USER_ID, username);
+//                             // userProfile.setProperty(ArgeoNames.ARGEO_ENABLED, true);
+//                             // userProfile.setProperty(ArgeoNames.ARGEO_ACCOUNT_NON_EXPIRED,
+//                             // true);
+//                             // userProfile.setProperty(ArgeoNames.ARGEO_ACCOUNT_NON_LOCKED,
+//                             // true);
+//                             // userProfile.setProperty(ArgeoNames.ARGEO_CREDENTIALS_NON_EXPIRED,
+//                             // true);
+//                             session.save();
+//
+//                             JcrUtils.clearAccessControList(session, userProfile.getPath(),
+//                                             username);
+//                             JcrUtils.addPrivilege(session, userProfile.getPath(), username,
+//                                             Privilege.JCR_READ);
+//                     }
 
                        // Remote roles
                        // if (roles != null) {
@@ -179,7 +180,7 @@ class HomeRepository extends JcrRepositoryWrapper implements KernelConstants {
                        // }
                        if (session.hasPendingChanges())
                                session.save();
-                       return userProfile;
+//                     return userProfile;
                } catch (RepositoryException e) {
                        JcrUtils.discardQuietly(session);
                        throw new CmsException("Cannot sync node security model for "
index 8d3044013fd1bcb85d2f3703106ee3509b2dbb1d..909b1faff1722dc284e7a34d682ef2e4e6834f86 100644 (file)
@@ -245,9 +245,17 @@ class KernelUtils implements KernelConstants {
                        buf.append(WEBDAV_PUBLIC);
                else
                        buf.append(WEBDAV_PRIVATE);
-               // TODO convey repo alias vie repository properties
-               return buf.append('/').append(NodeConstants.ALIAS_NODE).append('/').append(node.getSession().getWorkspace().getName())
-                               .append(node.getPath()).toString();
+               Session session = node.getSession();
+               Repository repository = session.getRepository();
+               String cn;
+               if (repository.isSingleValueDescriptor(NodeConstants.CN)) {
+                       cn = repository.getDescriptor(NodeConstants.CN);
+               } else {
+//                     log.warn("No cn defined in repository, using " + NodeConstants.NODE);
+                       cn = NodeConstants.NODE;
+               }
+               return buf.append('/').append(cn).append('/').append(session.getWorkspace().getName()).append(node.getPath())
+                               .toString();
        }
 
        public static String getCanonicalUrl(Node node, HttpServletRequest request) throws RepositoryException {
index 4a39a0fc3f45de11ec69aeb6958e4ff5a3455a3f..67c66e915302e898c87749ee37bdb38688a85162 100644 (file)
@@ -6,15 +6,17 @@ import javax.jcr.Repository;
 
 import org.argeo.jcr.JcrRepositoryWrapper;
 import org.argeo.node.DataModelNamespace;
+import org.argeo.node.NodeConstants;
 import org.osgi.framework.wiring.BundleCapability;
 
 class LocalRepository extends JcrRepositoryWrapper {
        private final String cn;
 
        public LocalRepository(Repository repository, BundleCapability dataModelCapability) {
+               super(repository);
                Map<String, Object> attrs = dataModelCapability.getAttributes();
                cn = (String) attrs.get(DataModelNamespace.CAPABILITY_NAME_ATTRIBUTE);
-               setRepository(repository);
+               putDescriptor(NodeConstants.CN, cn);
        }
 
        String getCn() {
index 0510b3c837116053f1ac5c8265e5c2213b96885d..abaadb0b14733a8633a8d9598db6fd0bd571b29c 100644 (file)
@@ -116,7 +116,7 @@ class NodeHttp implements KernelConstants {
                                        @Override
                                        public Session run() throws Exception {
                                                Collection<ServiceReference<Repository>> srs = bc.getServiceReferences(Repository.class, "("
-                                                               + NodeConstants.JCR_REPOSITORY_ALIAS + "=" + NodeConstants.ALIAS_NODE + ")");
+                                                               + NodeConstants.CN + "=" + NodeConstants.NODE + ")");
                                                Repository repository = bc.getService(srs.iterator().next());
                                                return repository.login();
                                        }
index b59b5e29c29ef23f8307b8b95e2719ff08717ee5..2e3e78f0da5b49380d55f453978f3f6ae78bbd48 100644 (file)
@@ -50,7 +50,7 @@ class NodeRepositoryFactory implements RepositoryFactory {
        protected Repository getRepositoryByAlias(String alias) {
                try {
                        Collection<ServiceReference<Repository>> srs = bundleContext.getServiceReferences(Repository.class,
-                                       "(" + NodeConstants.JCR_REPOSITORY_ALIAS + "=" + alias + ")");
+                                       "(" + NodeConstants.CN + "=" + alias + ")");
                        if (srs.size() == 0)
                                throw new ArgeoJcrException("No repository with alias " + alias + " found in OSGi registry");
                        else if (srs.size() > 1)
@@ -84,8 +84,8 @@ class NodeRepositoryFactory implements RepositoryFactory {
                // check if remote
                Repository repository;
                String uri = null;
-               if (parameters.containsKey(NodeConstants.JCR_REPOSITORY_URI))
-                       uri = parameters.get(NodeConstants.JCR_REPOSITORY_URI).toString();
+               if (parameters.containsKey(NodeConstants.LABELED_URI))
+                       uri = parameters.get(NodeConstants.LABELED_URI).toString();
                else if (parameters.containsKey(KernelConstants.JACKRABBIT_REPOSITORY_URI))
                        uri = parameters.get(KernelConstants.JACKRABBIT_REPOSITORY_URI).toString();
 
@@ -103,10 +103,10 @@ class NodeRepositoryFactory implements RepositoryFactory {
 
                }
 
-               else if (parameters.containsKey(NodeConstants.JCR_REPOSITORY_ALIAS)) {
+               else if (parameters.containsKey(NodeConstants.CN)) {
                        // Properties properties = new Properties();
                        // properties.putAll(parameters);
-                       String alias = parameters.get(NodeConstants.JCR_REPOSITORY_ALIAS).toString();
+                       String alias = parameters.get(NodeConstants.CN).toString();
                        // publish(alias, repository, properties);
                        // log.info("Registered JCR repository under alias '" + alias + "'
                        // with properties " + properties);
index e6efa1e79bbe29fb08b009dfcff6924249b8e760..6ec27659063087838443a89ef8f1a1d89eb5e737 100644 (file)
@@ -51,7 +51,7 @@ class RepositoryServiceFactory implements ManagedServiceFactory {
                        Object cn = properties.get(NodeConstants.CN);
                        if (cn != null) {
                                props.put(NodeConstants.CN, cn);
-                               props.put(NodeConstants.JCR_REPOSITORY_ALIAS, cn);
+//                             props.put(NodeConstants.JCR_REPOSITORY_ALIAS, cn);
                                pidToCn.put(pid, cn);
                        }
                        bc.registerService(RepositoryContext.class, repositoryContext, props);
index 83b61e4590e15ba8da1b98ea54d342b5ecdb1a69..44b4299343daee5298ab3d26aff8f0940ee9927d 100644 (file)
@@ -1,8 +1,9 @@
 package org.argeo.osgi.metatype;
 
+import org.argeo.naming.SpecifiedName;
 import org.osgi.service.metatype.AttributeDefinition;
 
-public interface EnumAD extends AttributeDefinition {
+public interface EnumAD extends SpecifiedName, AttributeDefinition {
        String name();
 
        default Object getDefault() {
index 3f5bf850d55a890093804df97993f27f1eb809e4..e8dd6f2a6974af43f0b5dda922256c847c27f8b7 100644 (file)
@@ -1,10 +1,10 @@
 package org.argeo.osgi.useradmin;
 
-import static org.argeo.osgi.useradmin.LdifName.inetOrgPerson;
-import static org.argeo.osgi.useradmin.LdifName.objectClass;
-import static org.argeo.osgi.useradmin.LdifName.organizationalPerson;
-import static org.argeo.osgi.useradmin.LdifName.person;
-import static org.argeo.osgi.useradmin.LdifName.top;
+import static org.argeo.naming.LdapAttrs.objectClass;
+import static org.argeo.naming.LdapObjs.inetOrgPerson;
+import static org.argeo.naming.LdapObjs.organizationalPerson;
+import static org.argeo.naming.LdapObjs.person;
+import static org.argeo.naming.LdapObjs.top;
 
 import java.io.File;
 import java.net.URI;
@@ -29,6 +29,7 @@ import javax.transaction.TransactionManager;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.argeo.naming.LdapAttrs;
 import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
@@ -50,10 +51,10 @@ public abstract class AbstractUserDirectory implements UserAdmin, UserDirectory
 
        private UserAdmin externalRoles;
        private List<String> indexedUserProperties = Arrays
-                       .asList(new String[] { LdifName.uid.name(), LdifName.mail.name(), LdifName.cn.name() });
+                       .asList(new String[] { LdapAttrs.uid.name(), LdapAttrs.mail.name(), LdapAttrs.cn.name() });
 
        private String memberAttributeId = "member";
-       private List<String> credentialAttributeIds = Arrays.asList(new String[] { LdifName.userPassword.name() });
+       private List<String> credentialAttributeIds = Arrays.asList(new String[] { LdapAttrs.userPassword.name() });
 
        // JTA
        private TransactionManager transactionManager;
index 7a617dfd6115ee3012717ad60276f040b5bb87ed..f78da0af0d29aed943c3cda8831bb9d97bffef47 100644 (file)
@@ -1,6 +1,6 @@
 package org.argeo.osgi.useradmin;
 
-import static org.argeo.osgi.useradmin.LdifName.objectClass;
+import static org.argeo.naming.LdapAttrs.objectClass;
 
 import java.util.ArrayList;
 import java.util.Dictionary;
@@ -24,6 +24,7 @@ import javax.transaction.TransactionManager;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.argeo.naming.LdapAttrs;
 import org.osgi.framework.Filter;
 
 /**
@@ -41,7 +42,7 @@ public class LdapUserAdmin extends AbstractUserDirectory {
                        Hashtable<String, Object> connEnv = new Hashtable<String, Object>();
                        connEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                        connEnv.put(Context.PROVIDER_URL, getUri().toString());
-                       connEnv.put("java.naming.ldap.attributes.binary", LdifName.userPassword.name());
+                       connEnv.put("java.naming.ldap.attributes.binary", LdapAttrs.userPassword.name());
 
                        initialLdapContext = new InitialLdapContext(connEnv, null);
                        // StartTlsResponse tls = (StartTlsResponse) ctx
index e06c42e1ffb213c501ce23b2bc2edd90498b74c0..c92ccf7a77e75918a0ec64b5f7e1090c68920599 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Collections;
 import java.util.Dictionary;
 import java.util.List;
 
+import org.argeo.naming.LdapAttrs;
 import org.osgi.service.useradmin.Authorization;
 import org.osgi.service.useradmin.Role;
 import org.osgi.service.useradmin.User;
@@ -23,11 +24,11 @@ class LdifAuthorization implements Authorization {
                } else {
                        this.name = user.getName();
                        Dictionary<String, Object> props = user.getProperties();
-                       Object displayName = props.get(LdifName.displayName);
+                       Object displayName = props.get(LdapAttrs.displayName);
                        if (displayName == null)
-                               displayName = props.get(LdifName.cn);
+                               displayName = props.get(LdapAttrs.cn);
                        if (displayName == null)
-                               displayName = props.get(LdifName.uid);
+                               displayName = props.get(LdapAttrs.uid);
                        if (displayName == null)
                                displayName = user.getName();
                        if (displayName == null)
index 919e5073f88e1d5e751aba174227b4cc08eb0c56..9beac3a51699499f1bb235fef5502c9e01ebe878 100644 (file)
@@ -2,11 +2,17 @@ package org.argeo.osgi.useradmin;
 
 import javax.naming.ldap.LdapName;
 
+import org.argeo.naming.LdapAttrs;
+import org.argeo.naming.LdapObjs;
+
 /**
  * Standard LDAP attributes and object classes leveraged in this implementation
  * of user admin. Named {@link LdifName} in order not to collide with
  * {@link LdapName}.
+ * 
+ * @deprecated Use {@link LdapAttrs} and {@link LdapObjs} instead.
  */
+@Deprecated
 public enum LdifName {
        // Attributes
        dn, dc, cn, sn, uid, mail, displayName, objectClass, userPassword, givenName, description, member,
index 866c48c6b4c8d64d0abfe879e9482c8fd74770a9..d26ed148f0f861aa22ed0661f56339c4d63da381 100644 (file)
@@ -22,6 +22,8 @@ import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttribute;
 import javax.naming.ldap.LdapName;
 
+import org.argeo.naming.LdapAttrs;
+
 /** Directory user implementation */
 class LdifUser implements DirectoryUser {
        private final AbstractUserDirectory userAdmin;
@@ -73,7 +75,7 @@ class LdifUser implements DirectoryUser {
                        // TODO check other sources (like PKCS12)
                        char[] password = toChars(value);
                        byte[] hashedPassword = hash(password);
-                       return hasCredential(LdifName.userPassword.name(), hashedPassword);
+                       return hasCredential(LdapAttrs.userPassword.name(), hashedPassword);
                }
 
                Object storedValue = getCredentials().get(key);
@@ -250,14 +252,14 @@ class LdifUser implements DirectoryUser {
                                        return null;
                                Object value = attr.get();
                                if (value instanceof byte[]) {
-                                       if (key.equals(LdifName.userPassword.name()))
+                                       if (key.equals(LdapAttrs.userPassword.name()))
                                                // TODO other cases (certificates, images)
                                                return value;
                                        value = new String((byte[]) value, Charset.forName("UTF-8"));
                                }
                                if (attr.size() == 1)
                                        return value;
-                               if (!attr.getID().equals(LdifName.objectClass.name()))
+                               if (!attr.getID().equals(LdapAttrs.objectClass.name()))
                                        return value;
                                // special case for object class
                                NamingEnumeration<?> en = attr.getAll();
@@ -284,7 +286,7 @@ class LdifUser implements DirectoryUser {
                                // TODO persist to other sources (like PKCS12)
                                char[] password = toChars(value);
                                byte[] hashedPassword = hash(password);
-                               return put(LdifName.userPassword.name(), hashedPassword);
+                               return put(LdapAttrs.userPassword.name(), hashedPassword);
                        }
 
                        userAdmin.checkEdit();
index 86ef808d4e7133cb295db5272d04f135a707412d..4ebca4fcff3a0c3b95ee27d5a16f107173ed8b14 100644 (file)
@@ -1,7 +1,7 @@
 package org.argeo.osgi.useradmin;
 
-import static org.argeo.osgi.useradmin.LdifName.inetOrgPerson;
-import static org.argeo.osgi.useradmin.LdifName.objectClass;
+import static org.argeo.naming.LdapObjs.inetOrgPerson;
+import static org.argeo.naming.LdapAttrs.objectClass;
 
 import java.io.File;
 import java.io.FileOutputStream;
index 6c23acaac2438852ffacfc0321b7148178359f6c..1e08c18ac7aeb43a4c989bb035dc61eb1657c926 100644 (file)
  */
 package org.argeo.jcr;
 
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.Binary;
 import javax.jcr.Credentials;
 import javax.jcr.LoginException;
 import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.PropertyType;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
 
 /**
  * Wrapper around a JCR repository which allows to simplify configuration and
@@ -34,21 +45,35 @@ public abstract class JcrRepositoryWrapper implements Repository {
        // wrapped repository
        private Repository repository;
 
+       private Map<String, String> additionalDescriptors = new HashMap<>();
+
        private Boolean autocreateWorkspaces = false;
 
+       public JcrRepositoryWrapper(Repository repository) {
+               setRepository(repository);
+       }
+
        /**
-        * Empty constructor, {@link #init()} should be called after properties have
-        * been set
+        * Empty constructor
         */
        public JcrRepositoryWrapper() {
        }
 
-       /** Initializes */
-       public void init() {
-       }
+       // /** Initializes */
+       // public void init() {
+       // }
+       //
+       // /** Shutdown the repository */
+       // public void destroy() throws Exception {
+       // }
 
-       /** Shutdown the repository */
-       public void destroy() throws Exception {
+       protected void putDescriptor(String key, String value) {
+               if (Arrays.asList(getRepository().getDescriptorKeys()).contains(key))
+                       throw new IllegalArgumentException("Descriptor key " + key + " is already defined in wrapped repository");
+               if (value == null)
+                       additionalDescriptors.remove(key);
+               else
+                       additionalDescriptors.put(key, value);
        }
 
        /*
@@ -56,17 +81,22 @@ public abstract class JcrRepositoryWrapper implements Repository {
         */
 
        public String getDescriptor(String key) {
+               if (additionalDescriptors.containsKey(key))
+                       return additionalDescriptors.get(key);
                return getRepository().getDescriptor(key);
        }
 
        public String[] getDescriptorKeys() {
-               return getRepository().getDescriptorKeys();
+               if (additionalDescriptors.size() == 0)
+                       return getRepository().getDescriptorKeys();
+               List<String> keys = Arrays.asList(getRepository().getDescriptorKeys());
+               keys.addAll(additionalDescriptors.keySet());
+               return keys.toArray(new String[keys.size()]);
        }
 
        /** Central login method */
        public Session login(Credentials credentials, String workspaceName)
-                       throws LoginException, NoSuchWorkspaceException,
-                       RepositoryException {
+                       throws LoginException, NoSuchWorkspaceException, RepositoryException {
                Session session;
                try {
                        session = getRepository().login(credentials, workspaceName);
@@ -84,13 +114,11 @@ public abstract class JcrRepositoryWrapper implements Repository {
                return login(null, null);
        }
 
-       public Session login(Credentials credentials) throws LoginException,
-                       RepositoryException {
+       public Session login(Credentials credentials) throws LoginException, RepositoryException {
                return login(credentials, null);
        }
 
-       public Session login(String workspaceName) throws LoginException,
-                       NoSuchWorkspaceException, RepositoryException {
+       public Session login(String workspaceName) throws LoginException, NoSuchWorkspaceException, RepositoryException {
                return login(null, workspaceName);
        }
 
@@ -100,12 +128,12 @@ public abstract class JcrRepositoryWrapper implements Repository {
 
        /** Wraps access to the repository, making sure it is available. */
        protected synchronized Repository getRepository() {
-//             if (repository == null) {
-//                     throw new ArgeoJcrException("No repository initialized."
-//                                     + " Was the init() method called?"
-//                                     + " The destroy() method should also"
-//                                     + " be called on shutdown.");
-//             }
+               // if (repository == null) {
+               // throw new ArgeoJcrException("No repository initialized."
+               // + " Was the init() method called?"
+               // + " The destroy() method should also"
+               // + " be called on shutdown.");
+               // }
                return repository;
        }
 
@@ -113,8 +141,8 @@ public abstract class JcrRepositoryWrapper implements Repository {
         * Logs in to the default workspace, creates the required workspace, logs
         * out, logs in to the required workspace.
         */
-       protected Session createWorkspaceAndLogsIn(Credentials credentials,
-                       String workspaceName) throws RepositoryException {
+       protected Session createWorkspaceAndLogsIn(Credentials credentials, String workspaceName)
+                       throws RepositoryException {
                if (workspaceName == null)
                        throw new ArgeoJcrException("No workspace specified.");
                Session session = getRepository().login(credentials);
@@ -128,10 +156,14 @@ public abstract class JcrRepositoryWrapper implements Repository {
        }
 
        public boolean isSingleValueDescriptor(String key) {
+               if (additionalDescriptors.containsKey(key))
+                       return true;
                return getRepository().isSingleValueDescriptor(key);
        }
 
        public Value getDescriptorValue(String key) {
+               if (additionalDescriptors.containsKey(key))
+                       return new StrValue(additionalDescriptors.get(key));
                return getRepository().getDescriptorValue(key);
        }
 
@@ -147,4 +179,74 @@ public abstract class JcrRepositoryWrapper implements Repository {
                this.autocreateWorkspaces = autocreateWorkspaces;
        }
 
+       protected static class StrValue implements Value {
+               private final String str;
+
+               public StrValue(String str) {
+                       this.str = str;
+               }
+
+               @Override
+               public String getString() throws ValueFormatException, IllegalStateException, RepositoryException {
+                       return str;
+               }
+
+               @Override
+               public InputStream getStream() throws RepositoryException {
+                       throw new UnsupportedOperationException();
+               }
+
+               @Override
+               public Binary getBinary() throws RepositoryException {
+                       throw new UnsupportedOperationException();
+               }
+
+               @Override
+               public long getLong() throws ValueFormatException, RepositoryException {
+                       try {
+                               return Long.parseLong(str);
+                       } catch (NumberFormatException e) {
+                               throw new ValueFormatException("Cannot convert", e);
+                       }
+               }
+
+               @Override
+               public double getDouble() throws ValueFormatException, RepositoryException {
+                       try {
+                               return Double.parseDouble(str);
+                       } catch (NumberFormatException e) {
+                               throw new ValueFormatException("Cannot convert", e);
+                       }
+               }
+
+               @Override
+               public BigDecimal getDecimal() throws ValueFormatException, RepositoryException {
+                       try {
+                               return new BigDecimal(str);
+                       } catch (NumberFormatException e) {
+                               throw new ValueFormatException("Cannot convert", e);
+                       }
+               }
+
+               @Override
+               public Calendar getDate() throws ValueFormatException, RepositoryException {
+                       throw new UnsupportedOperationException();
+               }
+
+               @Override
+               public boolean getBoolean() throws ValueFormatException, RepositoryException {
+                       try {
+                               return Boolean.parseBoolean(str);
+                       } catch (NumberFormatException e) {
+                               throw new ValueFormatException("Cannot convert", e);
+                       }
+               }
+
+               @Override
+               public int getType() {
+                       return PropertyType.STRING;
+               }
+
+       }
+
 }
index 874057be8850cd92d9e58568237550925a021136..3ef32e1e979609077f227deb3a16cd4cf9f2adf3 100644 (file)
@@ -18,30 +18,39 @@ package org.argeo.node;
 /** JCR names in the http://www.argeo.org/argeo namespace */
 public interface ArgeoNames {
        public final static String ARGEO_NAMESPACE = "http://www.argeo.org/ns/argeo";
-       public final static String ARGEO = "argeo";
+//     public final static String ARGEO = "argeo";
 
        public final static String ARGEO_URI = "argeo:uri";
        public final static String ARGEO_USER_ID = "argeo:userID";
-       public final static String ARGEO_PREFERENCES = "argeo:preferences";
-       public final static String ARGEO_DATA_MODEL_VERSION = "argeo:dataModelVersion";
+//     public final static String ARGEO_PREFERENCES = "argeo:preferences";
+//     public final static String ARGEO_DATA_MODEL_VERSION = "argeo:dataModelVersion";
 
        public final static String ARGEO_REMOTE = "argeo:remote";
        public final static String ARGEO_PASSWORD = "argeo:password";
 //     public final static String ARGEO_REMOTE_ROLES = "argeo:remoteRoles";
 
        // user profile
-       public final static String ARGEO_PROFILE = "argeo:profile";
+//     public final static String ARGEO_PROFILE = "argeo:profile";
 
        // spring security
+       @Deprecated
        public final static String ARGEO_ENABLED = "argeo:enabled";
-       public final static String ARGEO_ACCOUNT_NON_EXPIRED = "argeo:accountNonExpired";
-       public final static String ARGEO_ACCOUNT_NON_LOCKED = "argeo:accountNonLocked";
-       public final static String ARGEO_CREDENTIALS_NON_EXPIRED = "argeo:credentialsNonExpired";
+//     public final static String ARGEO_ACCOUNT_NON_EXPIRED = "argeo:accountNonExpired";
+//     public final static String ARGEO_ACCOUNT_NON_LOCKED = "argeo:accountNonLocked";
+//     public final static String ARGEO_CREDENTIALS_NON_EXPIRED = "argeo:credentialsNonExpired";
 
        // personal details
+       /** @deprecated Use org.argeo.naming.LdapAttrs */
+       @Deprecated
        public final static String ARGEO_FIRST_NAME = "argeo:firstName";
+       /** @deprecated Use org.argeo.naming.LdapAttrs */
+       @Deprecated
        public final static String ARGEO_LAST_NAME = "argeo:lastName";
+       /** @deprecated Use org.argeo.naming.LdapAttrs */
+       @Deprecated
        public final static String ARGEO_PRIMARY_EMAIL = "argeo:primaryEmail";
+       /** @deprecated Use org.argeo.naming.LdapAttrs */
+       @Deprecated
        public final static String ARGEO_PRIMARY_ORGANIZATION = "argeo:primaryOrganization";
 
        // tabular
index 8158abe6b511fb416a343cfeeef0a65732f3aace..bdf9c3fc0056d531aaf50b9b0dcd70e142bc037b 100644 (file)
@@ -17,14 +17,14 @@ package org.argeo.node;
 
 /** JCR types in the http://www.argeo.org/argeo namespace */
 public interface ArgeoTypes {
-       public final static String ARGEO_LINK = "argeo:link";
-       public final static String ARGEO_USER_HOME = "argeo:userHome";
-       public final static String ARGEO_USER_PROFILE = "argeo:userProfile";
+//     public final static String ARGEO_LINK = "argeo:link";
+//     public final static String ARGEO_USER_HOME = "argeo:userHome";
+//     public final static String ARGEO_USER_PROFILE = "argeo:userProfile";
        public final static String ARGEO_REMOTE_REPOSITORY = "argeo:remoteRepository";
-       public final static String ARGEO_PREFERENCE_NODE = "argeo:preferenceNode";
+//     public final static String ARGEO_PREFERENCE_NODE = "argeo:preferenceNode";
 
        // data model
-       public final static String ARGEO_DATA_MODEL = "argeo:dataModel";
+//     public final static String ARGEO_DATA_MODEL = "argeo:dataModel";
        
        // tabular
        public final static String ARGEO_TABLE = "argeo:table";
index 2bb6d06ef950a43131d4926b19fefe6b7092a893..889296112aeaec568a23a8cee8409b1ddadb9717 100644 (file)
@@ -1,7 +1,5 @@
 package org.argeo.node;
 
-import javax.jcr.Repository;
-
 public interface NodeConstants {
        /*
         * PIDs
@@ -20,30 +18,33 @@ public interface NodeConstants {
        String NODE_USER_DIRECTORIES_FACTORY_PID = "org.argeo.node.userDirectories";
 
        /*
-        * DEPLOY
+        * DN ATTRIBUTES (RFC 4514)
         */
-       String DEPLOY_BASEDN = "ou=deploy,ou=node";
+       String CN = "cn";
+       String L = "l";
+       String ST = "st";
+       String O = "o";
+       String OU = "ou";
+       String C = "c";
+       String STREET = "street";
+       String DC = "dc";
+       String UID = "uid";
 
        /*
-        * FRAMEWORK PROPERTIES
+        * STANDARD ATTRIBUTES
         */
-       String NODE_INIT = "argeo.node.init";
-       String I18N_DEFAULT_LOCALE = "argeo.i18n.defaultLocale";
-       String I18N_LOCALES = "argeo.i18n.locales";
-       // Node Security
-       String ROLES_URI = "argeo.node.roles.uri";
-       /** URI to an LDIF file or LDAP server used as initialization or backend */
-       String USERADMIN_URIS = "argeo.node.useradmin.uris";
-       // Node
-       /** Properties configuring the node repository */
-       String NODE_REPO_PROP_PREFIX = "argeo.node.repo.";
+       String LABELED_URI = "labeledUri";
 
        /*
-        * STANDARD ATTRIBUTES
+        * COMMON NAMES
         */
-       String CN = "cn";
-       String OU = "ou";
-       String URI = "uri";
+       String NODE = "node";
+       String HOME = "home";
+
+       /*
+        * BASE DNs
+        */
+       String DEPLOY_BASEDN = "ou=deploy,ou=node";
 
        /*
         * STANDARD VALUES
@@ -69,22 +70,45 @@ public interface NodeConstants {
        String LOGIN_CONTEXT_DATA_ADMIN = "DATA_ADMIN";
        String LOGIN_CONTEXT_SINGLE_USER = "SINGLE_USER";
 
+       /*
+        * FRAMEWORK PROPERTIES
+        */
+       String NODE_INIT = "argeo.node.init";
+       String I18N_DEFAULT_LOCALE = "argeo.i18n.defaultLocale";
+       String I18N_LOCALES = "argeo.i18n.locales";
+       // Node Security
+       String ROLES_URI = "argeo.node.roles.uri";
+       /** URI to an LDIF file or LDAP server used as initialization or backend */
+       String USERADMIN_URIS = "argeo.node.useradmin.uris";
+       // Node
+       /** Properties configuring the node repository */
+       String NODE_REPO_PROP_PREFIX = "argeo.node.repo.";
+
        /*
         * LEGACY
         */
-       String ARGEO_BASE_PATH = "/argeo:system";
-       String PEOPLE_BASE_PATH = NodeConstants.ARGEO_BASE_PATH + "/argeo:people";
-       String DATA_MODELS_BASE_PATH = NodeConstants.ARGEO_BASE_PATH + "/argeo:dataModels";
-       String ALIAS_HOME = "home";
+       // @Deprecated
+       // String ARGEO_BASE_PATH = "/argeo:system";
+       // @Deprecated
+       // String PEOPLE_BASE_PATH = NodeConstants.ARGEO_BASE_PATH +
+       // "/argeo:people";
+       // @Deprecated
+       // String DATA_MODELS_BASE_PATH = NodeConstants.ARGEO_BASE_PATH +
+       // "/argeo:dataModels";
+       // @Deprecated
+       // String ALIAS_HOME = "home";
        // standard aliases
        /**
         * Reserved alias for the "node" {@link Repository}, that is, the default
         * JCR repository.
         */
-       String ALIAS_NODE = "node";
+       // @Deprecated
+       // String ALIAS_NODE = "node";
        /** Key for a JCR repository URI */
-       String JCR_REPOSITORY_URI = "argeo.jcr.repository.uri";
+//     @Deprecated
+//     String JCR_REPOSITORY_URI = "argeo.jcr.repository.uri";
        // parameters (typically for call to a RepositoryFactory)
        /** Key for a JCR repository alias */
-       String JCR_REPOSITORY_ALIAS = "argeo.jcr.repository.alias";
+       // @Deprecated
+       // String JCR_REPOSITORY_ALIAS = "argeo.jcr.repository.alias";
 }
diff --git a/org.argeo.node.api/src/org/argeo/node/NodeNames.java b/org.argeo.node.api/src/org/argeo/node/NodeNames.java
new file mode 100644 (file)
index 0000000..05b86ff
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.node;
+
+/** JCR types in the http://www.argeo.org/node namespace */
+public interface NodeNames {
+       String LDAP_UID = "ldap:"+NodeConstants.UID;
+       String LDAP_CN = "ldap:"+NodeConstants.CN;
+}
diff --git a/org.argeo.node.api/src/org/argeo/node/NodeTypes.java b/org.argeo.node.api/src/org/argeo/node/NodeTypes.java
new file mode 100644 (file)
index 0000000..bfb55e1
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.node;
+
+/** JCR types in the http://www.argeo.org/node namespace */
+public interface NodeTypes {
+       String NODE_USER_HOME = "node:userHome";
+       String NODE_GROUP_HOME = "node:groupHome";
+}
index e1fb21adbf8d30fd69f1d0ae0556e1d39a4c62ca..b9281043d0efbe2e0f079ebc7be01fe4e994b1ba 100644 (file)
@@ -39,16 +39,14 @@ public class NodeUtils {
         * {@link NodeConstants#JCR_REPOSITORY_ALIAS} in order to simplify it and
         * protect against future API changes.
         */
-       public static Repository getRepositoryByAlias(
-                       RepositoryFactory repositoryFactory, String alias) {
+       public static Repository getRepositoryByAlias(RepositoryFactory repositoryFactory, String alias) {
                try {
                        Map<String, String> parameters = new HashMap<String, String>();
-                       parameters.put(NodeConstants.JCR_REPOSITORY_ALIAS, alias);
+                       parameters.put(NodeConstants.CN, alias);
                        return repositoryFactory.getRepository(parameters);
                } catch (RepositoryException e) {
-                       throw new RuntimeException(
-                                       "Unexpected exception when trying to retrieve repository with alias "
-                                                       + alias, e);
+                       throw new RuntimeException("Unexpected exception when trying to retrieve repository with alias " + alias,
+                                       e);
                }
        }
 
@@ -57,8 +55,7 @@ public class NodeUtils {
         * {@link NodeConstants#JCR_REPOSITORY_URI} in order to simplify it and
         * protect against future API changes.
         */
-       public static Repository getRepositoryByUri(
-                       RepositoryFactory repositoryFactory, String uri) {
+       public static Repository getRepositoryByUri(RepositoryFactory repositoryFactory, String uri) {
                return getRepositoryByUri(repositoryFactory, uri, null);
        }
 
@@ -67,18 +64,15 @@ public class NodeUtils {
         * {@link NodeConstants#JCR_REPOSITORY_URI} in order to simplify it and
         * protect against future API changes.
         */
-       public static Repository getRepositoryByUri(
-                       RepositoryFactory repositoryFactory, String uri, String alias) {
+       public static Repository getRepositoryByUri(RepositoryFactory repositoryFactory, String uri, String alias) {
                try {
                        Map<String, String> parameters = new HashMap<String, String>();
-                       parameters.put(NodeConstants.JCR_REPOSITORY_URI, uri);
+                       parameters.put(NodeConstants.LABELED_URI, uri);
                        if (alias != null)
-                               parameters.put(NodeConstants.JCR_REPOSITORY_ALIAS, alias);
+                               parameters.put(NodeConstants.CN, alias);
                        return repositoryFactory.getRepository(parameters);
                } catch (RepositoryException e) {
-                       throw new RuntimeException(
-                                       "Unexpected exception when trying to retrieve repository with uri "
-                                                       + uri, e);
+                       throw new RuntimeException("Unexpected exception when trying to retrieve repository with uri " + uri, e);
                }
        }
 
@@ -97,27 +91,42 @@ public class NodeUtils {
         */
        public static Node getUserHome(Session session, String username) {
                try {
-                       // String homePath = UserJcrUtils.getUserHomePath(username);
-                       // return session.itemExists(homePath) ? session.getNode(homePath)
-                       // : null;
-                       // kept for example of QOM queries
-                       QueryObjectModelFactory qomf = session.getWorkspace()
-                                       .getQueryManager().getQOMFactory();
-                       Selector userHomeSel = qomf.selector(ArgeoTypes.ARGEO_USER_HOME,
-                                       "userHome");
-                       DynamicOperand userIdDop = qomf.propertyValue(
-                                       userHomeSel.getSelectorName(), ArgeoNames.ARGEO_USER_ID);
-                       StaticOperand userIdSop = qomf.literal(session.getValueFactory()
-                                       .createValue(username));
-                       Constraint constraint = qomf.comparison(userIdDop,
-                                       QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, userIdSop);
-                       Query query = qomf.createQuery(userHomeSel, constraint, null, null);
+                       QueryObjectModelFactory qomf = session.getWorkspace().getQueryManager().getQOMFactory();
+                       Selector sel = qomf.selector(NodeTypes.NODE_USER_HOME, "sel");
+                       DynamicOperand dop = qomf.propertyValue(sel.getSelectorName(), NodeNames.LDAP_UID);
+                       StaticOperand sop = qomf.literal(session.getValueFactory().createValue(username));
+                       Constraint constraint = qomf.comparison(dop, QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, sop);
+                       Query query = qomf.createQuery(sel, constraint, null, null);
                        return querySingleNode(query);
                } catch (RepositoryException e) {
                        throw new RuntimeException("Cannot find home for user " + username, e);
                }
        }
 
+       /**
+        * Returns the home node of the user or null if none was found.
+        * 
+        * @param session
+        *            the session to use in order to perform the search, this can be
+        *            a session with a different user ID than the one searched,
+        *            typically when a system or admin session is used.
+        * @param cn
+        *            the username of the user
+        */
+       public static Node getGroupHome(Session session, String cn) {
+               try {
+                       QueryObjectModelFactory qomf = session.getWorkspace().getQueryManager().getQOMFactory();
+                       Selector sel = qomf.selector(NodeTypes.NODE_GROUP_HOME, "sel");
+                       DynamicOperand dop = qomf.propertyValue(sel.getSelectorName(), NodeNames.LDAP_CN);
+                       StaticOperand sop = qomf.literal(session.getValueFactory().createValue(cn));
+                       Constraint constraint = qomf.comparison(dop, QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, sop);
+                       Query query = qomf.createQuery(sel, constraint, null, null);
+                       return querySingleNode(query);
+               } catch (RepositoryException e) {
+                       throw new RuntimeException("Cannot find home for user " + cn, e);
+               }
+       }
+
        /**
         * Queries one single node.
         * 
@@ -150,24 +159,24 @@ public class NodeUtils {
                return getUserHome(session, userID);
        }
 
-       public static Node getUserProfile(Session session, String username) {
-               try {
-                       QueryObjectModelFactory qomf = session.getWorkspace()
-                                       .getQueryManager().getQOMFactory();
-                       Selector userHomeSel = qomf.selector(ArgeoTypes.ARGEO_USER_PROFILE,
-                                       "userProfile");
-                       DynamicOperand userIdDop = qomf.propertyValue(
-                                       userHomeSel.getSelectorName(), ArgeoNames.ARGEO_USER_ID);
-                       StaticOperand userIdSop = qomf.literal(session.getValueFactory()
-                                       .createValue(username));
-                       Constraint constraint = qomf.comparison(userIdDop,
-                                       QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, userIdSop);
-                       Query query = qomf.createQuery(userHomeSel, constraint, null, null);
-                       return querySingleNode(query);
-               } catch (RepositoryException e) {
-                       throw new RuntimeException(
-                                       "Cannot find profile for user " + username, e);
-               }
-       }
-
+       // public static Node getUserProfile(Session session, String username) {
+       // try {
+       // QueryObjectModelFactory qomf = session.getWorkspace()
+       // .getQueryManager().getQOMFactory();
+       // Selector userHomeSel = qomf.selector(ArgeoTypes.ARGEO_USER_PROFILE,
+       // "userProfile");
+       // DynamicOperand userIdDop = qomf.propertyValue(
+       // userHomeSel.getSelectorName(), ArgeoNames.ARGEO_USER_ID);
+       // StaticOperand userIdSop = qomf.literal(session.getValueFactory()
+       // .createValue(username));
+       // Constraint constraint = qomf.comparison(userIdDop,
+       // QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, userIdSop);
+       // Query query = qomf.createQuery(userHomeSel, constraint, null, null);
+       // return querySingleNode(query);
+       // } catch (RepositoryException e) {
+       // throw new RuntimeException(
+       // "Cannot find profile for user " + username, e);
+       // }
+       // }
+       //
 }
index fbfea9dd9d0a9a7811d070b544aec08d3604c5b3..8ac7c91f474585bed6b6d19fbe5b01dd942807a0 100644 (file)
@@ -1,42 +1,64 @@
+<ldap = 'http://www.argeo.org/ns/ldap'>
+<node = 'http://www.argeo.org/ns/node'>
 <argeo = 'http://www.argeo.org/ns/argeo'>
 
-// GENERIC TYPES NOT AVAILABLE IN JCR
-[argeo:link] > mix:created, mix:lastModified
+// DN (see https://tools.ietf.org/html/rfc4514)
+<cn = 'http://www.argeo.org/ns/rfc4514/cn'>
+<l = 'http://www.argeo.org/ns/rfc4514/l'>
+<st = 'http://www.argeo.org/ns/rfc4514/st'>
+<o = 'http://www.argeo.org/ns/rfc4514/o'>
+<ou = 'http://www.argeo.org/ns/rfc4514/ou'>
+<c = 'http://www.argeo.org/ns/rfc4514/c'>
+<street = 'http://www.argeo.org/ns/rfc4514/street'>
+<dc = 'http://www.argeo.org/ns/rfc4514/dc'>
+<uid = 'http://www.argeo.org/ns/rfc4514/uid'>
+
+
+[node:userHome]
 mixin
+- ldap:uid (STRING) m
+
+[node:groupHome]
+mixin
+- ldap:cn (STRING) m
+
+// GENERIC TYPES NOT AVAILABLE IN JCR
+//[argeo:link] > mix:created, mix:lastModified
+//mixin
 // URI(s)
-- argeo:uri (STRING) m
+//- argeo:uri (STRING) m
 
-[argeo:references] > nt:unstructured
-- * (REFERENCE) *
+//[argeo:references] > nt:unstructured
+//- * (REFERENCE) *
 
 // DATA MODEL
-[argeo:dataModel] > mix:created, mix:lastModified, mix:versionable
-mixin
-- argeo:uri (STRING) m
-- argeo:dataModelVersion (STRING) m
+//[argeo:dataModel] > mix:created, mix:lastModified, mix:versionable
+//mixin
+//- argeo:uri (STRING) m
+//- argeo:dataModelVersion (STRING) m
 
 // USER NODES
 // user should be lower case, between 3 and 15 characters long
-[argeo:userHome] > mix:created, mix:lastModified
-mixin
-- argeo:userID (STRING) m
-- argeo:remoteRoles (STRING) *
+//[argeo:userHome] > mix:created, mix:lastModified
+//mixin
+//- argeo:userID (STRING) m
+//- argeo:remoteRoles (STRING) *
 // deprecated. for backward compatibility:
-+ argeo:profile (argeo:userProfile)
-+ argeo:keyring (argeo:pbeSpec)
-+ argeo:preferences (argeo:preferenceNode)
+//+ argeo:profile (argeo:userProfile)
+//+ argeo:keyring (argeo:pbeSpec)
+//+ argeo:preferences (argeo:preferenceNode)
 
-[argeo:userProfile] > mix:created, mix:lastModified, mix:title, mix:versionable
-mixin
-- argeo:userID (STRING) m
-- argeo:enabled (BOOLEAN)
-- argeo:accountNonExpired (BOOLEAN)
-- argeo:accountNonLocked (BOOLEAN)
-- argeo:credentialsNonExpired (BOOLEAN)
+//[argeo:userProfile] > mix:created, mix:lastModified, mix:title, mix:versionable
+//mixin
+//- argeo:userID (STRING) m
+//- argeo:enabled (BOOLEAN)
+//- argeo:accountNonExpired (BOOLEAN)
+//- argeo:accountNonLocked (BOOLEAN)
+//- argeo:credentialsNonExpired (BOOLEAN)
 
-[argeo:preferenceNode] > mix:lastModified, mix:versionable
-mixin
-+ * (argeo:preferenceNode) * version
+//[argeo:preferenceNode] > mix:lastModified, mix:versionable
+//mixin
+//+ * (argeo:preferenceNode) * version
 
 [argeo:remoteRepository] > nt:unstructured
 - argeo:uri (STRING)