Search in sources :

Example 61 with ProtectionDomain

use of java.security.ProtectionDomain in project ignite by apache.

the class IgniteUtils method resolveProjectHome.

/**
 * Resolve project home directory based on source code base.
 *
 * @return Project home directory (or {@code null} if it cannot be resolved).
 */
@Nullable
private static String resolveProjectHome() {
    assert Thread.holdsLock(IgniteUtils.class);
    // Resolve Ignite home via environment variables.
    String ggHome0 = IgniteSystemProperties.getString(IGNITE_HOME);
    if (!F.isEmpty(ggHome0))
        return ggHome0;
    String appWorkDir = System.getProperty("user.dir");
    if (appWorkDir != null) {
        ggHome0 = findProjectHome(new File(appWorkDir));
        if (ggHome0 != null)
            return ggHome0;
    }
    URI classesUri;
    Class<IgniteUtils> cls = IgniteUtils.class;
    try {
        ProtectionDomain domain = cls.getProtectionDomain();
        // Should not happen, but to make sure our code is not broken.
        if (domain == null || domain.getCodeSource() == null || domain.getCodeSource().getLocation() == null) {
            logResolveFailed(cls, null);
            return null;
        }
        // Resolve path to class-file.
        classesUri = domain.getCodeSource().getLocation().toURI();
        // Overcome UNC path problem on Windows (http://www.tomergabel.com/JavaMishandlesUNCPathsOnWindows.aspx)
        if (isWindows() && classesUri.getAuthority() != null)
            classesUri = new URI(classesUri.toString().replace("file://", "file:/"));
    } catch (URISyntaxException | SecurityException e) {
        logResolveFailed(cls, e);
        return null;
    }
    File classesFile;
    try {
        classesFile = new File(classesUri);
    } catch (IllegalArgumentException e) {
        logResolveFailed(cls, e);
        return null;
    }
    return findProjectHome(classesFile);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) URISyntaxException(java.net.URISyntaxException) ZipFile(java.util.zip.ZipFile) File(java.io.File) JarFile(java.util.jar.JarFile) URI(java.net.URI) Nullable(org.jetbrains.annotations.Nullable)

Example 62 with ProtectionDomain

use of java.security.ProtectionDomain in project rt.equinox.framework by eclipse.

the class EclipseStarter method getSysPathFromCodeSource.

private static String getSysPathFromCodeSource() {
    ProtectionDomain pd = EclipseStarter.class.getProtectionDomain();
    if (pd == null)
        return null;
    CodeSource cs = pd.getCodeSource();
    if (cs == null)
        return null;
    URL url = cs.getLocation();
    if (url == null)
        return null;
    String result = url.getPath();
    if (File.separatorChar == '\\') {
        // in case on windows the \ is used
        result = result.replace('\\', '/');
    }
    if (result.endsWith(".jar")) {
        // $NON-NLS-1$
        result = result.substring(0, result.lastIndexOf('/'));
        if (// $NON-NLS-1$
        "folder".equals(getProperty(PROP_FRAMEWORK_SHAPE)))
            result = result.substring(0, result.lastIndexOf('/'));
    } else {
        if (// $NON-NLS-1$
        result.endsWith("/"))
            result = result.substring(0, result.length() - 1);
        result = result.substring(0, result.lastIndexOf('/'));
        result = result.substring(0, result.lastIndexOf('/'));
    }
    return result;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) CodeSource(java.security.CodeSource)

Example 63 with ProtectionDomain

use of java.security.ProtectionDomain in project rt.equinox.framework by eclipse.

the class EquinoxContainerAdaptor method invalidateWiring.

@Override
public void invalidateWiring(ModuleWiring moduleWiring, ModuleLoader current) {
    if (current instanceof BundleLoader) {
        BundleLoader bundleLoader = (BundleLoader) current;
        bundleLoader.close();
    }
    long updatedTimestamp = storage.getModuleDatabase().getRevisionsTimestamp();
    if (System.getSecurityManager() != null && updatedTimestamp != lastSecurityAdminFlush.getAndSet(updatedTimestamp)) {
        storage.getSecurityAdmin().clearCaches();
        List<Module> modules = storage.getModuleContainer().getModules();
        for (Module module : modules) {
            for (ModuleRevision revision : module.getRevisions().getModuleRevisions()) {
                Generation generation = (Generation) revision.getRevisionInfo();
                if (generation != null) {
                    ProtectionDomain domain = generation.getDomain();
                    if (domain != null) {
                        ((BundlePermissions) domain.getPermissions()).clearPermissionCache();
                    }
                }
            }
        }
    }
    clearManifestCache(moduleWiring);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) BundlePermissions(org.eclipse.osgi.internal.permadmin.BundlePermissions) SystemModule(org.eclipse.osgi.container.SystemModule) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) SystemBundleLoader(org.eclipse.osgi.internal.loader.SystemBundleLoader) BundleLoader(org.eclipse.osgi.internal.loader.BundleLoader)

Example 64 with ProtectionDomain

use of java.security.ProtectionDomain in project Payara by payara.

the class ACCClassLoader method copyClass.

private Class<?> copyClass(final Class c) throws ClassNotFoundException {
    final String name = c.getName();
    final ProtectionDomain pd = c.getProtectionDomain();
    byte[] bytecode = readByteCode(name);
    for (ClassFileTransformer xf : transformers) {
        try {
            bytecode = xf.transform(this, name, null, pd, bytecode);
        } catch (IllegalClassFormatException ex) {
            throw new ClassNotFoundException(name, ex);
        }
    }
    return defineClass(name, bytecode, 0, bytecode.length, pd);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) ClassFileTransformer(java.lang.instrument.ClassFileTransformer) IllegalClassFormatException(java.lang.instrument.IllegalClassFormatException)

Example 65 with ProtectionDomain

use of java.security.ProtectionDomain in project Payara by payara.

the class SecurityContextUtil method authorizeCORBA.

// return true if authorization succeeds, false otherwise.
private boolean authorizeCORBA(byte[] object_id, String method) throws Exception {
    // Check if target is an EJB
    ProtocolManager protocolMgr = orbHelper.getProtocolManager();
    // is on a callback object in the client VM.
    if (protocolMgr == null) {
        return true;
    }
    if (protocolMgr.getEjbDescriptor(object_id) != null) {
        // an EJB object
        return true;
    }
    CORBAObjectPermission perm = new CORBAObjectPermission("*", method);
    // Create a ProtectionDomain for principal on current thread.
    com.sun.enterprise.security.SecurityContext sc = com.sun.enterprise.security.SecurityContext.getCurrent();
    Set principalSet = sc.getPrincipalSet();
    Principal[] principals = (principalSet == null ? null : (Principal[]) principalSet.toArray(new Principal[principalSet.size()]));
    CodeSource cs = new CodeSource(new java.net.URL("file://"), (java.security.cert.Certificate[]) null);
    ProtectionDomain prdm = new ProtectionDomain(cs, null, null, principals);
    // Check if policy gives principal the permissions
    boolean result = policy.implies(prdm, perm);
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "CORBA Object permission evaluation result=" + result + " for method=" + method);
    }
    return result;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Set(java.util.Set) CORBAObjectPermission(com.sun.enterprise.security.CORBAObjectPermission) CodeSource(java.security.CodeSource) ProtocolManager(org.glassfish.enterprise.iiop.api.ProtocolManager) Principal(java.security.Principal)

Aggregations

ProtectionDomain (java.security.ProtectionDomain)148 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)44 Instrumentor (com.navercorp.pinpoint.bootstrap.instrument.Instrumentor)44 TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)42 CodeSource (java.security.CodeSource)39 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)28 AccessControlContext (java.security.AccessControlContext)24 Permissions (java.security.Permissions)22 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)20 Permission (java.security.Permission)17 URL (java.net.URL)16 Policy (java.security.Policy)16 Test (org.junit.Test)16 File (java.io.File)12 PermissionCollection (java.security.PermissionCollection)12 IOException (java.io.IOException)11 Method (java.lang.reflect.Method)8 URI (java.net.URI)8 HashSet (java.util.HashSet)8 Principal (java.security.Principal)7