Search in sources :

Example 1 with SecurityServiceInfo

use of org.apache.openejb.assembler.classic.SecurityServiceInfo in project aries by apache.

the class EJBExtender method setupOpenEJB.

private void setupOpenEJB() throws OpenEJBException {
    //Avoid a ClassLoader problem 
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(OpenEjbVersion.class.getClassLoader());
        OpenEjbVersion.get();
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
    Assembler a = new Assembler();
    TransactionServiceInfo tsi = new TransactionServiceInfo();
    tsi.service = "TransactionManager";
    tsi.id = "OSGi Transaction Manager";
    PassthroughFactory.add(tsi, OSGiTransactionManager.get());
    //Avoid another ClassLoader problem
    try {
        Thread.currentThread().setContextClassLoader(PassthroughFactory.class.getClassLoader());
        a.createTransactionManager(tsi);
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
    try {
        //Overwrite existing, default JPA integration with an Aries JPA integrated one
        Assembler.getContext().put(JtaEntityManagerRegistry.class.getName(), AriesPersistenceContextIntegration.get());
        SystemInstance.get().setComponent(JtaEntityManagerRegistry.class, AriesPersistenceContextIntegration.get());
    } catch (NoClassDefFoundError ncdfe) {
    //TODO log that no JPA Context integration is available
    }
    SecurityServiceInfo ssi = new SecurityServiceInfo();
    ssi.service = "SecurityService";
    ssi.id = "Pseudo Security Service";
    PassthroughFactory.add(ssi, new PseudoSecurityService());
    //Avoid another ClassLoader problem
    try {
        Thread.currentThread().setContextClassLoader(PassthroughFactory.class.getClassLoader());
        a.createSecurityService(ssi);
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
    ProxyFactoryInfo proxyFactoryInfo = new ProxyFactoryInfo();
    proxyFactoryInfo.id = "Aries ProxyFactory";
    proxyFactoryInfo.service = "ProxyFactory";
    proxyFactoryInfo.properties = new Properties();
    PassthroughFactory.add(proxyFactoryInfo, AriesProxyService.get());
    try {
        Thread.currentThread().setContextClassLoader(PassthroughFactory.class.getClassLoader());
        a.createProxyFactory(proxyFactoryInfo);
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) JtaEntityManagerRegistry(org.apache.openejb.persistence.JtaEntityManagerRegistry) OpenEjbVersion(org.apache.openejb.util.OpenEjbVersion) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) PseudoSecurityService(org.apache.openejb.ri.sp.PseudoSecurityService) PassthroughFactory(org.apache.openejb.assembler.dynamic.PassthroughFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo)

Example 2 with SecurityServiceInfo

use of org.apache.openejb.assembler.classic.SecurityServiceInfo in project tomee by apache.

the class ServerContext method createSecurityService.

public void createSecurityService(final SecurityService service) throws OpenEJBException {
    final SecurityServiceInfo serviceInfo = factory.configureService(service, SecurityServiceInfo.class);
    assembler.createSecurityService(serviceInfo);
}
Also used : SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo)

Example 3 with SecurityServiceInfo

use of org.apache.openejb.assembler.classic.SecurityServiceInfo in project tomee by apache.

the class StatefulSecurityPermissionsTest method test.

public void test() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    final SecurityServiceInfo securityServiceInfo = config.configureService(SecurityServiceInfo.class);
    securityServiceInfo.className = TestSecurityService.class.getName();
    assembler.createSecurityService(securityServiceInfo);
    final TestSecurityService securityService = (TestSecurityService) SystemInstance.get().getComponent(SecurityService.class);
    securityService.login("foo", "Jazz", "Rock", "Reggae", "HipHop");
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean(Color.class));
    final List<MethodPermission> permissions = ejbJar.getAssemblyDescriptor().getMethodPermission();
    permissions.add(new MethodPermission("*", "Color", "*", "Foo"));
    permissions.add(new MethodPermission("*", "Color", "create").setUnchecked());
    permissions.add(new MethodPermission("*", "Color", "ejbCreate").setUnchecked());
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assembler.createApplication(ejbJarInfo);
    final InitialContext context = new InitialContext();
    {
        final ColorLocal color = (ColorLocal) context.lookup("ColorLocal");
        assertEquals("Jazz", color.color());
        try {
            color.color((Object) null);
        } catch (final EJBAccessException e) {
            assertEquals("Excluded", actual.get());
        }
        assertEquals("Rock", color.color((String) null));
        assertEquals("Unchecked", color.color((Boolean) null));
        assertEquals("Reggae", color.color((Integer) null));
    }
}
Also used : StatefulBean(org.apache.openejb.jee.StatefulBean) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) MethodPermission(org.apache.openejb.jee.MethodPermission) InitialContext(javax.naming.InitialContext) EJBAccessException(javax.ejb.EJBAccessException) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) SecurityService(org.apache.openejb.spi.SecurityService) AbstractSecurityService(org.apache.openejb.core.security.AbstractSecurityService) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 4 with SecurityServiceInfo

use of org.apache.openejb.assembler.classic.SecurityServiceInfo in project tomee by apache.

the class SecurityTest method configureAssembler.

private Assembler configureAssembler(final String defaultUser) throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    final SecurityServiceInfo serviceInfo = new SecurityServiceInfo();
    serviceInfo.service = "SecurityService";
    serviceInfo.className = SecurityServiceImpl.class.getName();
    serviceInfo.id = "New Security Service";
    serviceInfo.properties = new Properties();
    if (defaultUser != null) {
        // override the default user
        serviceInfo.properties.setProperty("DefaultUser", defaultUser);
    }
    assembler.createSecurityService(serviceInfo);
    // containers
    assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class));
    final EjbJar ejbJar = new EjbJar("SecurityTest");
    ejbJar.addEnterpriseBean(new StatelessBean(FooBean.class));
    ejbJar.addEnterpriseBean(new StatelessBean(BarBean.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assembler.createApplication(ejbJarInfo);
    return assembler;
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) Properties(java.util.Properties) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)4 Assembler (org.apache.openejb.assembler.classic.Assembler)3 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)3 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)3 Properties (java.util.Properties)2 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)2 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)2 EjbJar (org.apache.openejb.jee.EjbJar)2 EJBAccessException (javax.ejb.EJBAccessException)1 EJBLocalObject (javax.ejb.EJBLocalObject)1 EJBObject (javax.ejb.EJBObject)1 InitialContext (javax.naming.InitialContext)1 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)1 PassthroughFactory (org.apache.openejb.assembler.dynamic.PassthroughFactory)1 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)1 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)1 AbstractSecurityService (org.apache.openejb.core.security.AbstractSecurityService)1 MethodPermission (org.apache.openejb.jee.MethodPermission)1 StatefulBean (org.apache.openejb.jee.StatefulBean)1 StatelessBean (org.apache.openejb.jee.StatelessBean)1