X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.rpmfactory%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Frpmfactory%2Fcore%2FRpmProxyServiceImpl.java;h=82d9e553b9613197fdead0ec30e00f2540f68f45;hb=e5b65f8f0f102ec5336623eea0c80bcbc48a298e;hp=d5b0bc78b4ba0083256518df9c62957b2c017720;hpb=b301144d5f9dc598da7d75bd1eb515f02f32f5ca;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmProxyServiceImpl.java b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmProxyServiceImpl.java index d5b0bc78b..82d9e553b 100644 --- a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmProxyServiceImpl.java +++ b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmProxyServiceImpl.java @@ -20,15 +20,21 @@ import java.util.Iterator; import java.util.Set; import javax.jcr.Node; +import javax.jcr.RepositoryException; import javax.jcr.Session; +import javax.jcr.nodetype.NodeType; +import javax.jcr.security.AccessControlException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.jcr.ArgeoNames; import org.argeo.jcr.JcrUtils; import org.argeo.jcr.proxy.AbstractUrlProxy; +import org.argeo.slc.SlcConstants; import org.argeo.slc.SlcException; import org.argeo.slc.jcr.SlcNames; +import org.argeo.slc.jcr.SlcTypes; +import org.argeo.slc.repo.RepoConstants; import org.argeo.slc.rpmfactory.RpmProxyService; import org.argeo.slc.rpmfactory.RpmRepository; @@ -39,6 +45,21 @@ public class RpmProxyServiceImpl extends AbstractUrlProxy implements private Set defaultRepositories = new HashSet(); + @Override + protected void beforeInitSessionSave(Session session) + throws RepositoryException { + JcrUtils.addPrivilege(session, "/", "anonymous", "jcr:read"); + try { + JcrUtils.addPrivilege(session, "/", SlcConstants.ROLE_SLC, + "jcr:all"); + } catch (AccessControlException e) { + if (log.isTraceEnabled()) + log.trace("Cannot give jcr:all privileges to ROLE_SLC"); + } + + JcrUtils.mkdirsSafe(session, RepoConstants.PROXIED_REPOSITORIES); + } + /** * Retrieve and add this file to the repository */ @@ -46,7 +67,8 @@ public class RpmProxyServiceImpl extends AbstractUrlProxy implements protected Node retrieve(Session session, String path) { StringBuilder relativePathBuilder = new StringBuilder(); String repoId = extractRepoId(path, relativePathBuilder); - String relativePath = relativePathBuilder.toString(); + // remove starting '/' + String relativePath = relativePathBuilder.toString().substring(1); RpmRepository sourceRepo = null; for (Iterator reposIt = defaultRepositories.iterator(); reposIt @@ -62,21 +84,11 @@ public class RpmProxyServiceImpl extends AbstractUrlProxy implements throw new SlcException("No RPM repository found for " + path); try { - // if (session.hasPendingChanges()) - // throw new SlcException("Session has pending changed"); String baseUrl = sourceRepo.getUrl(); String remoteUrl = baseUrl + relativePath; Node node = proxyUrl(session, remoteUrl, path); if (node != null) { - // node.addMixin(SlcTypes.SLC_KNOWN_ORIGIN); - // Node origin; - // if (!node.hasNode(SLC_ORIGIN)) - // origin = node.addNode(SLC_ORIGIN, SlcTypes.SLC_PROXIED); - // else - // origin = node.getNode(SLC_ORIGIN); - // // origin.setProperty(SLC_PROXY, sourceRepo.getId()); - // JcrUtils.urlToAddressProperties(origin, remoteUrl); - + registerSource(sourceRepo, node, remoteUrl); if (log.isDebugEnabled()) log.debug("Imported " + remoteUrl + " to " + node); return node; @@ -88,6 +100,36 @@ public class RpmProxyServiceImpl extends AbstractUrlProxy implements throw new SlcException("No proxy found for " + path); } + protected void registerSource(RpmRepository sourceRepo, Node node, + String remoteUrl) throws RepositoryException { + node.addMixin(SlcTypes.SLC_KNOWN_ORIGIN); + Node origin; + if (!node.hasNode(SLC_ORIGIN)) + origin = node.addNode(SLC_ORIGIN, SlcTypes.SLC_PROXIED); + else + origin = node.getNode(SLC_ORIGIN); + + // proxied repository + Node proxiedRepository; + String proxiedRepositoryPath = RepoConstants.PROXIED_REPOSITORIES + '/' + + sourceRepo.getId(); + Session session = node.getSession(); + if (session.itemExists(proxiedRepositoryPath)) { + proxiedRepository = session.getNode(proxiedRepositoryPath); + } else { + proxiedRepository = session.getNode( + RepoConstants.PROXIED_REPOSITORIES).addNode( + sourceRepo.getId()); + proxiedRepository.addMixin(NodeType.MIX_REFERENCEABLE); + JcrUtils.urlToAddressProperties(proxiedRepository, + sourceRepo.getUrl()); + proxiedRepository.setProperty(SLC_URL, sourceRepo.getUrl()); + } + + origin.setProperty(SLC_PROXY, proxiedRepository); + JcrUtils.urlToAddressProperties(origin, remoteUrl); + } + /** Returns the first token of the path */ protected String extractRepoId(String path, StringBuilder relativePath) { StringBuilder workspace = new StringBuilder(); @@ -104,8 +146,8 @@ public class RpmProxyServiceImpl extends AbstractUrlProxy implements @Override protected Boolean shouldUpdate(Session clientSession, String nodePath) { - if (nodePath.contains("/repodata/")) - return true; + // if (nodePath.contains("/repodata/")) + // return true; return super.shouldUpdate(clientSession, nodePath); }