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);
}
}
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);
}
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));
}
}
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;
}
Aggregations