Search in sources :

Example 21 with Generation

use of org.eclipse.osgi.storage.BundleInfo.Generation in project rt.equinox.framework by eclipse.

the class EquinoxBundle method hasPermission.

@Override
public boolean hasPermission(Object permission) {
    Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
    ProtectionDomain domain = current.getDomain();
    if (domain != null) {
        if (permission instanceof Permission) {
            SecurityManager sm = System.getSecurityManager();
            if (sm instanceof EquinoxSecurityManager) {
                /*
					 * If the FrameworkSecurityManager is active, we need to do checks the "right" way.
					 * We can exploit our knowledge that the security context of FrameworkSecurityManager
					 * is an AccessControlContext to invoke it properly with the ProtectionDomain.
					 */
                AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] { domain });
                try {
                    sm.checkPermission((Permission) permission, acc);
                    return true;
                } catch (Exception e) {
                    return false;
                }
            }
            return domain.implies((Permission) permission);
        }
        return false;
    }
    return true;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) EquinoxSecurityManager(org.eclipse.osgi.internal.permadmin.EquinoxSecurityManager) AccessControlContext(java.security.AccessControlContext) Permission(java.security.Permission) AdminPermission(org.osgi.framework.AdminPermission) AdaptPermission(org.osgi.framework.AdaptPermission) EquinoxSecurityManager(org.eclipse.osgi.internal.permadmin.EquinoxSecurityManager) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException)

Example 22 with Generation

use of org.eclipse.osgi.storage.BundleInfo.Generation in project rt.equinox.framework by eclipse.

the class EquinoxBundle method adapt0.

@SuppressWarnings("unchecked")
private <A> A adapt0(Class<A> adapterType) {
    if (AccessControlContext.class.equals(adapterType)) {
        Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
        ProtectionDomain domain = current.getDomain();
        return (A) (domain == null ? null : new AccessControlContext(new ProtectionDomain[] { domain }));
    }
    if (BundleContext.class.equals(adapterType)) {
        try {
            return (A) getBundleContext();
        } catch (SecurityException e) {
            return null;
        }
    }
    if (BundleRevision.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        return (A) module.getCurrentRevision();
    }
    if (BundleRevisions.class.equals(adapterType)) {
        return (A) module.getRevisions();
    }
    if (BundleStartLevel.class.equals(adapterType)) {
        return (A) module;
    }
    if (BundleWiring.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        ModuleRevision revision = module.getCurrentRevision();
        if (revision == null) {
            return null;
        }
        return (A) revision.getWiring();
    }
    if (BundleDTO.class.equals(adapterType)) {
        // Unfortunately we need to lock here to make sure the BSN and version
        // are consistent in case of updates
        readLock();
        try {
            return (A) DTOBuilder.newBundleDTO(this);
        } finally {
            readUnlock();
        }
    }
    if (BundleStartLevelDTO.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        return (A) DTOBuilder.newBundleStartLevelDTO(this, module);
    }
    if (BundleRevisionDTO.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        return (A) DTOBuilder.newBundleRevisionDTO(module.getCurrentRevision());
    }
    if (BundleRevisionDTO[].class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        // proper locking for us.
        return (A) DTOBuilder.newArrayBundleRevisionDTO(module.getRevisions());
    }
    if (BundleWiringDTO.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        readLock();
        try {
            return (A) DTOBuilder.newBundleWiringDTO(module.getCurrentRevision());
        } finally {
            readUnlock();
        }
    }
    if (BundleWiringDTO[].class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        readLock();
        try {
            return (A) DTOBuilder.newArrayBundleWiringDTO(module.getRevisions());
        } finally {
            readUnlock();
        }
    }
    if (ServiceReferenceDTO[].class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        BundleContextImpl current = getBundleContextImpl();
        ServiceReference<?>[] references = (current == null) ? null : equinoxContainer.getServiceRegistry().getRegisteredServices(current);
        return (A) DTOBuilder.newArrayServiceReferenceDTO(references);
    }
    if (getBundleId() == 0) {
        if (Framework.class.equals(adapterType)) {
            return (A) this;
        }
        if (FrameworkStartLevel.class.equals(adapterType)) {
            return (A) module.getContainer().getFrameworkStartLevel();
        }
        if (FrameworkWiring.class.equals(adapterType)) {
            return (A) module.getContainer().getFrameworkWiring();
        }
        if (FrameworkDTO.class.equals(adapterType)) {
            BundleContextImpl current = getBundleContextImpl();
            Map<String, String> configuration = equinoxContainer.getConfiguration().getConfiguration();
            readLock();
            try {
                return (A) DTOBuilder.newFrameworkDTO(current, configuration);
            } finally {
                readUnlock();
            }
        }
        if (FrameworkStartLevelDTO.class.equals(adapterType)) {
            return (A) DTOBuilder.newFrameworkStartLevelDTO(module.getContainer().getFrameworkStartLevel());
        }
        if (FrameworkWiringDTO.class.equals(adapterType)) {
            readLock();
            try {
                Set<BundleWiring> allWirings = new HashSet<>();
                for (Module m : module.getContainer().getModules()) {
                    for (BundleRevision revision : m.getRevisions().getRevisions()) {
                        BundleWiring wiring = revision.getWiring();
                        if (wiring != null) {
                            allWirings.add(wiring);
                        }
                    }
                }
                for (ModuleRevision revision : module.getContainer().getRemovalPending()) {
                    BundleWiring wiring = revision.getWiring();
                    if (wiring != null) {
                        allWirings.add(wiring);
                    }
                }
                return (A) DTOBuilder.newFrameworkWiringDTO(allWirings);
            } finally {
                readUnlock();
            }
        }
    }
    // Equinox extras
    if (Module.class.equals(adapterType)) {
        return (A) module;
    }
    if (ProtectionDomain.class.equals(adapterType)) {
        Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
        return (A) current.getDomain();
    }
    return null;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) BundleRevisionDTO(org.osgi.framework.wiring.dto.BundleRevisionDTO) BundleWiring(org.osgi.framework.wiring.BundleWiring) ServiceReference(org.osgi.framework.ServiceReference) ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) AccessControlContext(java.security.AccessControlContext) BundleWiringDTO(org.osgi.framework.wiring.dto.BundleWiringDTO) BundleRevision(org.osgi.framework.wiring.BundleRevision) SystemModule(org.eclipse.osgi.container.SystemModule) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) HashSet(java.util.HashSet)

Example 23 with Generation

use of org.eclipse.osgi.storage.BundleInfo.Generation in project rt.equinox.framework by eclipse.

the class EquinoxBundle method getEntry.

@Override
public URL getEntry(String path) {
    try {
        equinoxContainer.checkAdminPermission(this, AdminPermission.RESOURCE);
    } catch (SecurityException e) {
        return null;
    }
    checkValid();
    Generation current = (Generation) getModule().getCurrentRevision().getRevisionInfo();
    return current.getEntry(path);
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation)

Example 24 with Generation

use of org.eclipse.osgi.storage.BundleInfo.Generation in project rt.equinox.framework by eclipse.

the class Storage method saveGenerations.

private void saveGenerations(DataOutputStream out) throws IOException {
    List<Module> modules = moduleContainer.getModules();
    List<Generation> generations = new ArrayList<>();
    for (Module module : modules) {
        ModuleRevision revision = module.getCurrentRevision();
        if (revision != null) {
            Generation generation = (Generation) revision.getRevisionInfo();
            if (generation != null) {
                generations.add(generation);
            }
        }
    }
    out.writeInt(VERSION);
    out.writeUTF(runtimeVersion.toString());
    out.writeInt(cachedHeaderKeys.size());
    for (String headerKey : cachedHeaderKeys) {
        out.writeUTF(headerKey);
    }
    out.writeInt(generations.size());
    for (Generation generation : generations) {
        BundleInfo bundleInfo = generation.getBundleInfo();
        out.writeLong(bundleInfo.getBundleId());
        out.writeUTF(bundleInfo.getLocation());
        out.writeLong(bundleInfo.getNextGenerationId());
        out.writeLong(generation.getGenerationId());
        out.writeBoolean(generation.isDirectory());
        out.writeBoolean(generation.isReference());
        out.writeBoolean(generation.hasPackageInfo());
        if (bundleInfo.getBundleId() == 0) {
            // just write empty string for system bundle content in this case
            // $NON-NLS-1$
            out.writeUTF("");
        } else {
            if (generation.isReference()) {
                // make reference installs relative to the install path
                out.writeUTF(new FilePath(installPath).makeRelative(new FilePath(generation.getContent().getAbsolutePath())));
            } else {
                // make normal installs relative to the storage area
                out.writeUTF(Storage.getBundleFilePath(bundleInfo.getBundleId(), generation.getGenerationId()));
            }
        }
        out.writeLong(generation.getLastModified());
        Dictionary<String, String> headers = generation.getHeaders();
        for (String headerKey : cachedHeaderKeys) {
            String value = headers.get(headerKey);
            if (value != null) {
                out.writeUTF(value);
            } else {
                out.writeUTF(NUL);
            }
        }
        out.writeBoolean(generation.isMRJar());
    }
    saveStorageHookData(out, generations);
}
Also used : FilePath(org.eclipse.osgi.framework.util.FilePath) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ArrayList(java.util.ArrayList) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Example 25 with Generation

use of org.eclipse.osgi.storage.BundleInfo.Generation in project rt.equinox.framework by eclipse.

the class Storage method refreshMRJarBundles.

private Collection<Module> refreshMRJarBundles() throws BundleException {
    Collection<Module> mrJarBundles = new ArrayList<>();
    for (Module m : moduleContainer.getModules()) {
        Generation generation = (Generation) m.getCurrentRevision().getRevisionInfo();
        // Note that we check the raw headers here incase we are working off an old version of the persistent storage
        if (Boolean.parseBoolean(generation.getRawHeaders().get(BundleInfo.MULTI_RELEASE_HEADER))) {
            refresh(m);
            mrJarBundles.add(m);
        }
    }
    return mrJarBundles;
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ArrayList(java.util.ArrayList) Module(org.eclipse.osgi.container.Module)

Aggregations

Generation (org.eclipse.osgi.storage.BundleInfo.Generation)34 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)15 ArrayList (java.util.ArrayList)10 Module (org.eclipse.osgi.container.Module)10 IOException (java.io.IOException)8 File (java.io.File)7 BundleFile (org.eclipse.osgi.storage.bundlefile.BundleFile)7 DirBundleFile (org.eclipse.osgi.storage.bundlefile.DirBundleFile)6 NestedDirBundleFile (org.eclipse.osgi.storage.bundlefile.NestedDirBundleFile)6 ZipBundleFile (org.eclipse.osgi.storage.bundlefile.ZipBundleFile)6 BundleException (org.osgi.framework.BundleException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 URL (java.net.URL)3 ProtectionDomain (java.security.ProtectionDomain)3 ModuleRevisionBuilder (org.eclipse.osgi.container.ModuleRevisionBuilder)3 ModuleWire (org.eclipse.osgi.container.ModuleWire)3 SystemModule (org.eclipse.osgi.container.SystemModule)3 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2