Search in sources :

Example 86 with ProtectionDomain

use of java.security.ProtectionDomain in project head by mifos.

the class OSGILauncher method setupSecurityPolicy.

protected void setupSecurityPolicy() throws FrameworkException {
    String eclipseSecurity = (String) properties.get(PROP_ECLIPSE_SECURITY);
    if (eclipseSecurity != null) {
        // setup a policy that grants the launcher and path for the
        // framework AllPermissions.
        // Do not set the security manager, this will be done by the
        // framework itself.
        ProtectionDomain domain = OSGILauncher.class.getProtectionDomain();
        CodeSource source = null;
        if (domain != null)
            source = OSGILauncher.class.getProtectionDomain().getCodeSource();
        if (domain == null || source == null) {
            throw new FrameworkException("Can not automatically set the security manager. Please use a policy file.");
        }
        // get the list of codesource URLs to grant AllPermission to
        URL[] rootURLs = new URL[] { source.getLocation(), osgiFramework };
        // replace the security policy
        Policy eclipsePolicy = new OSGIPolicy(Policy.getPolicy(), rootURLs);
        Policy.setPolicy(eclipsePolicy);
    }
}
Also used : Policy(java.security.Policy) ProtectionDomain(java.security.ProtectionDomain) FrameworkException(org.eclipse.birt.core.framework.FrameworkException) CodeSource(java.security.CodeSource) URL(java.net.URL)

Example 87 with ProtectionDomain

use of java.security.ProtectionDomain in project spring-boot by spring-projects.

the class LogbackLoggingSystem method getLocation.

private Object getLocation(ILoggerFactory factory) {
    try {
        ProtectionDomain protectionDomain = factory.getClass().getProtectionDomain();
        CodeSource codeSource = protectionDomain.getCodeSource();
        if (codeSource != null) {
            return codeSource.getLocation();
        }
    } catch (SecurityException ex) {
    // Unable to determine location
    }
    return "unknown location";
}
Also used : ProtectionDomain(java.security.ProtectionDomain) CodeSource(java.security.CodeSource)

Example 88 with ProtectionDomain

use of java.security.ProtectionDomain in project spring-boot by spring-projects.

the class Launcher method createArchive.

protected final Archive createArchive() throws Exception {
    ProtectionDomain protectionDomain = getClass().getProtectionDomain();
    CodeSource codeSource = protectionDomain.getCodeSource();
    URI location = (codeSource == null ? null : codeSource.getLocation().toURI());
    String path = (location == null ? null : location.getSchemeSpecificPart());
    if (path == null) {
        throw new IllegalStateException("Unable to determine code source archive");
    }
    File root = new File(path);
    if (!root.exists()) {
        throw new IllegalStateException("Unable to determine code source archive from " + root);
    }
    return (root.isDirectory() ? new ExplodedArchive(root) : new JarFileArchive(root));
}
Also used : ExplodedArchive(org.springframework.boot.loader.archive.ExplodedArchive) ProtectionDomain(java.security.ProtectionDomain) JarFileArchive(org.springframework.boot.loader.archive.JarFileArchive) CodeSource(java.security.CodeSource) URI(java.net.URI) JarFile(org.springframework.boot.loader.jar.JarFile) File(java.io.File)

Example 89 with ProtectionDomain

use of java.security.ProtectionDomain in project spring-framework by spring-projects.

the class CallbacksSecurityTests method setUp.

@Before
public void setUp() throws Exception {
    final ProtectionDomain empty = new ProtectionDomain(null, new Permissions());
    provider = new SecurityContextProvider() {

        private final AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] { empty });

        @Override
        public AccessControlContext getAccessControlContext() {
            return acc;
        }
    };
    DefaultResourceLoader drl = new DefaultResourceLoader();
    Resource config = drl.getResource("/org/springframework/beans/factory/support/security/callbacks.xml");
    beanFactory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(config);
    beanFactory.setSecurityContextProvider(provider);
}
Also used : SecurityContextProvider(org.springframework.beans.factory.support.SecurityContextProvider) ProtectionDomain(java.security.ProtectionDomain) AccessControlContext(java.security.AccessControlContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) Permissions(java.security.Permissions) Resource(org.springframework.core.io.Resource) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Before(org.junit.Before)

Example 90 with ProtectionDomain

use of java.security.ProtectionDomain in project spring-framework by spring-projects.

the class CallbacksSecurityTests method testTrustedExecution.

@Test
public void testTrustedExecution() throws Exception {
    beanFactory.setSecurityContextProvider(null);
    Permissions perms = new Permissions();
    perms.add(new AuthPermission("getSubject"));
    ProtectionDomain pd = new ProtectionDomain(null, perms);
    new AccessControlContext(new ProtectionDomain[] { pd });
    final Subject subject = new Subject();
    subject.getPrincipals().add(new TestPrincipal("user1"));
    // request the beans from non-privileged code
    Subject.doAsPrivileged(subject, new PrivilegedAction<Object>() {

        @Override
        public Object run() {
            // sanity check
            assertEquals("user1", getCurrentSubjectName());
            assertEquals(false, NonPrivilegedBean.destroyed);
            beanFactory.getBean("trusted-spring-callbacks");
            beanFactory.getBean("trusted-custom-init-destroy");
            // the factory is a prototype - ask for multiple instances
            beanFactory.getBean("trusted-spring-factory");
            beanFactory.getBean("trusted-spring-factory");
            beanFactory.getBean("trusted-spring-factory");
            beanFactory.getBean("trusted-factory-bean");
            beanFactory.getBean("trusted-static-factory-method");
            beanFactory.getBean("trusted-factory-method");
            beanFactory.getBean("trusted-property-injection");
            beanFactory.getBean("trusted-working-property-injection");
            beanFactory.destroySingletons();
            assertEquals(true, NonPrivilegedBean.destroyed);
            return null;
        }
    }, provider.getAccessControlContext());
}
Also used : ProtectionDomain(java.security.ProtectionDomain) AccessControlContext(java.security.AccessControlContext) AuthPermission(javax.security.auth.AuthPermission) Permissions(java.security.Permissions) Subject(javax.security.auth.Subject) Test(org.junit.Test)

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