if (homeNode != null)
homeNode.dispose();
homeNode = new SingleJcrNodeElem(null, userHome,
- userSession.getUserID(), NodeConstants.ALIAS_NODE);
+ userSession.getUserID(), NodeConstants.NODE);
}
}
if (repositoryRegister != null) {
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;
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;
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();
+++ /dev/null
-/*
- * 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;
- }
-}
@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();
+++ /dev/null
-/*
- * 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;
- }
-
-}
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();
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;
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);
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();
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
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();
// 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);
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);
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;
}
@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");
}
@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);
@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);
// 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);
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;
}
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;
/**
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);
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);
}
}
- private Node syncJcr(Session session, String username) {
+ private void syncJcr(Session session, String username) {
try {
Node userHome = NodeUtils.getUserHome(session, username);
if (userHome == null) {
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);
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) {
// }
if (session.hasPendingChanges())
session.save();
- return userProfile;
+// return userProfile;
} catch (RepositoryException e) {
JcrUtils.discardQuietly(session);
throw new CmsException("Cannot sync node security model for "
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 {
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() {
@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();
}
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)
// 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();
}
- 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);
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);
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() {
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;
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;
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;
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;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.argeo.naming.LdapAttrs;
import org.osgi.framework.Filter;
/**
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
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;
} 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)
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,
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;
// 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);
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();
// 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();
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;
*/
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
// 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);
}
/*
*/
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);
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);
}
/** 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;
}
* 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);
}
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);
}
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;
+ }
+
+ }
+
}
/** 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
/** 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";
package org.argeo.node;
-import javax.jcr.Repository;
-
public interface NodeConstants {
/*
* PIDs
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
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";
}
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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";
+}
* {@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);
}
}
* {@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);
}
* {@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);
}
}
*/
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.
*
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);
+ // }
+ // }
+ //
}
+<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)