import java.util.Locale;
import java.util.Map;
import java.util.NavigableMap;
-import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import javax.xml.validation.Schema;
import org.argeo.api.acr.Content;
import org.argeo.api.acr.ContentSession;
// TODO synchronize ?
private NavigableMap<String, String> prefixes = new TreeMap<>();
- private Schema schema;
+// private Schema schema;
private CmsContentSession systemSession;
});
Document document;
- if (Files.exists(path)) {
+ if (path != null && Files.exists(path)) {
InputSource inputSource = new InputSource(path.toAbsolutePath().toUri().toString());
inputSource.setEncoding(StandardCharsets.UTF_8.name());
// TODO public id as well?
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(document);
- try (Writer writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
- StreamResult result = new StreamResult(writer);
- transformer.transform(source, result);
- }
+ if (path != null)
+ try (Writer writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
+ StreamResult result = new StreamResult(writer);
+ transformer.transform(source, result);
+ }
}
DomContentProvider contentProvider = new DomContentProvider(document);
@Override
public Content get(String path) {
Map.Entry<String, ContentProvider> entry = partitions.floorEntry(path);
+ if (entry == null)
+ throw new IllegalArgumentException("No entry provider found for " + path);
String mountPath = entry.getKey();
ContentProvider provider = entry.getValue();
String relativePath = path.substring(mountPath.length());
throws IOException {
if (!prefixes.containsKey(prefix)) {
ByteBuffer bb = ByteBuffer.wrap(namespace.getBytes(StandardCharsets.UTF_8));
- int size = udfav.write(XMLNS_ + prefix, bb);
+ udfav.write(XMLNS_ + prefix, bb);
prefixes.put(prefix, namespace);
}
}
+ public void registerPrefix(String prefix, String namespace) {
+ if (prefixes.containsKey(prefix))
+ prefixes.remove(prefix);
+ try {
+ UserDefinedFileAttributeView udfav = Files.getFileAttributeView(rootPath,
+ UserDefinedFileAttributeView.class);
+ addDefaultNamespace(udfav, prefix, namespace);
+ } catch (IOException e) {
+ throw new RuntimeException("Cannot register namespace " + prefix + " " + namespace + " on " + rootPath, e);
+ }
+
+ }
+
boolean isRoot(Path path) {
try {
return isRoot && Files.isSameFile(rootPath, path);
if (namespaceURI == null) {
return toQName(node, node.getLocalName());
} else {
- String contextPrefix = session.getPrefix(namespaceURI);
+ String contextPrefix = provider.getPrefix(namespaceURI);
if (contextPrefix == null)
throw new IllegalStateException("Namespace " + namespaceURI + " is unbound");
- return toQName(node, namespaceURI, node.getLocalName(), session);
+ return toQName(node, namespaceURI, node.getLocalName(), provider);
}
} else {
String namespaceURI = node.getNamespaceURI();
if (namespaceURI == null)
namespaceURI = node.getOwnerDocument().lookupNamespaceURI(prefix);
if (namespaceURI == null) {
- namespaceURI = session.getNamespaceURI(prefix);
+ namespaceURI = provider.getNamespaceURI(prefix);
if (XMLConstants.NULL_NS_URI.equals(namespaceURI))
throw new IllegalStateException("Prefix " + prefix + " is unbound");
// TODO bind the prefix in the document?
}
- return toQName(node, namespaceURI, node.getLocalName(), session);
+ return toQName(node, namespaceURI, node.getLocalName(), provider);
}
}
protected QName toQName(Node source, String namespaceURI, String localName, NamespaceContext namespaceContext) {
- return new ContentName(namespaceURI, localName, session);
+ return new ContentName(namespaceURI, localName, namespaceContext);
}
protected QName toQName(Node source, String localName) {
return result;
}
+ @SuppressWarnings("unchecked")
@Override
public <A> Optional<A> get(QName key, Class<A> clss) {
String namespaceUriOrNull = XMLConstants.NULL_NS_URI.equals(key.getNamespaceURI()) ? null
import java.util.List;
import javax.xml.namespace.NamespaceContext;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import org.argeo.api.acr.Content;
import org.argeo.api.acr.ContentNotFoundException;
-import org.argeo.api.acr.CrName;
+import org.argeo.api.acr.NamespaceUtils;
import org.argeo.api.acr.spi.ContentProvider;
import org.argeo.api.acr.spi.ProvidedSession;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
public class DomContentProvider implements ContentProvider, NamespaceContext {
private Document document;
@Override
protected XPath initialValue() {
// TODO set the document as namespace context?
- XPath res= xPathFactory.newXPath();
+ XPath res = xPathFactory.newXPath();
res.setNamespaceContext(DomContentProvider.this);
return res;
}
*/
@Override
public String getNamespaceURI(String prefix) {
+ String namespaceURI = NamespaceUtils.getStandardNamespaceURI(prefix);
+ if (namespaceURI != null)
+ return namespaceURI;
return document.lookupNamespaceURI(prefix);
}
@Override
public String getPrefix(String namespaceURI) {
+ String prefix = NamespaceUtils.getStandardPrefix(namespaceURI);
+ if (prefix != null)
+ return prefix;
return document.lookupPrefix(namespaceURI);
}
return Collections.unmodifiableList(res).iterator();
}
-
}
package org.argeo.cms.auth;
import java.security.Principal;
-import java.util.Collection;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
import javax.security.auth.Subject;
import javax.security.auth.x500.X500Principal;
-import org.argeo.api.cms.CmsSession;
-import org.argeo.api.cms.CmsSessionId;
-import org.argeo.api.cms.DataAdminPrincipal;
import org.argeo.api.cms.AnonymousPrincipal;
import org.argeo.api.cms.CmsConstants;
+import org.argeo.api.cms.CmsSessionId;
+import org.argeo.api.cms.DataAdminPrincipal;
import org.argeo.cms.internal.auth.CmsSessionImpl;
import org.argeo.cms.internal.auth.ImpliedByPrincipal;
import org.argeo.cms.internal.http.WebCmsSessionImpl;
import org.argeo.cms.internal.runtime.CmsContextImpl;
import org.argeo.cms.security.NodeSecurityUtils;
import org.argeo.osgi.useradmin.AuthenticatingUser;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpContext;
import org.osgi.service.useradmin.Authorization;
final static String SHARED_STATE_REMOTE_ADDR = "org.argeo.cms.auth.remote.addr";
final static String SHARED_STATE_REMOTE_PORT = "org.argeo.cms.auth.remote.port";
+ final static String SINGLE_USER_LOCAL_ID = "single-user";
+
static void addAuthorization(Subject subject, Authorization authorization) {
assert subject != null;
checkSubjectEmpty(subject);
"Subject already logged with session " + storedSessionId + " (not " + nodeSessionId + ")");
}
} else {
- CmsSessionImpl cmsSession = new CmsSessionImpl(subject, authorization, locale, "desktop");
- CmsContextImpl.getCmsContext().registerCmsSession(cmsSession);
+ CmsSessionImpl cmsSession = CmsContextImpl.getCmsContext().getCmsSessionByLocalId(SINGLE_USER_LOCAL_ID);
+ if (cmsSession == null) {
+ cmsSession = new CmsSessionImpl(subject, authorization, locale, SINGLE_USER_LOCAL_ID);
+ CmsContextImpl.getCmsContext().registerCmsSession(cmsSession);
+ }
CmsSessionId nodeSessionId = new CmsSessionId(cmsSession.getUuid());
subject.getPrivateCredentials().add(nodeSessionId);
}
cmsSessionsByLocalId.remove(cmsSession.getLocalId());
}
+ /**
+ * The {@link CmsSession} related to this UUID, or <code>null</null> if not
+ * registered.
+ */
public synchronized CmsSessionImpl getCmsSessionByUuid(UUID uuid) {
return cmsSessionsByUuid.get(uuid);
}
+ /**
+ * The {@link CmsSession} related to this local id, or <code>null</null> if not
+ * registered.
+ */
public synchronized CmsSessionImpl getCmsSessionByLocalId(String localId) {
return cmsSessionsByLocalId.get(localId);
}