Search in sources :

Example 56 with ProtectionDomain

use of java.security.ProtectionDomain in project jdk8u_jdk by JetBrains.

the class MBeanInstantiator method getClassLoader.

private ClassLoader getClassLoader(final ObjectName name) {
    if (clr == null) {
        return null;
    }
    // Restrict to getClassLoader permission only
    Permissions permissions = new Permissions();
    permissions.add(new MBeanPermission("*", null, name, "getClassLoader"));
    ProtectionDomain protectionDomain = new ProtectionDomain(null, permissions);
    ProtectionDomain[] domains = { protectionDomain };
    AccessControlContext ctx = new AccessControlContext(domains);
    ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {

        public ClassLoader run() {
            return clr.getClassLoader(name);
        }
    }, ctx);
    return loader;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) AccessControlContext(java.security.AccessControlContext) MBeanPermission(javax.management.MBeanPermission) Permissions(java.security.Permissions)

Example 57 with ProtectionDomain

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

the class Main method main.

/**
     * @param args
     */
public static void main(String[] args) {
    String home = System.getProperties().getProperty(SLING_HOME);
    if (home == null) {
        home = new File(DEFAULT_STANBOL_HOME).getAbsolutePath();
        System.setProperty(SLING_HOME, home);
    }
    //else do not override user configured values
    List<String> argsList = new ArrayList<String>(Arrays.asList(args));
    if (argsList.contains(PRINTHELPARG)) {
        doHelp();
        System.exit(0);
    }
    if (argsList.contains(NOSECURITYARG)) {
        argsList.remove(NOSECURITYARG);
    } else {
        args = argsList.toArray(new String[argsList.size()]);
        Policy.setPolicy(new Policy() {

            @Override
            public PermissionCollection getPermissions(ProtectionDomain domain) {
                PermissionCollection result = new Permissions();
                result.add(new AllPermission());
                return result;
            }
        });
        System.setSecurityManager(new SecurityManager());
    }
    //now use the standard Apache Sling launcher to do the job
    org.apache.sling.launchpad.app.Main.main(argsList.toArray(new String[argsList.size()]));
}
Also used : Policy(java.security.Policy) ProtectionDomain(java.security.ProtectionDomain) PermissionCollection(java.security.PermissionCollection) ArrayList(java.util.ArrayList) Permissions(java.security.Permissions) AllPermission(java.security.AllPermission) File(java.io.File)

Example 58 with ProtectionDomain

use of java.security.ProtectionDomain in project jdk8u_jdk by JetBrains.

the class DGCImplInsulation method main.

public static void main(String[] args) throws Exception {
    TestLibrary.suggestSecurityManager(null);
    Permissions perms = new Permissions();
    perms.add(new SocketPermission("*:1024-", "listen"));
    AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(new CodeSource(null, (Certificate[]) null), perms) });
    Remote impl = new DGCImplInsulation();
    ;
    try {
        Remote stub = (Remote) java.security.AccessController.doPrivileged(new ExportAction(impl));
        System.err.println("exported remote object; local stub: " + stub);
        MarshalledObject mobj = new MarshalledObject(stub);
        stub = (Remote) mobj.get();
        System.err.println("marshalled/unmarshalled stub: " + stub);
        ReferenceQueue refQueue = new ReferenceQueue();
        Reference weakRef = new WeakReference(impl, refQueue);
        impl = null;
        System.gc();
        if (refQueue.remove(TIMEOUT) == weakRef) {
            throw new RuntimeException("TEST FAILED: remote object garbage collected");
        } else {
            System.err.println("TEST PASSED");
            stub = null;
            System.gc();
            Thread.sleep(2000);
            System.gc();
        }
    } finally {
        try {
            UnicastRemoteObject.unexportObject(impl, true);
        } catch (Exception e) {
        }
    }
}
Also used : ProtectionDomain(java.security.ProtectionDomain) ReferenceQueue(java.lang.ref.ReferenceQueue) Reference(java.lang.ref.Reference) WeakReference(java.lang.ref.WeakReference) SocketPermission(java.net.SocketPermission) Remote(java.rmi.Remote) CodeSource(java.security.CodeSource) AccessControlContext(java.security.AccessControlContext) MarshalledObject(java.rmi.MarshalledObject) WeakReference(java.lang.ref.WeakReference) Permissions(java.security.Permissions) Certificate(java.security.cert.Certificate)

Example 59 with ProtectionDomain

use of java.security.ProtectionDomain in project wcomponents by BorderTech.

the class DefaultInternalConfiguration method getDebuggingInfo.

/**
 * @return debugging information for logging on application start-up.
 */
protected String getDebuggingInfo() {
    final String paramsFile = "log4j.appender.PARAMS.File";
    File cwd = new File(".");
    String workingDir;
    try {
        workingDir = cwd.getCanonicalPath();
    } catch (IOException ex) {
        workingDir = "UNKNOWN";
    }
    String codesourceStr = "";
    // Try to be sneaky and print the codesource location (for orientation of user)
    try {
        ProtectionDomain domain = getClass().getProtectionDomain();
        CodeSource codesource = null;
        if (domain != null) {
            codesource = domain.getCodeSource();
        }
        codesourceStr = (codesource != null ? " code location of ParamImpl: " + codesource.getLocation() : "");
    } catch (Throwable failed) {
    // Okay
    }
    StringBuffer info = new StringBuffer();
    info.append("----Parameters start----");
    info.append(codesourceStr);
    info.append("\nWorking directory is ");
    info.append(workingDir);
    info.append("\nParameters have loaded, there is a full parameter dump in log4j FILE appender at ");
    info.append(get(paramsFile));
    info.append("\nTo dump all params to stdout set ");
    info.append(DUMP);
    info.append(" to true; currently value is ");
    info.append(get(DUMP));
    info.append("\n----Parameters end------");
    return info.toString();
}
Also used : ProtectionDomain(java.security.ProtectionDomain) IOException(java.io.IOException) CodeSource(java.security.CodeSource) File(java.io.File)

Example 60 with ProtectionDomain

use of java.security.ProtectionDomain in project jPOS by jpos.

the class Slf4JDynamicBinder method applyMods.

public static void applyMods() throws Exception {
    if (!bound && !bindingsExist()) {
        final ProtectionDomain pd = Slf4JDynamicBinder.class.getProtectionDomain();
        final ClassPool cp = ClassPool.getDefault();
        CtClass clz = cp.getAndRename(StaticLoggerBinder.class.getName(), STATIC_BINDER_CLASS);
        clz.toClass(null, pd);
        CtClass clz2 = cp.get("org.slf4j.LoggerFactory");
        CtMethod bindMethod = clz2.getDeclaredMethod("bind");
        bindMethod.setBody("try " + "{" + " org.slf4j.impl.StaticLoggerBinder.getSingleton();" + " INITIALIZATION_STATE = SUCCESSFUL_INITIALIZATION;" + " fixSubstituteLoggers();" + " replayEvents();" + " SUBST_FACTORY.clear();" + "} " + "catch(Exception e)" + "{" + " failedBinding(e); " + " throw new IllegalStateException(\"Unexpected initialization failure\", e);" + "}");
        clz2.toClass(null, pd);
        clz2.detach();
        clz.detach();
        bound = true;
    }
}
Also used : ProtectionDomain(java.security.ProtectionDomain) CtClass(javassist.CtClass) ClassPool(javassist.ClassPool) CtMethod(javassist.CtMethod)

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