repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/callerprincipal/GetCallerPrincipalTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.callerprincipal; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.util.concurrent.Callable; import jakarta.jms.DeliveryMode; import jakarta.jms.Message; import jakarta.jms.MessageConsumer; import jakarta.jms.MessageProducer; import jakarta.jms.ObjectMessage; import jakarta.jms.Queue; import jakarta.jms.QueueConnection; import jakarta.jms.QueueConnectionFactory; import jakarta.jms.QueueSession; import jakarta.jms.Session; import jakarta.jms.TemporaryQueue; import jakarta.jms.TextMessage; import javax.naming.InitialContext; import javax.naming.NamingException; import org.jboss.as.test.shared.integration.ejb.security.Util; import org.junit.Assert; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.categories.CommonCriteria; import org.jboss.as.test.integration.common.jms.JMSOperationsProvider; import org.jboss.as.test.integration.ejb.security.EjbSecurityDomainSetup; import org.jboss.as.test.integration.management.base.AbstractMgmtServerSetupTask; import org.jboss.as.test.integration.management.base.AbstractMgmtTestBase; import org.jboss.as.test.integration.management.util.MgmtOperationException; import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.staxmapper.XMLElementReader; import org.jboss.staxmapper.XMLElementWriter; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.wildfly.security.permission.ElytronPermission; /** * The Bean Provider can invoke the getCallerPrincipal and isCallerInRole methods only * in the enterprise bean’s business methods as specified in Table 1 on page 94, Table 2 on page 103, * Table 4 on page 149, Table 5 on page 231, and Table 11 on page 303. If they are otherwise invoked * when no security context exists, they should throw the java.lang.IllegalStateException * runtime exception. * * In case of no security context * Stateless - PostConstruct, PreDestroy * MDB - PostConstruct, PreDestroy * Entity Beans - ejbActivate, ebjPassivate * * @author Ondrej Chaloupka */ @RunWith(Arquillian.class) @ServerSetup({EjbSecurityDomainSetup.class, GetCallerPrincipalTestCase.JmsQueueSetup.class}) @Category(CommonCriteria.class) public class GetCallerPrincipalTestCase { private static final String QUEUE_NAME = "queue/callerPrincipal"; private static final String QUEUE_LOOKUP = "java:jboss/" + QUEUE_NAME; private static final Logger log = Logger.getLogger(GetCallerPrincipalTestCase.class); private static final String ANONYMOUS = "anonymous"; //TODO: is this constant configured somewhere? private static final String OK = "OK"; public static final String LOCAL_USER = "$local"; @ArquillianResource Deployer deployer; @ArquillianResource private InitialContext initialContext; static class JmsQueueSetup extends AbstractMgmtServerSetupTask { @Override protected void doSetup(final ManagementClient managementClient) throws Exception { JMSOperationsProvider.getInstance(managementClient).createJmsQueue(QUEUE_NAME, QUEUE_LOOKUP); } @Override public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception { JMSOperationsProvider.getInstance(managementClient).removeJmsQueue(QUEUE_NAME); } } @Deployment(managed=true, testable = false, name = "single", order = 0) public static Archive<?> deploymentSingleton() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "single.jar") .addClass(TestResultsSingleton.class) .addClass(ITestResultsSingleton.class) .addAsManifestResource(GetCallerPrincipalTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml") .addAsManifestResource(GetCallerPrincipalTestCase.class.getPackage(), "MANIFEST.MF-single", "MANIFEST.MF") .addAsManifestResource(createPermissionsXmlAsset(new ElytronPermission("getSecurityDomain"), new ElytronPermission("authenticate")), "permissions.xml"); jar.addPackage(CommonCriteria.class.getPackage()); return jar; } @Deployment(managed=false, testable = false, name = "slsb", order = 100) public static Archive<?> deploymentSlsb() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "slsb.jar") .addClass(SLSBLifecycleCallback.class) .addClass(IBeanLifecycleCallback.class) .addAsResource(GetCallerPrincipalTestCase.class.getPackage(), "users.properties", "users.properties") .addAsResource(GetCallerPrincipalTestCase.class.getPackage(), "roles.properties", "roles.properties") .addAsManifestResource(GetCallerPrincipalTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml") .addAsManifestResource(GetCallerPrincipalTestCase.class.getPackage(), "MANIFEST.MF-bean", "MANIFEST.MF") .addAsManifestResource(createPermissionsXmlAsset(new ElytronPermission("getSecurityDomain"), new ElytronPermission("authenticate")), "permissions.xml"); jar.addPackage(CommonCriteria.class.getPackage()); return jar; } @Deployment(managed=false, testable = false, name = "sfsb", order = 101) public static Archive<?> deploymentSfsb() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "sfsb.jar") .addClass(SFSBLifecycleCallback.class) .addClass(IBeanLifecycleCallback.class) .addAsResource(GetCallerPrincipalTestCase.class.getPackage(), "users.properties", "users.properties") .addAsResource(GetCallerPrincipalTestCase.class.getPackage(), "roles.properties", "roles.properties") .addAsManifestResource(GetCallerPrincipalTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml") .addAsManifestResource(GetCallerPrincipalTestCase.class.getPackage(), "MANIFEST.MF-bean", "MANIFEST.MF") .addAsManifestResource(createPermissionsXmlAsset(new ElytronPermission("getSecurityDomain"), new ElytronPermission("authenticate")), "jboss-permissions.xml"); jar.addPackage(CommonCriteria.class.getPackage()); return jar; } @Deployment(managed=false, testable = false, name = "mdb", order = 102) public static Archive<?> deploymentMdb() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "mdb.jar") .addClass(MDBLifecycleCallback.class) .addAsResource(GetCallerPrincipalTestCase.class.getPackage(), "users.properties", "users.properties") .addAsResource(GetCallerPrincipalTestCase.class.getPackage(), "roles.properties", "roles.properties") .addAsManifestResource(GetCallerPrincipalTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml") .addAsManifestResource(GetCallerPrincipalTestCase.class.getPackage(), "MANIFEST.MF-bean", "MANIFEST.MF") .addAsManifestResource(createPermissionsXmlAsset(new ElytronPermission("getSecurityDomain"), new ElytronPermission("authenticate")), "permissions.xml"); jar.addPackage(CommonCriteria.class.getPackage()); return jar; } @Deployment(managed = true, testable = true, name="test", order = 3) public static Archive<?> deployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "callerprincipal-test.jar") .addClass(GetCallerPrincipalTestCase.class) .addClass(SLSBWithoutSecurityDomain.class) .addClass(ISLSBWithoutSecurityDomain.class) .addClass(PollingUtils.class) .addClass(Util.class) .addClasses(JmsQueueSetup.class, EjbSecurityDomainSetup.class, AbstractSecurityDomainSetup.class, AbstractMgmtTestBase.class) .addPackage(AbstractMgmtTestBase.class.getPackage()).addClasses(MgmtOperationException.class, XMLElementReader.class, XMLElementWriter.class) .addAsResource(GetCallerPrincipalTestCase.class.getPackage(), "users.properties", "users.properties") .addAsResource(GetCallerPrincipalTestCase.class.getPackage(), "roles.properties", "roles.properties") .addAsManifestResource(GetCallerPrincipalTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml") .addAsManifestResource(GetCallerPrincipalTestCase.class.getPackage(), "MANIFEST.MF-test", "MANIFEST.MF") .addAsManifestResource(createPermissionsXmlAsset(new ElytronPermission("getSecurityDomain"), new ElytronPermission("authenticate")), "permissions.xml"); jar.addPackage(CommonCriteria.class.getPackage()); return jar; } private ITestResultsSingleton getResultsSingleton() throws NamingException { return (ITestResultsSingleton) initialContext.lookup("ejb:/single//" + TestResultsSingleton.class.getSimpleName() + "!" + ITestResultsSingleton.class.getName()); } @Test public void testStatelessLifecycle() throws Exception { deployer.deploy("slsb"); ITestResultsSingleton results = this.getResultsSingleton(); IBeanLifecycleCallback bean = (IBeanLifecycleCallback) initialContext.lookup("ejb:/slsb//" + SLSBLifecycleCallback.class.getSimpleName() + "!" + IBeanLifecycleCallback.class.getName()); log.trace("Stateless bean returns: " + bean.get()); Assert.assertEquals(OK + "start", results.getSlsb("postconstruct")); deployer.undeploy("slsb"); Assert.assertEquals(OK + "stop", results.getSlsb("predestroy")); } @Test public void testStatefulLifecycle() throws Exception { deployer.deploy("sfsb"); try { ITestResultsSingleton results = this.getResultsSingleton(); IBeanLifecycleCallback bean = (IBeanLifecycleCallback) initialContext.lookup("ejb:/sfsb//" + SFSBLifecycleCallback.class.getSimpleName() + "!" + IBeanLifecycleCallback.class.getName() + "?stateful"); log.trace("Stateful bean returns: " + bean.get()); Assert.assertEquals(ANONYMOUS + "start", results.getSfsb("postconstruct")); bean.remove(); Assert.assertEquals(LOCAL_USER + "stop", results.getSfsb("predestroy")); } finally { deployer.undeploy("sfsb"); } } /** * Run this one in the container so it can lookup the queue * @throws Exception */ @OperateOnDeployment("test") @Test public void testMDBLifecycle() throws Exception { deployer.deploy("mdb"); final Callable<Void> callable = () -> { ITestResultsSingleton results = this.getResultsSingleton(); MessageProducer producer = null; MessageConsumer consumer = null; QueueConnection conn = null; Session session = null; try { QueueConnectionFactory qcf = (QueueConnectionFactory) new InitialContext().lookup("java:/ConnectionFactory"); Queue queue = (Queue) new InitialContext().lookup("java:jboss/" + QUEUE_NAME); conn = qcf.createQueueConnection("guest", "guest"); conn.start(); session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); TemporaryQueue replyQueue = session.createTemporaryQueue(); TextMessage msg = session.createTextMessage("Hello world"); msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); msg.setJMSReplyTo(replyQueue); producer = session.createProducer(queue); producer.send(msg); consumer = session.createConsumer(replyQueue); Message replyMsg = consumer.receive(5000); Object obj = ((ObjectMessage) replyMsg).getObject(); log.trace("MDB message get: " + obj); Assert.assertEquals(OK + "start", results.getMdb("postconstruct")); deployer.undeploy("mdb"); Assert.assertEquals(OK + "stop", results.getMdb("predestroy")); } finally { if(consumer != null) { consumer.close(); } if(producer!=null) { producer.close(); } if(session!=null) { session.close(); } if(conn!=null) { conn.close(); } } return null; }; Util.switchIdentitySCF("user1", "password1", callable); } }
14,688
48.291946
211
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/callerprincipal/TestResultsSingleton.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.callerprincipal; import java.util.HashMap; import java.util.Map; import jakarta.ejb.Remote; import jakarta.ejb.Singleton; import jakarta.ejb.Startup; @Singleton @Startup @Remote(ITestResultsSingleton.class) public class TestResultsSingleton implements ITestResultsSingleton { private Map<String, String> slsb = new HashMap<String, String>(); private Map<String, String> sfsb = new HashMap<String, String>(); private Map<String, String> mdb = new HashMap<String, String>(); private Map<String, String> eb = new HashMap<String, String>(); public String getSlsb(String index) { return this.slsb.get(index); } public void setSlsb(String index, String value) { this.slsb.put(index, value); } public String getSfsb(String index) { return this.sfsb.get(index); } public void setSfsb(String index, String value) { this.sfsb.put(index, value); } public String getMdb(String index) { return mdb.get(index); } public void setMdb(String index, String value) { this.mdb.put(index, value); } public String getEb(String index) { return eb.get(index); } public void setEb(String index, String value) { this.eb.put(index, value); } }
2,342
33.970149
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/callerprincipal/ISLSBWithoutSecurityDomain.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.callerprincipal; import java.security.Principal; public interface ISLSBWithoutSecurityDomain { Principal getCallerPrincipal(); }
1,211
39.4
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/callerprincipal/SFSBLifecycleCallback.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.callerprincipal; import java.security.Principal; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import jakarta.annotation.Resource; import jakarta.ejb.Remote; import jakarta.ejb.Remove; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateful; import org.jboss.ejb3.annotation.SecurityDomain; import org.jboss.logging.Logger; @Stateful @Remote(IBeanLifecycleCallback.class) @SecurityDomain("ejb3-tests") public class SFSBLifecycleCallback implements IBeanLifecycleCallback { private static Logger log = Logger.getLogger(SFSBLifecycleCallback.class); @Resource private SessionContext sessContext; private ITestResultsSingleton getSingleton() { return (ITestResultsSingleton) sessContext.lookup("java:global/single/" + TestResultsSingleton.class.getSimpleName()); } @Remove public void remove() { // removing the sfsb } @PostConstruct public void init() throws Exception { // on Stateful bean is permitted to call getCallerPrincipal on @PostConstruct ITestResultsSingleton results = this.getSingleton(); Principal princ = sessContext.getCallerPrincipal(); results.setSfsb("postconstruct", princ.getName() + "start"); log.trace(SFSBLifecycleCallback.class.getSimpleName() + " @PostConstruct called"); } @PreDestroy public void tearDown() throws Exception { // on Stateful bean is permitted to call getCallerPrincipal on @PreDestroy ITestResultsSingleton results = this.getSingleton(); Principal princ = sessContext.getCallerPrincipal(); results.setSfsb("predestroy", princ.getName() + "stop"); log.trace(SFSBLifecycleCallback.class.getSimpleName() + " @PreDestroy called"); } public String get() { log.trace("stateful get() principal: " + sessContext.getCallerPrincipal()); return "stateful"; } }
2,996
35.54878
126
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/callerprincipal/PollingUtils.java
/* * JBoss, Home of Professional Open Source. * Copyright 2010, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.callerprincipal; import static org.jboss.as.protocol.StreamUtils.safeClose; import java.io.BufferedInputStream; import java.io.InputStream; import java.io.OutputStreamWriter; import java.net.URL; import java.net.URLConnection; import java.nio.charset.StandardCharsets; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.naming.Context; import javax.naming.NamingException; /** * Since things get installed asynchronously, a deployment is sometimes * reported as installed before we can actually use it. Work around this * by retrying for now. * * @author <a href="[email protected]">Kabir Khan</a> * @version $Revision: 1.1 $ */ public class PollingUtils { public static void retryWithTimeout(long timeoutMs, Task task) throws Exception { long end = System.currentTimeMillis() + timeoutMs; do { if (task.execute()) { return; } Thread.sleep(100); } while (System.currentTimeMillis() < end); throw new RuntimeException("Task could not be completed within " + timeoutMs + "ms"); } public interface Task { boolean execute() throws Exception; } public static class WaitForMBeanTask implements Task { private final MBeanServerConnection server; private final ObjectName name; public WaitForMBeanTask(MBeanServerConnection server, ObjectName name) { this.server = server; this.name = name; } @Override public boolean execute() throws Exception { try { return server.getMBeanInfo(name) != null; } catch (Exception e) { return false; } } } public static class JndiLookupTask implements Task { private final Context context; private final String name; private Object result; public JndiLookupTask(Context context, String name) { this.context = context; this.name = name; } @Override public boolean execute() throws Exception { try { result = context.lookup(name); } catch (NamingException e) { return false; } return true; } public <T> T getResult(Class<T> clazz) { return clazz.cast(result); } } public static class UrlConnectionTask implements Task { private final URL url; private String response; private final String request; public UrlConnectionTask(URL url) { this.url = url; this.request = null; } public UrlConnectionTask(URL url, String request) { this.url = url; this.request = request; } @Override public boolean execute() throws Exception { URLConnection conn = null; InputStream in = null; OutputStreamWriter osw = null; try { conn = url.openConnection(); conn.setDoInput(true); if (request != null) { conn.setDoOutput(true); osw = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8); osw.write(request); osw.flush(); } in = new BufferedInputStream(conn.getInputStream()); int i = in.read(); StringBuilder sb = new StringBuilder(); while (i != -1) { sb.append((char) i); i = in.read(); } response = sb.toString(); return true; } catch (Exception e) { return false; }finally { if (osw != null) { safeClose(osw); } safeClose(in); } } public String getResponse() { return response; } } }
5,152
31.006211
97
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/callerprincipal/IBeanLifecycleCallback.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.callerprincipal; public interface IBeanLifecycleCallback { String get(); void remove(); }
1,174
39.517241
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/callerprincipal/GetCallerPrincipalWithNoDefaultSecurityDomainTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.callerprincipal; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.test.categories.CommonCriteria; import org.jboss.as.test.integration.management.base.AbstractMgmtServerSetupTask; import org.jboss.as.test.integration.management.base.AbstractMgmtTestBase; import org.jboss.as.test.integration.management.util.MgmtOperationException; import org.jboss.dmr.ModelNode; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.staxmapper.XMLElementReader; import org.jboss.staxmapper.XMLElementWriter; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import javax.naming.InitialContext; import java.security.Principal; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; /** * Tests that when the default security domain is disabled at EJB3 subsystem level then the security API * invocations on the EJB work correctly * * @author Jaikiran Pai * @see https://issues.jboss.org/browse/AS7-5581 */ @RunWith(Arquillian.class) @ServerSetup({GetCallerPrincipalWithNoDefaultSecurityDomainTestCase.DisableDefaultSecurityDomainSetupTask.class}) @Category(CommonCriteria.class) public class GetCallerPrincipalWithNoDefaultSecurityDomainTestCase { private static final Logger LOGGER = Logger.getLogger(GetCallerPrincipalWithNoDefaultSecurityDomainTestCase.class); private static final String ANONYMOUS = "anonymous"; //TODO: is this constant configured somewhere? private static final String MODULE_NAME = "callerprincipal-without-default-security-domain"; /** * Server setup task responsible for disabling (and then re-enabling) the default security domain * that's configured at EJB3 subsystem level */ static class DisableDefaultSecurityDomainSetupTask extends AbstractMgmtServerSetupTask { private static final String DEFAULT_SECURITY_DOMAIN = "default-security-domain"; private static final String SUBSYSTEM_NAME = "ejb3"; private String defaultSecurityDomain; @Override protected void doSetup(final ManagementClient managementClient) throws Exception { // first read the current value of the default-security-domain final PathAddress ejb3SubsystemPathAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME)); final ModelNode defaultSecurityDomainAttr = new ModelNode(); defaultSecurityDomainAttr.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION); defaultSecurityDomainAttr.get(NAME).set(DEFAULT_SECURITY_DOMAIN); defaultSecurityDomainAttr.get(OP_ADDR).set(ejb3SubsystemPathAddress.toModelNode()); final ModelNode readResult = executeOperation(defaultSecurityDomainAttr); this.defaultSecurityDomain = readResult.asString(); // remove the default security domain from EJB3 subsystem final ModelNode disableDefaultSecurityDomain = new ModelNode(); disableDefaultSecurityDomain.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION); disableDefaultSecurityDomain.get(NAME).set(DEFAULT_SECURITY_DOMAIN); disableDefaultSecurityDomain.get(OP_ADDR).set(ejb3SubsystemPathAddress.toModelNode()); executeOperation(disableDefaultSecurityDomain); } @Override public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception { final PathAddress ejb3SubsystemPathAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME)); final ModelNode defaultSecurityDomainAttr = new ModelNode(); defaultSecurityDomainAttr.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION); defaultSecurityDomainAttr.get(NAME).set(DEFAULT_SECURITY_DOMAIN); defaultSecurityDomainAttr.get(VALUE).set(this.defaultSecurityDomain); defaultSecurityDomainAttr.get(OP_ADDR).set(ejb3SubsystemPathAddress.toModelNode()); executeOperation(defaultSecurityDomainAttr); } } @ArquillianResource private InitialContext initialContext; @Deployment public static Archive<?> deployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar") .addClass(GetCallerPrincipalWithNoDefaultSecurityDomainTestCase.class) .addClass(SLSBWithoutSecurityDomain.class) .addClass(ISLSBWithoutSecurityDomain.class) .addClasses(DisableDefaultSecurityDomainSetupTask.class, AbstractMgmtTestBase.class) .addPackage(AbstractMgmtTestBase.class.getPackage()).addClasses(MgmtOperationException.class, XMLElementReader.class, XMLElementWriter.class) .addAsManifestResource(GetCallerPrincipalWithNoDefaultSecurityDomainTestCase.class.getPackage(), "MANIFEST.MF-no-default-security-domain", "MANIFEST.MF"); jar.addPackage(CommonCriteria.class.getPackage()); return jar; } /** * Tests that the {@link jakarta.ejb.EJBContext#getCallerPrincipal()} works as expected in the absence of * any default security domain at EJB3 susbsystem level and any explicit security domain on the bean */ @Test public void testUnauthenticatedNoSecurityDomain() throws Exception { try { ISLSBWithoutSecurityDomain bean = (ISLSBWithoutSecurityDomain) initialContext.lookup("ejb:/" + MODULE_NAME + "//" + SLSBWithoutSecurityDomain.class.getSimpleName() + "!" + ISLSBWithoutSecurityDomain.class.getName()); final Principal principal = bean.getCallerPrincipal(); assertNotNull("EJB 3.1 FR 17.6.5 The container must never return a null from the getCallerPrincipal method.", principal); assertEquals(ANONYMOUS, principal.getName()); } catch (RuntimeException e) { LOGGER.error("EJB 3.1 FR 17.6.5", e); fail("EJB 3.1 FR 17.6.5 The EJB container must provide the caller’s security context information during the execution of a business method (" + e.getMessage() + ")"); } } }
8,269
50.6875
228
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/callerprincipal/SLSBLifecycleCallback.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.callerprincipal; import java.security.Principal; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import jakarta.annotation.Resource; import jakarta.ejb.Remote; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; import org.jboss.ejb3.annotation.SecurityDomain; import org.jboss.logging.Logger; @Stateless @Remote(IBeanLifecycleCallback.class) @SecurityDomain("ejb3-tests") public class SLSBLifecycleCallback implements IBeanLifecycleCallback { private static Logger log = Logger.getLogger(SLSBLifecycleCallback.class); @Resource private SessionContext sessContext; private ITestResultsSingleton getSingleton() { return (ITestResultsSingleton) sessContext.lookup("java:global/single/" + TestResultsSingleton.class.getSimpleName()); } public void remove() { // nothing to do } @PostConstruct public void init() throws Exception { // on Stateless bean is not permitted to call getCallerPrincipal on @PostConstruct ITestResultsSingleton results = getSingleton(); log.trace(SLSBLifecycleCallback.class.getSimpleName() + " @PostConstruct called"); Principal princ = null; try { princ = sessContext.getCallerPrincipal(); } catch (IllegalStateException e) { results.setSlsb("postconstruct", "OKstart"); return; } results.setSlsb("postconstruct", "Method getCallerPrincipal was called from @PostConstruct with result: " + princ); } @PreDestroy public void tearDown() throws Exception { // on Stateless bean is not permitted to call getCallerPrincipal on @PreDestroy ITestResultsSingleton results = getSingleton(); log.trace(SLSBLifecycleCallback.class.getSimpleName() + " @PreDestroy called"); Principal princ = null; try { princ = sessContext.getCallerPrincipal(); } catch (IllegalStateException e) { results.setSlsb("predestroy", "OKstop"); return; } results.setSlsb("predestroy", "Method getCallerPrincipal was called from @PreDestroy with result: " + princ); } public String get() { return "stateless"; } }
3,316
36.269663
126
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/callerprincipal/ITestResultsSingleton.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.callerprincipal; public interface ITestResultsSingleton { String getSlsb(String index); void setSlsb(String index, String value); String getSfsb(String index); void setSfsb(String index, String value); String getMdb(String index); void setMdb(String index, String value); String getEb(String index); void setEb(String index, String value); }
1,450
40.457143
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/callerprincipal/MDBLifecycleCallback.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.callerprincipal; import java.security.Principal; import jakarta.annotation.PostConstruct; import jakarta.annotation.Resource; import jakarta.ejb.ActivationConfigProperty; import jakarta.ejb.EJBException; import jakarta.ejb.MessageDriven; import jakarta.ejb.MessageDrivenBean; import jakarta.ejb.MessageDrivenContext; import jakarta.jms.DeliveryMode; import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.jms.ObjectMessage; import jakarta.jms.Queue; import jakarta.jms.QueueConnection; import jakarta.jms.QueueConnectionFactory; import jakarta.jms.QueueSender; import jakarta.jms.QueueSession; import javax.naming.NamingException; import org.jboss.ejb3.annotation.SecurityDomain; import org.jboss.logging.Logger; @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/queue/callerPrincipal") }) @SecurityDomain("ejb3-tests") public class MDBLifecycleCallback implements MessageDrivenBean, MessageListener { private static final long serialVersionUID = 1L; private static final Logger log = Logger.getLogger(MDBLifecycleCallback.class); @Resource(mappedName = "java:/ConnectionFactory") private QueueConnectionFactory qFactory; private MessageDrivenContext msgContext; private ITestResultsSingleton getSingleton() throws NamingException { return (ITestResultsSingleton) msgContext.lookup("java:global/single/" + TestResultsSingleton.class.getSimpleName()); } @PostConstruct public void init() throws Exception { ITestResultsSingleton results = this.getSingleton(); log.trace(MDBLifecycleCallback.class.getSimpleName() + " @PostConstruct called"); Principal princ = null; try { princ = msgContext.getCallerPrincipal(); } catch (IllegalStateException e) { results.setMdb("postconstruct", "OKstart"); return; } results.setMdb("postconstruct", "Method getCallerPrincipal was called from @PostConstruct with result: " + princ); } @Override public void ejbRemove() throws EJBException { try { ITestResultsSingleton results = this.getSingleton(); log.trace(MDBLifecycleCallback.class.getSimpleName() + " @PreDestroy called"); Principal princ = null; try { princ = msgContext.getCallerPrincipal(); } catch (IllegalStateException e) { results.setMdb("predestroy", "OKstop"); return; } results.setMdb("predestroy", "Method getCallerPrincipal was called from @PreDestroy with result: " + princ); } catch (Exception e) { throw new RuntimeException(e); } } @Resource @Override public void setMessageDrivenContext(MessageDrivenContext ctx) throws EJBException { this.msgContext = ctx; } public void onMessage(Message message) { //log.trace("onMessage received msg: " + message.toString()); try { try { sendReply((Queue) message.getJMSReplyTo(), message.getJMSMessageID(), null); } catch (Exception e) { sendReply((Queue) message.getJMSReplyTo(), message.getJMSMessageID(), e); } } catch (JMSException e) { throw new RuntimeException(e); } } private void sendReply(Queue destination, String messageID, Exception e) throws JMSException { QueueConnection conn = qFactory.createQueueConnection(); try { QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); QueueSender sender = session.createSender(destination); ObjectMessage message = session.createObjectMessage(e == null ? "SUCCESS" : e); message.setJMSCorrelationID(messageID); sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500); } finally { conn.close(); } } }
5,241
37.544118
125
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/lifecycle/BaseBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.lifecycle; import jakarta.ejb.EJBContext; /** * The base class for calling the four EJBContext methods. * * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ public abstract class BaseBean { private static final String DEFAULT_ROLE = "Users"; public static final String GET_CALLER_PRINCIPAL = "getCallerPrincipal()"; public static final String IS_CALLER_IN_ROLE = "isCallerInRole(String)"; public static final String DEPENDENCY_INJECTION = "Dependency Injection"; public static final String LIFECYCLE_CALLBACK = "Lifecycle Callback"; public static final String BUSINESS = "Business"; public static final String AFTER_BEGIN = "After Begin"; public abstract EJBContext getEJBContext(); private String callGetCallerPrincipal() { try { return getEJBContext().getCallerPrincipal().getName(); } catch (Exception e) { return e.getClass().getSimpleName(); } } private String callIsCallerInRole() { try { return Boolean.toString(getEJBContext().isCallerInRole(DEFAULT_ROLE)); } catch (Exception e) { return e.getClass().getSimpleName(); } } void performTests(final String beanMethod) { ResultHolder.addResult(beanMethod, GET_CALLER_PRINCIPAL, callGetCallerPrincipal()); ResultHolder.addResult(beanMethod, IS_CALLER_IN_ROLE,callIsCallerInRole()); } }
2,531
34.661972
91
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/lifecycle/StatefulBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.lifecycle; import jakarta.ejb.AfterBegin; import jakarta.ejb.Stateful; import org.jboss.ejb3.annotation.SecurityDomain; /** * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ @Stateful @SecurityDomain("ejb3-tests") public class StatefulBean extends SessionBean { @AfterBegin public void afterBegin() { performTests(AFTER_BEGIN); } }
1,465
33.904762
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/lifecycle/EntryBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.lifecycle; import java.util.Map; import jakarta.annotation.Resource; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; import org.jboss.ejb3.annotation.SecurityDomain; /** * The main bean to call the beans being tested and return the results. * * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ @Stateless @SecurityDomain("ejb3-tests") public class EntryBean { @Resource private SessionContext sessionContext; public Map<String, String> testStatefulBean() { return testSessionBean("java:global/ejb3security/StatefulBean"); } public Map<String, String> testStatlessBean() { return testSessionBean("java:global/ejb3security/StatelessBean"); } private Map<String, String> testSessionBean(final String jndiName) { ResultHolder.reset(); SessionBean sessionBean = (SessionBean) sessionContext.lookup(jndiName); sessionBean.business(); sessionBean.remove(); return ResultHolder.getResults(); } }
2,113
32.555556
80
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/lifecycle/SessionBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.lifecycle; import jakarta.annotation.PostConstruct; import jakarta.annotation.Resource; import jakarta.ejb.EJBContext; import jakarta.ejb.Remove; import jakarta.ejb.SessionContext; /** * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ public abstract class SessionBean extends BaseBean { private SessionContext sessionContext; public EJBContext getEJBContext() { return sessionContext; } // TODO - Why do I need to override this method. public void performTests(final String beanMethod) { super.performTests(beanMethod); } @Resource public void setSessionContext(SessionContext sessionContext) { this.sessionContext = sessionContext; performTests(DEPENDENCY_INJECTION); } @PostConstruct public void postConstruct() { performTests(LIFECYCLE_CALLBACK); } public void business() { performTests(BUSINESS); } @Remove public void remove() { } // TODO - Work out how to fit in afterCompletion. }
2,128
30.308824
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/lifecycle/ResultHolder.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.lifecycle; import java.util.Collections; import java.util.HashMap; import java.util.Map; /** * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ public class ResultHolder { private static final Map<String, String> results = new HashMap<String, String>(); static void reset() { results.clear(); } static void addResult(final String beanMethod, final String ejbContextMethod, final String result) { results.put(beanMethod + ":" + ejbContextMethod, result); } static Map<String, String> getResults() { return Collections.unmodifiableMap(results); } }
1,713
34.708333
104
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/lifecycle/StatelessBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.lifecycle; import jakarta.ejb.Stateless; import org.jboss.ejb3.annotation.SecurityDomain; /** * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ @Stateless @SecurityDomain("ejb3-tests") public class StatelessBean extends SessionBean { }
1,347
37.514286
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/jbossappxml/JBossAppXMLSecurityTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.jbossappxml; import javax.naming.Context; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.categories.CommonCriteria; import org.jboss.as.test.integration.ejb.security.EjbSecurityDomainSetup; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; /** * Unit test the security mappings from jboss-app.xml * @author anil saldhana */ @RunWith(Arquillian.class) @RunAsClient @SuppressWarnings({"rawtypes","unchecked"}) @ServerSetup(JBossAppXMLSecurityTestCase.JBossAppXMLSecurityTestCaseSetup.class) @Category(CommonCriteria.class) public class JBossAppXMLSecurityTestCase { private static final String APP_NAME = "myapp"; private static final String DISTINCT_NAME = ""; private static final String MODULE_NAME = "jboss-app-xml-sec"; private static final Logger logger = Logger.getLogger(JBossAppXMLSecurityTestCase.class); @ArquillianResource private Context context; static class JBossAppXMLSecurityTestCaseSetup extends EjbSecurityDomainSetup { @Override public boolean isUsersRolesRequired() { return false; } @Override protected String getSecurityDomainName() { return "mydomain"; } } @Deployment(testable = false) // the incorrectly named "testable" attribute tells Arquillian whether or not // it should add Arquillian specific metadata to the archive (which ultimately transforms it to a WebArchive). // We don't want that, so set that flag to false public static Archive createDeployment() { final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear"); ear.addAsManifestResource(JBossAppXMLSecurityTestCase.class.getPackage(), "jboss-app.xml", "jboss-app.xml"); final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar"); jar.addClasses(BeanInterface.class,FirstBean.class, SecondBean.class); jar.addPackage(CommonCriteria.class.getPackage()); jar.addAsManifestResource(JBossAppXMLSecurityTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml"); ear.addAsModule(jar); return ear; } @Test public void testEJBRunAs() throws Exception { final BeanInterface firstBean = (BeanInterface) context.lookup("ejb:" + APP_NAME + "/" + MODULE_NAME + "/" + DISTINCT_NAME + "/" + FirstBean.class.getSimpleName() + "!" + BeanInterface.class.getName()); assertNotNull("Lookup returned a null bean proxy", firstBean); String callerPrincipal = firstBean.getCallerPrincipal(); assertNotNull(callerPrincipal); assertEquals("javajoe", callerPrincipal); assertTrue(firstBean.isCallerInRole("Manager")); } }
4,477
42.475728
130
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/jbossappxml/SecondBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.jbossappxml; import jakarta.annotation.Resource; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.LocalBean; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; /** * EJB3 bean that returns the current caller principal * @author anil saldhana */ @Stateless @RolesAllowed("Employee") @LocalBean public class SecondBean implements BeanInterface{ @Resource private SessionContext context; public String getCallerPrincipal(){ return context.getCallerPrincipal().getName(); } @Override public boolean isCallerInRole(String roleName) { return context.isCallerInRole(roleName); } }
1,730
35.0625
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/jbossappxml/BeanInterface.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.jbossappxml; /** * @author anil saldhana */ public interface BeanInterface { String getCallerPrincipal(); boolean isCallerInRole(String roleName); }
1,233
40.133333
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/jbossappxml/FirstBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.jbossappxml; import org.jboss.ejb3.annotation.RunAsPrincipal; import jakarta.annotation.security.RunAs; import jakarta.ejb.EJB; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; /** * Simple EJB3 bean that calls another bean with a run as * * @author anil saldhana */ @RunAs("Employee") @RunAsPrincipal("javajoe") @Stateless @Remote(BeanInterface.class) public class FirstBean implements BeanInterface { @EJB private SecondBean secondBean; public String getCallerPrincipal() { return secondBean.getCallerPrincipal(); } @Override public boolean isCallerInRole(String roleName) { return secondBean.isCallerInRole(roleName); } }
1,761
31.62963
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/RunAsTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.security.Principal; import java.util.concurrent.Callable; import org.jboss.logging.Logger; import jakarta.ejb.EJB; import jakarta.ejb.EJBAccessException; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.test.categories.CommonCriteria; import org.jboss.as.test.integration.common.HttpRequest; import org.jboss.as.test.integration.ejb.security.EjbSecurityDomainSetup; import org.jboss.as.test.integration.ejb.security.Entry; import org.jboss.as.test.integration.ejb.security.WhoAmI; import org.jboss.as.test.integration.ejb.security.base.WhoAmIBean; import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup; import org.jboss.as.test.shared.integration.ejb.security.Util; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; /** * Test case to test the requirements related to the handling of a RunAs identity. * * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ @RunWith(Arquillian.class) @ServerSetup({EjbSecurityDomainSetup.class}) @Category(CommonCriteria.class) public class RunAsTestCase { private static final Logger log = Logger.getLogger(RunAsTestCase.class.getName()); @ArquillianResource InitialContext ctx; @EJB(mappedName = "java:global/ejb3security/WhoAmIBean!org.jboss.as.test.integration.ejb.security.WhoAmI") private WhoAmI whoAmIBean; @EJB(mappedName = "java:global/ejb3security/EntryBean!org.jboss.as.test.integration.ejb.security.runas.EntryBean") private EntryBean entryBean; /* * isCallerInRole Scenarios with @RunAs Defined * * EJB 3.1 FR 17.2.5.2 isCallerInRole tests the principal that represents the caller of the enterprise bean, not the * principal that corresponds to the run-as security identity for the bean. */ @Deployment public static Archive<?> runAsDeployment() { final Package currentPackage = RunAsTestCase.class.getPackage(); // using JavaArchive doesn't work, because of a bug in Arquillian, it only deploys wars properly final WebArchive war = ShrinkWrap.create(WebArchive.class, "ejb3security.war") .addPackage(WhoAmIBean.class.getPackage()).addPackage(EntryBean.class.getPackage()) .addPackage(HttpRequest.class.getPackage()).addClass(WhoAmI.class).addClass(Util.class).addClass(Entry.class) .addClasses(AbstractSecurityDomainSetup.class, EjbSecurityDomainSetup.class) .addAsResource(currentPackage, "users.properties", "users.properties") .addAsResource(currentPackage, "roles.properties", "roles.properties") .addAsWebInfResource(currentPackage, "web.xml", "web.xml") .addAsWebInfResource(currentPackage, "jboss-web.xml", "jboss-web.xml") .addAsWebInfResource(currentPackage, "jboss-ejb3.xml", "jboss-ejb3.xml") .addAsManifestResource(new StringAsset("Manifest-Version: 1.0\nDependencies: org.jboss.as.controller-client,org.jboss.dmr\n"), "MANIFEST.MF") .addAsManifestResource(currentPackage, "permissions.xml", "permissions.xml"); war.addPackage(CommonCriteria.class.getPackage()); return war; } @Test public void testAuthentication_TwoBeans() throws Exception { final Callable<Void> callable = () -> { String[] response = entryBean.doubleWhoAmI(); assertEquals("user1", response[0]); assertEquals("anonymous", response[1]); //Unless a run-as-principal configuration has been done, you cannot expect a principal return null; }; Util.switchIdentity("user1", "password1", callable); } @Test public void testRunAsICIR_TwoBeans() throws Exception { Callable<Void> callable = () -> { // TODO - Enable once auth checks are working. /* * try { whoAmIBean.getCallerPrincipal(); fail("Expected call to whoAmIBean to fail"); } catch (Exception expected) * { } */ boolean[] response; response = entryBean.doubleDoIHaveRole("Users"); assertTrue(response[0]); assertFalse(response[1]); response = entryBean.doubleDoIHaveRole("Role1"); assertTrue(response[0]); assertFalse(response[1]); response = entryBean.doubleDoIHaveRole("Role2"); assertFalse(response[0]); assertTrue(response[1]); return null; }; Util.switchIdentity("user1", "password1", callable); callable = () -> { // Verify the call now passes. Principal user = whoAmIBean.getCallerPrincipal(); assertNotNull(user); boolean[] response; response = entryBean.doubleDoIHaveRole("Users"); assertTrue(response[0]); assertFalse(response[1]); response = entryBean.doubleDoIHaveRole("Role1"); assertFalse(response[0]); assertFalse(response[1]); response = entryBean.doubleDoIHaveRole("Role2"); assertTrue(response[0]); assertTrue(response[1]); return null; }; Util.switchIdentity("user2", "password2", callable); } @Test public void testOnlyRole1() { try { entryBean.callOnlyRole1(); fail("Expected EJBAccessException"); } catch (EJBAccessException e) { // good } } /** * Migration test from EJB Testsuite (security/TimerRunAs) to AS7 [JBQA-5483]. */ @Test public void testTimerNoSecurityAssociationPrincipal() throws Exception { final Callable<Void> callable = () -> { TimerTester test = (TimerTester) ctx.lookup("java:module/" + TimerTesterBean.class.getSimpleName()); assertNotNull(test); test.startTimer(150); Assert.assertTrue(TimerTesterBean.awaitTimerCall()); Assert.assertEquals("user2", TimerTesterBean.calleeCallerPrincipal.iterator().next().getName()); return null; }; Util.switchIdentity("user1", "password1", callable); } }
7,961
40.685864
157
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/EntryBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas; import static jakarta.ejb.TransactionAttributeType.SUPPORTS; import jakarta.annotation.security.RunAs; import jakarta.ejb.EJB; import jakarta.ejb.LocalBean; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionAttribute; import org.jboss.as.test.integration.ejb.security.Entry; import org.jboss.ejb3.annotation.SecurityDomain; /** * Concrete implementation to allow deployment of bean. * * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ @Stateless @LocalBean @RunAs("Role2") @TransactionAttribute(SUPPORTS) @SecurityDomain("ejb3-tests") public class EntryBean extends org.jboss.as.test.integration.ejb.security.base.EntryBean implements Entry { @EJB private WhoAmIBean whoAmIBean; public void callOnlyRole1() { whoAmIBean.onlyRole1(); } }
1,893
34.735849
107
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/UncheckedStatelessBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas; import java.security.Principal; import java.util.HashSet; import java.util.Set; import jakarta.annotation.Resource; import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RunAs; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; import org.jboss.as.ejb3.context.SessionContextImpl; import org.jboss.ejb3.annotation.SecurityDomain; import org.jboss.logging.Logger; import org.wildfly.security.auth.principal.NamePrincipal; import org.wildfly.security.authz.Roles; /** * @author <a href="mailto:[email protected]">William DeCoste</a> */ @Stateless @RunAs("nobody") @SecurityDomain("ejb3-tests") public class UncheckedStatelessBean { private static final Logger log = Logger.getLogger(UncheckedStatelessBean.class); @Resource private SessionContext ctx; @PermitAll public Set<Principal> unchecked() { org.wildfly.security.auth.server.SecurityDomain securityDomain = org.wildfly.security.auth.server.SecurityDomain.getCurrent(); if (securityDomain != null) { final Roles roles = ((SessionContextImpl) ctx).getComponent().getIncomingRunAsIdentity().getRoles("ejb"); final HashSet<Principal> rolesSet = new HashSet<>(); if (roles != null) { roles.forEach(role -> rolesSet.add(new NamePrincipal(role.toString()))); } return rolesSet; } else { throw new IllegalStateException("Legacy security has been removed"); } } }
2,589
37.656716
134
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/TimerTesterBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas; import java.security.Principal; import java.util.Date; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import jakarta.annotation.Resource; import jakarta.annotation.security.RunAs; import jakarta.ejb.Remote; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; import jakarta.ejb.Timeout; import jakarta.ejb.Timer; import jakarta.ejb.TimerService; import javax.naming.InitialContext; import org.jboss.ejb3.annotation.SecurityDomain; import org.jboss.logging.Logger; /** * @author <a href="mailto:[email protected]">Bill Burke</a> */ @Stateless @Remote(TimerTester.class) @RunAs("user2") @SecurityDomain("ejb3-tests") public class TimerTesterBean implements TimerTester { private static final Logger log = Logger.getLogger(TimerTesterBean.class); private static final CountDownLatch latch = new CountDownLatch(1); public static boolean timerCalled = false; public static Principal callerPrincipal = null; public static Set<Principal> calleeCallerPrincipal = null; @Resource private TimerService timerService; @Resource private SessionContext ctx; public void startTimer(long pPeriod) { timerCalled = false; timerService.createTimer(new Date(System.currentTimeMillis() + pPeriod), null); } public static boolean awaitTimerCall() { try { latch.await(2, TimeUnit.SECONDS); } catch (InterruptedException e) { throw new RuntimeException(e); } return timerCalled; } @Timeout public void timeoutHandler(Timer timer) { callerPrincipal = ctx.getCallerPrincipal(); log.trace("timeoutHanlder() - getCallerPrincipal: " + callerPrincipal); try { UncheckedStatelessBean tester = (UncheckedStatelessBean) new InitialContext().lookup("java:module/" + UncheckedStatelessBean.class.getSimpleName()); calleeCallerPrincipal = tester.unchecked(); log.trace("callee: " + calleeCallerPrincipal); timerCalled = true; } catch (Exception e) { log.error(e); } } }
3,257
32.9375
111
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/WhoAmIBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas; import static jakarta.ejb.TransactionAttributeType.SUPPORTS; import java.security.Principal; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.LocalBean; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionAttribute; import org.jboss.as.test.integration.ejb.security.WhoAmI; import org.jboss.ejb3.annotation.SecurityDomain; /** * Concrete implementation to allow deployment of bean. * * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ @Stateless @LocalBean @RolesAllowed("Role2") @TransactionAttribute(SUPPORTS) @SecurityDomain("ejb3-tests") public class WhoAmIBean extends org.jboss.as.test.integration.ejb.security.base.WhoAmIBean implements WhoAmI { // TODO - Do I really need to override methods and do they really need to be annotated individually. @Override @RolesAllowed("Role2") public Principal getCallerPrincipal() { return super.getCallerPrincipal(); } @Override @RolesAllowed("Role2") public boolean doIHaveRole(String roleName) { return super.doIHaveRole(roleName); } @RolesAllowed("Role1") public void onlyRole1() { throw new AssertionError("Should not come here"); } }
2,308
33.462687
110
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/TimerTester.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas; /** * @author <a href="mailto:[email protected]">Bill Burke</a> */ public interface TimerTester { void startTimer(long pPeriod); }
1,220
39.7
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/propagation/ServerCallerInRole.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.propagation; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.annotation.Resource; import jakarta.annotation.security.PermitAll; import jakarta.ejb.Remote; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; /** * @author tmiyar * */ @Stateless @Remote(CallerInRole.class) @SecurityDomain("ejbtest-domain") @PermitAll public class ServerCallerInRole implements CallerInRole { @Resource private SessionContext context; @Override public Boolean isCallerInRole(String role) { return context.isCallerInRole(role); } }
1,668
31.72549
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/propagation/CallerInRole.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.propagation; import jakarta.ejb.Remote; /** * @author tmiyar * */ @Remote public interface CallerInRole { Boolean isCallerInRole(String role); }
1,245
33.611111
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/propagation/IntermediateCallerInRole.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.propagation; import jakarta.annotation.Resource; import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RunAs; import jakarta.ejb.EJB; import jakarta.ejb.Remote; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; import org.jboss.ejb3.annotation.RunAsPrincipal; import org.jboss.ejb3.annotation.SecurityDomain; /** * @author tmiyar */ @Stateless @Remote(IntermediateCallerInRoleRemote.class) @SecurityDomain("ejbtest-domain") @PermitAll @RunAsPrincipal("user2") @RunAs("role2") public class IntermediateCallerInRole implements IntermediateCallerInRoleRemote { @Resource private SessionContext context; @EJB(lookup = "ejb:/ejb-security-context-propagation/ServerCallerInRole!org.jboss.as.test.integration.ejb.security.runas.propagation.CallerInRole") private CallerInRole callerInRole; @Override public Boolean isCallerInRole(String role) { return context.isCallerInRole(role); } @Override public Boolean isServerCallerInRole(String role) { return callerInRole.isCallerInRole(role); } }
2,181
33.634921
151
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/propagation/IntermediateCallerInRoleRemote.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.propagation; import jakarta.ejb.Remote; /** * @author tmiyar */ @Remote public interface IntermediateCallerInRoleRemote { Boolean isCallerInRole(String role); Boolean isServerCallerInRole(String role); }
1,308
34.378378
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/propagation/RunAsWithElytronEJBContextPropagationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.propagation; import java.io.File; import java.util.Properties; import javax.naming.Context; import javax.naming.NamingException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.naming.InitialContext; import org.jboss.as.test.integration.management.base.AbstractCliTestBase; import org.jboss.as.test.shared.CLIServerSetupTask; import org.jboss.as.test.shared.TestSuiteEnvironment; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.naming.client.WildFlyInitialContextFactory; /** * Testing EJB Elytron security context propagation with @RunAs annotation, using outbound connection to connect to back to this * server. Test for WFLY-11094 * * @author tmiyar * */ @RunWith(Arquillian.class) @ServerSetup(RunAsWithElytronEJBContextPropagationTestCase.ServerSetupTask.class) @RunAsClient public class RunAsWithElytronEJBContextPropagationTestCase extends AbstractCliTestBase { private static final String EJB_TEST_MODULE_NAME = "ejb-security-context-propagation"; private static final String DEFAULT_CONNECTION_SERVER = "jboss"; private static final String ORIGINAL_USERS_PATH = "application-users.properties"; private static final String ORIGINAL_ROLES_PATH = "application-roles.properties"; private static final String RELATIVE_TO = "jboss.server.config.dir"; private static final String USERNAME = "user1"; private static final String PASSWORD = "password1"; private static final String ROLE = "role2"; private static boolean removeRealmProperties = false; // Avoid problem on windows with path private static final String USERS_PATH = new File( RunAsWithElytronEJBContextPropagationTestCase.class.getResource("users.properties").getFile()).getAbsolutePath() .replace("\\", "/"); private static final String ROLES_PATH = new File( RunAsWithElytronEJBContextPropagationTestCase.class.getResource("roles.properties").getFile()).getAbsolutePath() .replace("\\", "/"); @Deployment(name = EJB_TEST_MODULE_NAME, managed = true, testable = false) public static Archive<?> createEjbClientDeployment() { final JavaArchive ejbClientJar = ShrinkWrap.create(JavaArchive.class, EJB_TEST_MODULE_NAME + ".jar"); ejbClientJar.addClass(IntermediateCallerInRole.class).addClass(IntermediateCallerInRoleRemote.class) .addClass(CallerInRole.class).addClass(ServerCallerInRole.class).addAsManifestResource( IntermediateCallerInRole.class.getPackage(), "jboss-ejb-client.xml", "jboss-ejb-client.xml"); return ejbClientJar; } /** * Test that checks the first EJB is called by admin role, same user is used to call the second EJB were the role does not * change. * * The test uses http-remoting protocol. */ @Test public void testRunAsWithElytronEJBContextPropagation() { InitialContext context = initContext(); IntermediateCallerInRoleRemote intermediate; try { intermediate = (IntermediateCallerInRoleRemote) context .lookup("ejb:/ejb-security-context-propagation/IntermediateCallerInRole!" + IntermediateCallerInRoleRemote.class.getName()); } catch (NamingException e) { throw new RuntimeException(e); } Assert.assertFalse(intermediate.isCallerInRole(ROLE)); Assert.assertTrue(intermediate.isServerCallerInRole(ROLE)); closeContext(context); } private InitialContext initContext() { Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName()); props.put(Context.PROVIDER_URL, "remote+http://" + TestSuiteEnvironment.getServerAddress() + ":8080"); props.put(Context.SECURITY_PRINCIPAL, USERNAME); props.put(Context.SECURITY_CREDENTIALS, PASSWORD); try { return new InitialContext(props); } catch (NamingException e) { throw new RuntimeException(e); } } private void closeContext(InitialContext context) { try { context.close(); } catch (NamingException e) { throw new RuntimeException(e); } } public static class ServerSetupTask extends CLIServerSetupTask { public ServerSetupTask() { this.builder.node(DEFAULT_CONNECTION_SERVER) .setup("/subsystem=ejb3/application-security-domain=ejbtest-domain:add(security-domain=ApplicationDomain)") .setup("/subsystem=elytron/authentication-configuration=ejb-outbound-configuration:add(authentication-name=user2,security-domain=ApplicationDomain,realm=ApplicationRealm,forwarding-mode=authorization,credential-reference={clear-text=password2})") .setup("/subsystem=elytron/authentication-context=ejb-outbound-context:add(match-rules=[{authentication-configuration=ejb-outbound-configuration,match-no-user=true}])") .setup(String.format("/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=ejb-outbound:add(host=\"%s\",port=8080)", TestSuiteEnvironment.getServerAddress())) .setup("/subsystem=remoting/remote-outbound-connection=ejb-outbound-connection:add(outbound-socket-binding-ref=ejb-outbound,authentication-context=ejb-outbound-context)") .setup("/subsystem=elytron/sasl-authentication-factory=application-sasl-authentication:write-attribute(name=mechanism-configurations,value=[{mechanism-name=PLAIN},{mechanism-name=JBOSS-LOCAL-USER,realm-mapper=local},{mechanism-name=DIGEST-MD5,mechanism-realm-configurations=[{realm-name=ApplicationRealm}]}])") .setup(String.format( "/subsystem=elytron/properties-realm=ApplicationRealm:write-attribute(name=users-properties.path,value=\"%s\")", USERS_PATH)) .setup("/subsystem=elytron/properties-realm=ApplicationRealm:write-attribute(name=users-properties.plain-text,value=true)") .setup("/subsystem=elytron/properties-realm=ApplicationRealm:undefine-attribute(name=users-properties.relative-to)") .setup(String.format( "/subsystem=elytron/properties-realm=ApplicationRealm:write-attribute(name=groups-properties.path,value=\"%s\")", ROLES_PATH)) .setup("/subsystem=elytron/properties-realm=ApplicationRealm:undefine-attribute(name=groups-properties.relative-to)") .setup("/subsystem=elytron/simple-permission-mapper=auth-forwarding-permission-mapper:add(permission-mappings=[{principals=[anonymous]}," + "{principals=[user2],permissions=[{class-name=org.wildfly.security.auth.permission.RunAsPrincipalPermission,target-name=*},{class-name=org.wildfly.security.auth.permission.LoginPermission},{class-name=org.wildfly.extension.batch.jberet.deployment.BatchPermission," + "module=org.wildfly.extension.batch.jberet,target-name=*},{class-name=org.wildfly.transaction.client.RemoteTransactionPermission,module=org.wildfly.transaction.client},{class-name=org.jboss.ejb.client.RemoteEJBPermission,module=org.jboss.ejb-client}]},{match-all=true,permissions=[{class-name=org.wildfly.security.auth.permission.LoginPermission}," + "{class-name=org.wildfly.extension.batch.jberet.deployment.BatchPermission,module=org.wildfly.extension.batch.jberet,target-name=*},{class-name=org.wildfly.transaction.client.RemoteTransactionPermission,module=org.wildfly.transaction.client},{class-name=org.jboss.ejb.client.RemoteEJBPermission,module=org.jboss.ejb-client}]}])") .setup("/subsystem=elytron/security-domain=ApplicationDomain:write-attribute(name=permission-mapper,value=auth-forwarding-permission-mapper)") .teardown( "/subsystem=elytron/sasl-authentication-factory=application-sasl-authentication:write-attribute(name=mechanism-configurations,value=[{mechanism-name=JBOSS-LOCAL-USER,realm-mapper=local},{mechanism-name=DIGEST-MD5,mechanism-realm-configurations=[{realm-name=ApplicationRealm}]}])") .teardown("/subsystem=remoting/remote-outbound-connection=ejb-outbound-connection:remove") .teardown( "/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=ejb-outbound:remove") .teardown("/subsystem=elytron/authentication-context=ejb-outbound-context:remove") .teardown("/subsystem=elytron/authentication-configuration=ejb-outbound-configuration:remove") .teardown("/subsystem=ejb3/application-security-domain=ejbtest-domain:remove") .teardown(String.format( "/subsystem=elytron/properties-realm=ApplicationRealm:write-attribute(name=users-properties.path,value=\"%s\")", ORIGINAL_USERS_PATH)) .teardown(String.format( "/subsystem=elytron/properties-realm=ApplicationRealm:write-attribute(name=users-properties.relative-to,value=\"%s\")", RELATIVE_TO)) .teardown( "/subsystem=elytron/properties-realm=ApplicationRealm:undefine-attribute(name=users-properties.plain-text)") .teardown(String.format( "/subsystem=elytron/properties-realm=ApplicationRealm:write-attribute(name=groups-properties.path,value=\"%s\")", ORIGINAL_ROLES_PATH)) .teardown(String.format( "/subsystem=elytron/properties-realm=ApplicationRealm:write-attribute(name=groups-properties.relative-to,value=\"%s\")", RELATIVE_TO)) .teardown( "/subsystem=elytron/security-domain=ApplicationDomain:write-attribute(name=permission-mapper,value=default-permission-mapper)") .teardown("/subsystem=elytron/simple-permission-mapper=auth-forwarding-permission-mapper:remove()"); } } }
11,803
62.122995
378
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/mdb/RunAsMDBUnitTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.mdb; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import jakarta.jms.Connection; import jakarta.jms.ConnectionFactory; import jakarta.jms.DeliveryMode; import jakarta.jms.Message; import jakarta.jms.MessageConsumer; import jakarta.jms.MessageProducer; import jakarta.jms.ObjectMessage; import jakarta.jms.Queue; import jakarta.jms.Session; import jakarta.jms.TemporaryQueue; import jakarta.jms.TextMessage; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.categories.CommonCriteria; import org.jboss.as.test.integration.common.jms.JMSOperations; import org.jboss.as.test.integration.common.jms.JMSOperationsProvider; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.wildfly.security.auth.permission.ChangeRoleMapperPermission; import org.wildfly.security.permission.ElytronPermission; /** * Make sure the run-as on a MDB is picked up. * Part of migration test from EAP5 (JBAS-6239) to AS7 [JBQA-5275]. * * @author Carlo de Wolf, Ondrej Chaloupka */ @RunWith(Arquillian.class) @ServerSetup({RunAsMDBUnitTestCase.JmsQueueSetup.class}) @Category(CommonCriteria.class) public class RunAsMDBUnitTestCase { private static final Logger log = Logger.getLogger(RunAsMDBUnitTestCase.class.getName()); private static final String queueName = "queue/mdbtest"; static class JmsQueueSetup implements ServerSetupTask { private JMSOperations jmsAdminOperations; @Override public void setup(ManagementClient managementClient, String containerId) throws Exception { jmsAdminOperations = JMSOperationsProvider.getInstance(managementClient); jmsAdminOperations.createJmsQueue(queueName, "java:jboss/" + queueName); } @Override public void tearDown(ManagementClient managementClient, String containerId) throws Exception { if (jmsAdminOperations != null) { jmsAdminOperations.removeJmsQueue(queueName); jmsAdminOperations.close(); } } } @ArquillianResource InitialContext ctx; @Deployment public static Archive<?> deploy() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "runas-mdb.jar") .addPackage(RunAsMDBUnitTestCase.class.getPackage()) .addPackage(JMSOperations.class.getPackage()) .addClass(JmsQueueSetup.class); jar.addAsManifestResource(RunAsMDBUnitTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml"); jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client,org.jboss.dmr \n"), "MANIFEST.MF"); jar.addPackage(CommonCriteria.class.getPackage()); // TODO WFLY-15289 Should these permissions be required? jar.addAsResource(createPermissionsXmlAsset(new ElytronPermission("setRunAsPrincipal"), new ElytronPermission("handleSecurityEvent"), new ChangeRoleMapperPermission("ejb")), "META-INF/jboss-permissions.xml"); return jar; } protected <T> T lookup(String name, Class<T> cls) throws Exception { return cls.cast(ctx.lookup(name)); } @Test public void testSendMessage() throws Exception { ConnectionFactory connFactory = lookup("ConnectionFactory", ConnectionFactory.class); Connection conn = connFactory.createConnection(); conn.start(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); TemporaryQueue replyQueue = session.createTemporaryQueue(); TextMessage msg = session.createTextMessage("Hello world"); msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); msg.setJMSReplyTo(replyQueue); Queue queue = lookup("java:jboss/" + queueName, Queue.class); MessageProducer producer = session.createProducer(queue); producer.send(msg); MessageConsumer consumer = session.createConsumer(replyQueue); Message replyMsg = consumer.receive(5000); Assert.assertNotNull(replyMsg); if (replyMsg instanceof ObjectMessage) { Exception e = (Exception) ((ObjectMessage) replyMsg).getObject(); throw e; } Assert.assertTrue(replyMsg instanceof TextMessage); String actual = ((TextMessage) replyMsg).getText(); Assert.assertEquals("SUCCESS", actual); consumer.close(); producer.close(); session.close(); conn.close(); } }
6,224
41.636986
131
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/mdb/MyStateless.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.mdb; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ public interface MyStateless { String getState(); void setState(String state); }
1,253
38.1875
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/mdb/QueueTestMDB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.mdb; import jakarta.annotation.Resource; import jakarta.annotation.security.RunAs; import jakarta.ejb.ActivationConfigProperty; import jakarta.ejb.EJB; import jakarta.ejb.MessageDriven; import jakarta.jms.DeliveryMode; import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.jms.ObjectMessage; import jakarta.jms.Queue; import jakarta.jms.QueueConnection; import jakarta.jms.QueueConnectionFactory; import jakarta.jms.QueueSender; import jakarta.jms.QueueSession; import jakarta.jms.TextMessage; import org.jboss.ejb3.annotation.SecurityDomain; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/queue/mdbtest") }) @RunAs("TestRole") @SecurityDomain(value = "other", unauthenticatedPrincipal = "user") public class QueueTestMDB implements MessageListener { @Resource(mappedName = "java:/ConnectionFactory") private QueueConnectionFactory qFactory; @EJB MyStateless bean; public void onMessage(Message message) { try { try { bean.setState(((TextMessage) message).getText()); sendReply((Queue) message.getJMSReplyTo(), message.getJMSMessageID()); } catch (Exception e) { sendReply((Queue) message.getJMSReplyTo(), message.getJMSMessageID(), e); } } catch (JMSException e) { throw new RuntimeException(e); } } private void sendReply(Queue destination, String messageID) throws JMSException { QueueConnection conn = qFactory.createQueueConnection(); try { QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); QueueSender sender = session.createSender(destination); TextMessage message = session.createTextMessage("SUCCESS"); message.setJMSCorrelationID(messageID); sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500); } finally { conn.close(); } } private void sendReply(Queue destination, String messageID, Exception e) throws JMSException { QueueConnection conn = qFactory.createQueueConnection(); try { QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); QueueSender sender = session.createSender(destination); ObjectMessage message = session.createObjectMessage(e); message.setJMSCorrelationID(messageID); sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500); } finally { conn.close(); } } }
3,941
39.639175
110
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/mdb/StatelessBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.mdb; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; import org.jboss.ejb3.annotation.SecurityDomain; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @Stateless @Remote(MyStateless.class) @SecurityDomain("other") public class StatelessBean implements MyStateless { // static so it's shared by all private static String state; @RolesAllowed("anyone") public String getState() { return state; } @RolesAllowed("TestRole") public void setState(String state) { StatelessBean.state = state; } }
1,709
33.2
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/ejb2mdb/HolaBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.ejb2mdb; import jakarta.annotation.Resource; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.Remote; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; /** * Returns hola greeting for INTERNAL_ROLE. * * @author Ondrej Chaloupka */ @Stateless(name = "Hola") @RolesAllowed({}) @Remote(Hola.class) @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public class HolaBean implements Hola { public static final String SAYING = "Hola"; @Resource private SessionContext context; @RolesAllowed("INTERNAL_ROLE") public String sayHola() { return String.format("%s %s", SAYING, getName()); } private String getName() { return context.getCallerPrincipal().getName(); } }
1,933
32.344828
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/ejb2mdb/HelloBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.ejb2mdb; import jakarta.annotation.Resource; import jakarta.ejb.Remote; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; import jakarta.jms.Connection; import jakarta.jms.ConnectionFactory; import jakarta.jms.JMSException; import jakarta.jms.MessageConsumer; import jakarta.jms.MessageProducer; import jakarta.jms.Queue; import jakarta.jms.Session; import jakarta.jms.TemporaryQueue; import jakarta.jms.TextMessage; import javax.naming.InitialContext; import org.jboss.as.test.shared.TimeoutUtil; import org.jboss.logging.Logger; /** * Bean passes message to HelloMDB bean and checks the reply queue. * * @author Ondrej Chaloupka */ @Stateless(name = "Hello") @Remote(Hello.class) @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public class HelloBean implements Hello { private static final Logger log = Logger.getLogger(HelloBean.class); public static final String SAYING = "Hello"; public static final String QUEUE_NAME = "queue/TestQueue"; public static final String QUEUE_NAME_JNDI = "java:jboss/exported/" + QUEUE_NAME; @Resource private SessionContext context; public String sayHello() throws Exception { InitialContext initialContext = new InitialContext(); try { ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("java:/ConnectionFactory"); String replyMessage = HelloBean.sendMessage(cf); return String.format("%s %s, %s", SAYING, getName(), replyMessage); } finally { initialContext.close(); } } /** * Helper method to send message to {@link #QUEUE_NAME}. */ public static String sendMessage(ConnectionFactory cf) throws Exception { Connection connection = null; try { Queue queue = cf.createContext("guest", "guest").createQueue(QUEUE_NAME); connection = cf.createConnection("guest", "guest"); connection.start(); // we need to start connection for consumer Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer sender = session.createProducer(queue); TextMessage message = session.createTextMessage("hello goodbye"); TemporaryQueue replyQueue = session.createTemporaryQueue(); message.setJMSReplyTo(replyQueue); sender.send(message); log.tracef("Message '%s' sent", message); // consume message processed by MDB MessageConsumer consumer = session.createConsumer(replyQueue); TextMessage replyMessage = (TextMessage) consumer.receive(TimeoutUtil.adjust(5000)); log.tracef("Message '%s' received", replyMessage); if(replyMessage == null) { return "ReplyMessage is 'null'. No response received from HelloMDB." + " Consult server log for details."; } return replyMessage.getText(); } finally { try { if (connection != null) connection.close(); } catch (JMSException jmse) { log.trace("connection close failed", jmse); } } } private String getName() { return context.getCallerPrincipal().getName(); } }
4,474
36.923729
104
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/ejb2mdb/GoodByeHome.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.ejb2mdb; import java.rmi.RemoteException; import jakarta.ejb.CreateException; import jakarta.ejb.EJBHome; /** * @author Ondrej Chaloupka */ public interface GoodByeHome extends EJBHome { GoodBye create() throws RemoteException, CreateException; }
1,340
37.314286
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/ejb2mdb/GoodByeLocal.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.ejb2mdb; import jakarta.ejb.EJBException; import jakarta.ejb.EJBLocalObject; /** * @author Ondrej Chaloupka */ public interface GoodByeLocal extends EJBLocalObject { String sayGoodBye() throws EJBException; }
1,302
37.323529
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/ejb2mdb/Hello.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.ejb2mdb; /** * @author Ondrej Chaloupka */ public interface Hello { String sayHello() throws Exception; }
1,197
38.933333
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/ejb2mdb/HowdyBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.ejb2mdb; import jakarta.annotation.Resource; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.EJB; import jakarta.ejb.Local; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; import jakarta.ejb.TransactionAttribute; import jakarta.ejb.TransactionAttributeType; /** * Returns howdy greeting for INTERNAL_ROLE. * * @author Ondrej Chaloupka */ @Stateless(name = "Howdy") @RolesAllowed("INTERNAL_ROLE") @Local(Howdy.class) @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public class HowdyBean implements Howdy { public static final String SAYING = "Howdy"; @Resource private SessionContext context; @EJB Hola hola; public String sayHowdy() { return String.format("%s %s, %s", SAYING, getName(), hola.sayHola()); } private String getName() { return context.getCallerPrincipal().getName(); } }
1,984
32.083333
77
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/ejb2mdb/GoodByeBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.ejb2mdb; import jakarta.ejb.SessionBean; import jakarta.ejb.SessionContext; /** * Bean returning goodbye greeting. * * @author Ondrej Chaloupka */ public class GoodByeBean implements SessionBean { private static final long serialVersionUID = 1L; public static final String SAYING = "GoodBye"; public String sayGoodBye() { return SAYING; } public void setSessionContext(SessionContext sessionContext) { } public void ejbCreate() { } public void ejbRemove() { } public void ejbActivate() { } public void ejbPassivate() { } }
1,684
29.089286
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/ejb2mdb/Howdy.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.ejb2mdb; /** * @author Ondrej Chaloupka */ public interface Howdy { String sayHowdy(); }
1,181
37.129032
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/ejb2mdb/RunAsEjbMdbTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.ejb2mdb; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.util.PropertyPermission; import jakarta.jms.ConnectionFactory; import javax.naming.InitialContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.arquillian.api.ContainerResource; import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.test.integration.common.jms.JMSOperations; import org.jboss.as.test.integration.common.jms.JMSOperationsProvider; import org.jboss.as.test.shared.TimeoutUtil; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.wildfly.security.auth.permission.ChangeRoleMapperPermission; import org.wildfly.security.permission.ElytronPermission; /** * Test case based on reproducer for <a href="https://issues.jboss.org/browse/JBPAPP-7897">JBPAPP-7897</a> * * Test case checks propagation of role from {@code RunAs} when ejb2, ejb3, mdb beans are part of the chain. * * @author Derek Horton, Ondrej Chaloupka */ @RunWith(Arquillian.class) @RunAsClient @ServerSetup(RunAsEjbMdbTestCase.RunAsTestCaseEJBMDBSetup.class) public class RunAsEjbMdbTestCase { private static final String PRINCIPAL = "anonymous"; @ContainerResource private InitialContext initialContext; static class RunAsTestCaseEJBMDBSetup implements ServerSetupTask { @Override public void setup(final ManagementClient managementClient, final String containerId) throws Exception { final JMSOperations ops = JMSOperationsProvider.getInstance(managementClient.getControllerClient()); ops.createJmsQueue(HelloBean.QUEUE_NAME, HelloBean.QUEUE_NAME_JNDI); } @Override public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception { final JMSOperations ops = JMSOperationsProvider.getInstance(managementClient.getControllerClient()); ops.removeJmsQueue(HelloBean.QUEUE_NAME); } } @Deployment(testable = false, managed = true, name = "ejb2", order = 1) public static Archive<?> runAsEJB2() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "runasmdbejb-ejb2.jar") .addClasses(GoodBye.class, GoodByeBean.class, GoodByeHome.class, GoodByeLocal.class, GoodByeLocalHome.class); jar.addAsManifestResource(RunAsEjbMdbTestCase.class.getPackage(), "ejb-jar-ejb2.xml", "ejb-jar.xml"); return jar; } @Deployment(testable = false, managed = true, name = "ejb3", order = 2) public static Archive<?> runAsEJB3() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "runasmdbejb-ejb3.jar") .addClasses(HelloBean.class, Hello.class, HolaBean.class, Hola.class, Howdy.class, HowdyBean.class, HelloMDB.class, TimeoutUtil.class); // TODO WFLY-15289 Should these permissions be required? jar.addAsResource(createPermissionsXmlAsset(new PropertyPermission("ts.timeout.factor", "read"), new ElytronPermission("setRunAsPrincipal"), new ElytronPermission("handleSecurityEvent"), new ChangeRoleMapperPermission("ejb")), "META-INF/jboss-permissions.xml"); jar.addAsManifestResource(new StringAsset("Dependencies: deployment.runasmdbejb-ejb2.jar \n"), "MANIFEST.MF"); return jar; } /** * The setup of testcase is: * * <pre> * ejb client * +-> ejb3 slsb -> ejb3 mdb (@RunAs) -> ( ejb3 slsb -> ejb2 slsb && ejb2 slsb ) * </pre> */ @Test public void clientCall() throws Exception { Hello helloBean = (Hello) initialContext.lookup("runasmdbejb-ejb3/Hello!org.jboss.as.test.integration.ejb.security.runas.ejb2mdb.Hello"); String hellomsg = helloBean.sayHello(); Assert.assertEquals(String.format("%s %s, %s %s, %s %s! %s.", HelloBean.SAYING, PRINCIPAL, HowdyBean.SAYING, PRINCIPAL, HolaBean.SAYING, PRINCIPAL, GoodByeBean.SAYING), hellomsg); } /** * The setup of testcase is: * * <pre> * send message * +-> ejb3 mdb (@RunAs) -> ( ejb3 slsb -> ejb2 slsb && ejb2 slsb ) * </pre> */ @Test public void sendMessage() throws Exception { ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("jms/RemoteConnectionFactory"); String replyMessage = HelloBean.sendMessage(cf); Assert.assertEquals(String.format("%s %s, %s %s! %s.", HowdyBean.SAYING, PRINCIPAL, HolaBean.SAYING, PRINCIPAL, GoodByeBean.SAYING), replyMessage); } }
6,239
43.571429
145
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/ejb2mdb/Hola.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.ejb2mdb; /** * @author Ondrej Chaloupka */ public interface Hola { String sayHola(); }
1,179
37.064516
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/ejb2mdb/GoodBye.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.ejb2mdb; import java.rmi.RemoteException; import jakarta.ejb.EJBObject; /** * @author Ondrej Chaloupka */ public interface GoodBye extends EJBObject { String sayGoodBye() throws RemoteException; }
1,290
36.970588
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/ejb2mdb/HelloMDB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.ejb2mdb; import jakarta.annotation.Resource; import jakarta.annotation.security.RunAs; import jakarta.annotation.security.PermitAll; import jakarta.ejb.ActivationConfigProperty; import jakarta.ejb.EJB; import jakarta.ejb.MessageDriven; import jakarta.jms.DeliveryMode; import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.jms.Queue; import jakarta.jms.QueueConnection; import jakarta.jms.QueueConnectionFactory; import jakarta.jms.QueueSender; import jakarta.jms.QueueSession; import jakarta.jms.TextMessage; import org.jboss.logging.Logger; /** * MDB with RunAs annotation. Takes data from in queue and replies to reply queue. * * @author Ondrej Chaloupka */ @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/exported/queue/TestQueue"), @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1")}) @RunAs("INTERNAL_ROLE") @PermitAll // needed for access not being denied, see WFLY-8560 public class HelloMDB implements MessageListener { private static final Logger log = Logger.getLogger(HowdyBean.class); @EJB Howdy howdy; @Resource(mappedName = "java:/ConnectionFactory") private QueueConnectionFactory qFactory; @Resource(lookup = "java:global/runasmdbejb-ejb2/GoodBye!org.jboss.as.test.integration.ejb.security.runas.ejb2mdb.GoodByeLocalHome") GoodByeLocalHome goodByeHome; public void onMessage(Message message) { try { GoodByeLocal goodBye = goodByeHome.create(); String messageToReply = String.format("%s! %s.", howdy.sayHowdy(), goodBye.sayGoodBye()); sendReply(messageToReply, (Queue) message.getJMSReplyTo(), message.getJMSMessageID()); } catch (Exception e) { log.errorf(e, "Can't process message '%s'", message); } } private void sendReply(String msg, Queue destination, String messageID) throws JMSException { QueueConnection conn = qFactory.createQueueConnection("guest", "guest"); try { QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); conn.start(); QueueSender sender = session.createSender(destination); TextMessage message = session.createTextMessage(msg); message.setJMSCorrelationID(messageID); sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500); } finally { conn.close(); } } }
3,847
40.376344
136
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runas/ejb2mdb/GoodByeLocalHome.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.runas.ejb2mdb; import jakarta.ejb.CreateException; import jakarta.ejb.EJBLocalHome; /** * @author Ondrej Chaloupka */ public interface GoodByeLocalHome extends EJBLocalHome { GoodByeLocal create() throws CreateException; }
1,310
37.558824
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authentication/EntryBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authentication; import jakarta.ejb.Stateless; import org.jboss.as.test.integration.ejb.security.Entry; import org.jboss.ejb3.annotation.SecurityDomain; /** * Concrete implementation to allow deployment of bean. * * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ @Stateless @SecurityDomain("ejb3-tests") public class EntryBean extends org.jboss.as.test.integration.ejb.security.base.EntryBean implements Entry { }
1,527
39.210526
107
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authentication/WhoAmIBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authentication; import jakarta.ejb.Stateless; import org.jboss.as.test.integration.ejb.security.WhoAmI; import org.jboss.ejb3.annotation.SecurityDomain; /** * Concrete implementation to allow deployment of bean. * * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ @Stateless @SecurityDomain("ejb3-tests") public class WhoAmIBean extends org.jboss.as.test.integration.ejb.security.base.WhoAmIBean implements WhoAmI { }
1,531
39.315789
110
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/singleton/SecuredSingletonBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.singleton; import jakarta.annotation.Resource; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.EJBContext; import jakarta.ejb.Remote; import jakarta.ejb.Singleton; import org.jboss.ejb3.annotation.SecurityDomain; /** * User: jpai */ @Singleton @SecurityDomain("other") @Remote(SingletonSecurity.class) public class SecuredSingletonBean implements SingletonSecurity { @Resource private EJBContext ejbContext; @Override @RolesAllowed("Role1") public void allowedForRole1() { if (!this.ejbContext.isCallerInRole("Role1")) { throw new RuntimeException("Only Role1 was expected to be allowed to invoke this method"); } } }
1,772
33.096154
102
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/singleton/SingletonSecurityTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.singleton; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.util.concurrent.Callable; import org.jboss.as.test.shared.integration.ejb.security.Util; import org.jboss.logging.Logger; import jakarta.ejb.EJBAccessException; import javax.naming.InitialContext; import org.junit.Assert; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.categories.CommonCriteria; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.wildfly.security.permission.ElytronPermission; /** * Tests that invocations on a secured singleton bean work as expected. * Part of the migration AS6->AS7 testsuite [JBQA-5275] - ejb3/singleton. * * @author Jaikiran Pai, Ondrej Chaloupka */ @RunWith(Arquillian.class) @Category(CommonCriteria.class) public class SingletonSecurityTestCase { private static final Logger log = Logger.getLogger(SingletonSecurityTestCase.class.getName()); @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejb3-singleton-security.jar"); jar.addPackage(SingletonSecurityTestCase.class.getPackage()); jar.addPackage(CommonCriteria.class.getPackage()); jar.addClass(Util.class); jar.addAsResource(createPermissionsXmlAsset( new RuntimePermission("org.jboss.security.setSecurityContext"), new ElytronPermission("getSecurityDomain"), new ElytronPermission("authenticate"), new ElytronPermission("setRunAsPrincipal") ), "META-INF/permissions.xml"); return jar; } /** * Test a method invocation on a singleton bean with the correct expected role. * * @throws Exception */ @Test public void testInvocationOnSecuredMethodWithCorrectRole() throws Exception { final SingletonSecurity securedSingleton = InitialContext.doLookup("java:module/" + SecuredSingletonBean.class.getSimpleName()); final Callable<Void> callable = () -> { // expects role1, so should succeed securedSingleton.allowedForRole1(); return null; }; Util.switchIdentitySCF("user1", "password1", callable); } /** * Test a method invocation on a singleton bean with an incorrect role. * * @throws Exception */ @Test public void testInvocationOnSecuredMethodWithInCorrectRole() throws Exception { final SingletonSecurity securedSingleton = InitialContext.doLookup("java:module/" + SecuredSingletonBean.class.getSimpleName()); final Callable<Void> callable = () -> { // expects role1, so should fail securedSingleton.allowedForRole1(); Assert.fail("Call to secured method, with incorrect role, was expected to fail"); return null; }; try { Util.switchIdentitySCF("user2", "password2", callable); } catch (EJBAccessException ejbae) { // expected } } /** * Test a method invocation on a singleton bean without logging in. * * @throws Exception */ @Test public void testInvocationOnSecuredMethodWithoutLogin() throws Exception { final SingletonSecurity securedSingleton = InitialContext.doLookup("java:module/" + SecuredSingletonBean.class.getSimpleName()); try { securedSingleton.allowedForRole1(); Assert.fail("Call to secured method was expected to fail"); } catch (EJBAccessException ejbae) { // expected } } }
4,961
37.465116
136
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/singleton/SingletonSecurity.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.singleton; /** * User: jpai */ public interface SingletonSecurity { void allowedForRole1(); }
1,177
35.8125
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/AttendanceRegistrySLSB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; import java.io.Serializable; import java.util.Date; /** * @author Jaikiran Pai */ @Stateless @Remote(AttendanceRegistry.class) @SecurityDomain("ejb3-tests") public class AttendanceRegistrySLSB implements AttendanceRegistry<AttendanceRegistrySLSB.DefaultTimeProvider> { @PermitAll @Override public String recordEntry(final String user, final DefaultTimeProvider defaultTimeProvider) { return "(PermitAll) - User " + user + " logged in at " + defaultTimeProvider.getTime(); } @RolesAllowed("Role2") @Override public String recordEntry(final String user, final long time) { return "User " + user + " logged in at " + time; } public static final class DefaultTimeProvider implements TimeProvider, Serializable { private final Date date; public DefaultTimeProvider(final Date date) { this.date = date; } @Override public long getTime() { return this.date.getTime(); } } }
2,302
32.376812
111
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/InjectionSLSBtoSFSB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.ejb.EJB; import jakarta.ejb.Stateful; /** * @author <a href="mailto:[email protected]">Jan Lanik</a>. */ @Stateful @SecurityDomain("other") public class InjectionSLSBtoSFSB implements SimpleAuthorizationRemote { @EJB AnnOnlyCheckSLSBForInjection injected; public String defaultAccess(String message) { return injected.defaultAccess(message); } public String roleBasedAccessOne(String message) { return injected.roleBasedAccessOne(message); } public String roleBasedAccessMore(String message) { return injected.roleBasedAccessMore(message); } public String permitAll(String message) { return injected.permitAll(message); } public String denyAll(String message) { return injected.denyAll(message); } public String starRoleAllowed(String message) { return injected.starRoleAllowed(message); } }
2,039
30.384615
71
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/ParentAnnOnlyCheck.java
package org.jboss.as.test.integration.ejb.security.authorization; import jakarta.annotation.security.DenyAll; import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed; /** * This is a parent class with methods which will be inherrited in test session bean to check that the annotations are inherrited. * * @author <a href="mailto:[email protected]">Jan Lanik</a>. */ public abstract class ParentAnnOnlyCheck implements SimpleAuthorizationRemote { public String defaultAccess(String message) { return message; } @RolesAllowed("Role1") public String roleBasedAccessOne(String message) { return message; } @RolesAllowed({"Role2", "Negative", "No-role"}) public String roleBasedAccessMore(String message) { return message; } @PermitAll public String permitAll(String message) { return message; } @DenyAll public String denyAll(String message) { return message; } @RolesAllowed("**") public String starRoleAllowed(String message) { return message; } }
1,085
23.133333
130
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/SimpleAuthorizationRemote.java
package org.jboss.as.test.integration.ejb.security.authorization; import jakarta.ejb.Remote; /** * @author <a href="mailto:[email protected]">Peter Skopek</a> */ @Remote public interface SimpleAuthorizationRemote { String defaultAccess(String message); String roleBasedAccessOne(String message); String roleBasedAccessMore(String message); String permitAll(String message); String denyAll(String message); String starRoleAllowed(String message); }
484
19.208333
65
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/AttendanceRegistry.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import jakarta.ejb.Remote; /** * @author Jaikiran Pai */ @Remote public interface AttendanceRegistry<T extends TimeProvider> { String recordEntry(String user, T timeProvider); String recordEntry(String user, long time); }
1,330
34.972973
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/DenyAllOverrideBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import jakarta.annotation.security.DenyAll; import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.Stateless; import org.jboss.ejb3.annotation.SecurityDomain; /** * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ @Stateless @DenyAll @SecurityDomain("ejb3-tests") public class DenyAllOverrideBean { public String defaultEcho(final String message) { return message; } @PermitAll public String permitAllEcho(final String message) { return message; } @PermitAll public String[] permitAllEchoWithArrayParams(final String[] messages) { return messages; } @RolesAllowed("Role1") public String role1Echo(final String message) { return message; } }
1,906
31.322034
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/SingleMethodsAnnOnlyCheckSFSB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.annotation.security.DenyAll; import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.Stateful; /** * @author <a href="mailto:[email protected]">Peter Skopek</a> */ @Stateful @SecurityDomain("other") public class SingleMethodsAnnOnlyCheckSFSB implements SimpleAuthorizationRemote { public String defaultAccess(String message) { return message; } @RolesAllowed("Role1") public String roleBasedAccessOne(String message) { return message; } @RolesAllowed({"Role2", "Negative", "No-role"}) public String roleBasedAccessMore(String message) { return message; } @PermitAll public String permitAll(String message) { return message; } @DenyAll public String denyAll(String message) { return message; } @RolesAllowed("**") public String starRoleAllowed(String message) { return message; } }
2,125
30.264706
81
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/InjectionSFSBtoSFSB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.ejb.EJB; import jakarta.ejb.Stateful; /** * @author <a href="mailto:[email protected]">Jan Lanik</a>. */ @Stateful @SecurityDomain("other") public class InjectionSFSBtoSFSB implements SimpleAuthorizationRemote { @EJB AnnOnlyCheckSFSBForInjection injected; public String defaultAccess(String message) { return injected.defaultAccess(message); } public String roleBasedAccessOne(String message) { return injected.roleBasedAccessOne(message); } public String roleBasedAccessMore(String message) { return injected.roleBasedAccessMore(message); } public String permitAll(String message) { return injected.permitAll(message); } public String denyAll(String message) { return injected.denyAll(message); } public String starRoleAllowed(String message) { return injected.starRoleAllowed(message); } }
2,037
31.349206
71
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/Simple.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import jakarta.ejb.Local; /** * Simple local interface * * @author <a href="mailto:[email protected]">Jan Lanik</a>. */ @Local public interface Simple { String testAuthorizedRole(); String testUnauthorizedRole(); String testPermitAll(); String testDenyAll(); }
1,373
34.230769
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/SingleMethodsAnnOnlyCheckSLSB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.DenyAll; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.Stateless; /** * @author <a href="mailto:[email protected]">Peter Skopek</a> */ @Stateless @SecurityDomain("other") public class SingleMethodsAnnOnlyCheckSLSB implements SimpleAuthorizationRemote { public String defaultAccess(String message) { return message; } @RolesAllowed("Role1") public String roleBasedAccessOne(String message) { return message; } @RolesAllowed({"Role2", "Negative", "No-role"}) public String roleBasedAccessMore(String message) { return message; } @PermitAll public String permitAll(String message) { return message; } @DenyAll public String denyAll(String message) { return message; } @RolesAllowed("**") public String starRoleAllowed(final String message) { return message; } }
2,134
29.942029
81
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/SimpleSLSB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.annotation.security.DenyAll; import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.Stateless; /** * @author <a href="mailto:[email protected]">Jan Lanik</a>. */ @Stateless @SecurityDomain(value = "ejb3-tests", unauthenticatedPrincipal = "nobody") public class SimpleSLSB implements Simple{ public static final String SUCCESS = "SUCCESS"; @RolesAllowed("MDBrole") public String testAuthorizedRole() { return SUCCESS; } @RolesAllowed("SomeOtherRole") public String testUnauthorizedRole() { return SUCCESS; } @PermitAll public String testPermitAll() { return SUCCESS; } @DenyAll public String testDenyAll() { return SUCCESS; } }
1,917
30.442623
74
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/InherritanceAnnOnlyCheckSLSB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.ejb.Stateless; /** * @author <a href="mailto:[email protected]">Jan Lanik</a>. */ @Stateless @SecurityDomain("other") public class InherritanceAnnOnlyCheckSLSB extends ParentAnnOnlyCheck implements SimpleAuthorizationRemote { }
1,391
37.666667
107
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/InjectionSFSBtoSLSB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.ejb.EJB; import jakarta.ejb.Stateless; /** * @author <a href="mailto:[email protected]">Jan Lanik</a>. */ @Stateless @SecurityDomain("other") public class InjectionSFSBtoSLSB implements SimpleAuthorizationRemote { @EJB AnnOnlyCheckSFSBForInjection injected; public String defaultAccess(String message) { return injected.defaultAccess(message); } public String roleBasedAccessOne(String message) { return injected.roleBasedAccessOne(message); } public String roleBasedAccessMore(String message) { return injected.roleBasedAccessMore(message); } public String permitAll(String message) { return injected.permitAll(message); } public String denyAll(String message) { return injected.denyAll(message); } public String starRoleAllowed(String message) { return injected.starRoleAllowed(message); } }
2,041
30.415385
71
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/RolesAllowedOverrideBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import jakarta.annotation.security.DenyAll; import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.Stateless; import org.jboss.ejb3.annotation.SecurityDomain; /** * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ @Stateless @RolesAllowed("Role1") @SecurityDomain("ejb3-tests") public class RolesAllowedOverrideBean extends RolesAllowedOverrideBeanBase { public String defaultEcho(final String message) { return message; } @PermitAll public String permitAllEcho(final String message) { return message; } @DenyAll public String denyAllEcho(final String message) { return message; } @RolesAllowed("Role2") public String role2Echo(final String message) { return message; } @RolesAllowed("HR") public String aMethod(final String message) { return message; } }
2,042
30.921875
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/InjectionSLSBtoSLSB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.ejb.EJB; import jakarta.ejb.Stateless; /** * @author <a href="mailto:[email protected]">Jan Lanik</a>. */ @Stateless @SecurityDomain("other") public class InjectionSLSBtoSLSB implements SimpleAuthorizationRemote{ @EJB AnnOnlyCheckSLSBForInjection injected; public String defaultAccess(String message) { return injected.defaultAccess(message); } public String roleBasedAccessOne(String message) { return injected.roleBasedAccessOne(message); } public String roleBasedAccessMore(String message) { return injected.roleBasedAccessMore(message); } public String permitAll(String message) { return injected.permitAll(message); } public String denyAll(String message) { return injected.denyAll(message); } public String starRoleAllowed(String message) { return injected.starRoleAllowed(message); } }
2,042
30.430769
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/AnnOnlyCheckSFSBForInjection.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.annotation.security.DenyAll; import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.Stateful; /** * This is a no-interface session bean which is to be injected. * * @author <a href="mailto:[email protected]">Jan Lanik</a>. */ @Stateful @SecurityDomain("other") public class AnnOnlyCheckSFSBForInjection { public String defaultAccess(String message) { return message; } @RolesAllowed("Role1") public String roleBasedAccessOne(String message) { return message; } @RolesAllowed({"Role2", "Negative", "No-role"}) public String roleBasedAccessMore(String message) { return message; } @PermitAll public String permitAll(String message) { return message; } @DenyAll public String denyAll(String message) { return message; } @RolesAllowed("**") public String starRoleAllowed(String message) { return message; } }
2,123
28.915493
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/RolesAllowedOverrideBeanBase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import jakarta.annotation.security.RolesAllowed; /** * @author wangchao * */ @RolesAllowed("Admin") public class RolesAllowedOverrideBeanBase { public String aMethod(final String message) { return message; } public String bMethod(final String message) { return message; } }
1,405
30.954545
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/SaslLegacyMechanismBean.java
/* * JBoss, Home of Professional Open Source * Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual * contributors by the @authors tag. See the copyright.txt in the * distribution for a full listing of individual contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.test.integration.ejb.security.authorization; import jakarta.annotation.Resource; import jakarta.annotation.security.PermitAll; import jakarta.ejb.EJBContext; import jakarta.ejb.Remote; import jakarta.ejb.Stateless; /** */ @Stateless @Remote(SaslLegacyMechanismBeanRemote.class) @PermitAll public class SaslLegacyMechanismBean implements SaslLegacyMechanismBeanRemote { @Resource private EJBContext context; @Override public String getPrincipal() { return context.getCallerPrincipal().getName(); } }
1,351
32.8
79
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/PermitAllOverrideBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import jakarta.annotation.security.DenyAll; import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.Stateless; import org.jboss.ejb3.annotation.SecurityDomain; /** * @author <a href="mailto:[email protected]">Darran Lofthouse</a> */ @Stateless @PermitAll @SecurityDomain("ejb3-tests") public class PermitAllOverrideBean { public String defaultEcho(final String message) { return message; } @DenyAll public String denyAllEcho(final String message) { return message; } @RolesAllowed("Role1") public String role1Echo(final String message) { return message; } }
1,783
32.037037
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/InherritanceAnnOnlyCheckSFSB.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.ejb.Stateful; /** * @author <a href="mailto:[email protected]">Jan Lanik</a>. */ @Stateful @SecurityDomain("other") public class InherritanceAnnOnlyCheckSFSB extends ParentAnnOnlyCheck implements SimpleAuthorizationRemote { }
1,389
37.611111
107
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/AnnOnlyCheckSLSBForInjection.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.annotation.security.DenyAll; import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.RolesAllowed; import jakarta.ejb.Stateless; /** * This is a no-interface session bean which is to be injected. * * @author <a href="mailto:[email protected]">Jan Lanik</a>. */ @Stateless @SecurityDomain("other") public class AnnOnlyCheckSLSBForInjection { public String defaultAccess(String message) { return message; } @RolesAllowed("Role1") public String roleBasedAccessOne(String message) { return message; } @RolesAllowed({"Role2", "Negative", "No-role"}) public String roleBasedAccessMore(String message) { return message; } @PermitAll public String permitAll(String message) { return message; } @DenyAll public String denyAll(String message) { return message; } @RolesAllowed("**") public String starRoleAllowed(String message) { return message; } }
2,125
28.943662
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/MDBRole.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; import org.jboss.ejb3.annotation.SecurityDomain; import jakarta.annotation.Resource; import jakarta.annotation.security.RunAs; import jakarta.ejb.ActivationConfigProperty; import jakarta.ejb.EJB; import jakarta.ejb.EJBAccessException; import jakarta.ejb.MessageDriven; import jakarta.jms.ConnectionFactory; import jakarta.jms.Destination; import jakarta.jms.JMSContext; import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.jms.TextMessage; /** * @author <a href="mailto:[email protected]">Jan Lanik</a>. */ @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/myAwesomeQueue") }) @RunAs("MDBrole") @SecurityDomain(value = "ejb3-tests", unauthenticatedPrincipal = "nobody") public class MDBRole implements MessageListener { @Resource(lookup = "java:/JmsXA") private ConnectionFactory factory; @EJB Simple simple; private String createResponse(){ String response; try{ response = simple.testAuthorizedRole(); } catch (EJBAccessException ex) { response = "UNAUTHORIZED: testAuthorizedRole()"; return response; } try{ response = simple.testUnauthorizedRole(); return "ILLEGALY AUTHORIZED: testUnauthorizedRole()"; } catch (EJBAccessException ex) { // OK, we expect an exception } try{ response = simple.testPermitAll(); } catch (EJBAccessException ex) { response = "UNAUTHORIZED: testPermitAll()"; return response; } try{ response = simple.testDenyAll(); return "ILLEGALY AUTHORIZED: testDenyAll()"; } catch (EJBAccessException ex) { // OK, we expect an exception } return response; } public void onMessage(Message message) { try { if (!"Let's test it!".equals(((TextMessage) message).getText())){ throw new AssertionError("Unexpected message: " + ((TextMessage) message).getText() + " ; expected:\"Let's test it!\""); } final Destination replyTo = message.getJMSReplyTo(); // ignore messages that need no reply if (replyTo == null) return; try ( JMSContext context = factory.createContext() ) { context.createProducer() .setJMSCorrelationID(message.getJMSMessageID()) .send(replyTo, createResponse()); } } catch (JMSException e) { throw new RuntimeException(e); } } }
3,702
31.769912
132
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/SaslLegacyMechanismBeanRemote.java
/* * JBoss, Home of Professional Open Source * Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual * contributors by the @authors tag. See the copyright.txt in the * distribution for a full listing of individual contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jboss.as.test.integration.ejb.security.authorization; /** */ public interface SaslLegacyMechanismBeanRemote { String getPrincipal(); }
953
35.692308
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/authorization/TimeProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.security.authorization; /** * @author Jaikiran Pai */ public interface TimeProvider { long getTime(); }
1,181
37.129032
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sessioncontext/SetSessionContextMethodInvocationTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.sessioncontext; import javax.naming.InitialContext; import javax.naming.NamingException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests that bean implementing the {@link jakarta.ejb.SessionBean} interface has its * {@link jakarta.ejb.SessionBean#setSessionContext(jakarta.ejb.SessionContext)} method invoked. * <p/> * User: Jaikiran Pai */ @RunWith(Arquillian.class) public class SetSessionContextMethodInvocationTestCase { @ArquillianResource InitialContext ctx; @Deployment public static JavaArchive createDeployment() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class); jar.addPackage(SLSBImplementingSessionBean.class.getPackage()); return jar; } private<T> T lookup(Class<T> beanType) throws NamingException { return beanType.cast(ctx.lookup("java:module/" + beanType.getSimpleName() + "!" + beanType.getName())); } /** * Tests that {@link jakarta.ejb.SessionBean#setSessionContext(jakarta.ejb.SessionContext)} was invoked on a stateless * session bean, implementing the {@link jakarta.ejb.SessionBean} interface * * @throws Exception */ @Test public void testSetSessionContextOnSLSB() throws Exception { final SLSBImplementingSessionBean slsb = lookup(SLSBImplementingSessionBean.class); Assert.assertTrue("setSessionContext(SessionContext) method was not invoked on a stateless bean implementing jakarta.ejb.SessionBean", slsb.wasSetSessionContextMethodInvoked()); } /** * Tests that {@link jakarta.ejb.SessionBean#setSessionContext(jakarta.ejb.SessionContext)} was invoked on a stateful * session bean, implementing the {@link jakarta.ejb.SessionBean} interface * * @throws Exception */ @Test public void testSetSessionContextOnSFSB() throws Exception { final SFSBImplementingSessionBean sfsb = lookup(SFSBImplementingSessionBean.class); Assert.assertTrue("setSessionContext(SessionContext) method was not invoked on a stateful bean implementing jakarta.ejb.SessionBean", sfsb.wasSetSessionContextMethodInvoked()); } /** * Tests that a {@link jakarta.ejb.SessionContext} is injected into a stateless bean, via the @Resource annotation * * @throws Exception */ @Test public void testSessionContextInjectionOnSLSB() throws Exception { final SLSBImplementingSessionBean slsb = lookup(SLSBImplementingSessionBean.class); Assert.assertTrue("SessionContext was not injectd in stateless bean", slsb.wasSessionContextInjected()); } /** * Tests that a {@link jakarta.ejb.SessionContext} is injected into a stateful bean, via the @Resource annotation * * @throws Exception */ @Test public void testSessionContextInjectionOnSFSB() throws Exception { final SFSBImplementingSessionBean sfsb = lookup(SFSBImplementingSessionBean.class); Assert.assertTrue("SessionContext was not injectd in stateful bean", sfsb.wasSessionContextInjected()); } /** * Testing whether correct exception is called on {@link jakarta.ejb.SessionContext#wasCancelCalled()} is returned. Supposing IllegalStateException. */ @Test public void testWasCancelledCalled() throws Exception { final SLSBImplementingSessionBean slsb = lookup(SLSBImplementingSessionBean.class); try { slsb.wasCanceledCalled(); } catch (Exception e) { Assert.assertEquals("The SessionContext.wasCanceledCalled() method was called on not asynchronous method. We supposing " + IllegalStateException.class.getName(), IllegalStateException.class, e.getCause().getClass()); return; // we are fine with this } Assert.fail("Expecting: " + IllegalStateException.class.getName() + " and it was not thrown."); } }
5,277
40.559055
173
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sessioncontext/SLSBImplementingSessionBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.sessioncontext; import java.rmi.RemoteException; import jakarta.annotation.Resource; import jakarta.ejb.EJBException; import jakarta.ejb.SessionBean; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; /** * User: jpai */ @Stateless public class SLSBImplementingSessionBean implements SessionBean { private static final long serialVersionUID = 1L; private SessionContext sessionContext; private SessionContext injectedSessionContext; @Override public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException { this.sessionContext = ctx; } @Override public void ejbRemove() throws EJBException, RemoteException { } @Override public void ejbActivate() throws EJBException, RemoteException { } @Override public void ejbPassivate() throws EJBException, RemoteException { } @Resource public void setInjectedSessionContext(SessionContext ctx) { this.injectedSessionContext = ctx; } public boolean wasSetSessionContextMethodInvoked() { return this.sessionContext != null; } public boolean wasSessionContextInjected() { return this.injectedSessionContext != null; } public void wasCanceledCalled() { sessionContext.wasCancelCalled(); } }
2,385
28.825
92
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/sessioncontext/SFSBImplementingSessionBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.sessioncontext; import java.rmi.RemoteException; import jakarta.annotation.Resource; import jakarta.ejb.EJBException; import jakarta.ejb.SessionBean; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateful; /** * User: Jaikiran Pai */ @Stateful public class SFSBImplementingSessionBean implements SessionBean { private static final long serialVersionUID = 1L; private SessionContext sessionContext; private SessionContext injectedSessionContext; @Override public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException { this.sessionContext = ctx; } @Override public void ejbRemove() throws EJBException, RemoteException { } @Override public void ejbActivate() throws EJBException, RemoteException { } @Override public void ejbPassivate() throws EJBException, RemoteException { } @Resource public void setInjectedSessionContext(SessionContext ctx) { this.injectedSessionContext = ctx; } public boolean wasSetSessionContextMethodInvoked() { return this.sessionContext != null; } public boolean wasSessionContextInjected() { return this.injectedSessionContext != null; } }
2,305
28.948052
92
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inheritorder/MoreInterceptorInheritanceTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.inheritorder; import javax.naming.InitialContext; import org.junit.Test; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.runner.RunWith; /** * Interceptor inheritance test. * * @author Ondrej Chaloupka */ @RunWith(Arquillian.class) public class MoreInterceptorInheritanceTestCase { @ArquillianResource InitialContext ctx; @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "more-interceptor-test.jar"); jar.addPackage(MoreInterceptorInheritanceTestCase.class.getPackage()); return jar; } @Test public void test() throws Exception { CClass bean = (CClass) ctx.lookup("java:module/" + CClass.class.getSimpleName()); String supposedResult = "A1 A2 CGrandparent CChild " + // Class interceptor "Cmethod " + BClass.class.getSimpleName() + ".method " + CClass.class.getSimpleName() + ".method " + // Method // interceptors AClass.class.getSimpleName() + BClass.class.getSimpleName() + CClass.class.getSimpleName(); // Class method // calls Assert.assertEquals(supposedResult, bean.run()); } }
2,750
39.455882
132
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inheritorder/CClass.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.inheritorder; import jakarta.ejb.Stateless; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.Interceptors; import jakarta.interceptor.InvocationContext; /** * @author Ondrej Chaloupka */ @Stateless @Interceptors(CChildInterceptor.class) public class CClass extends BClass { @Override @Interceptors({ CMethodInterceptor.class }) public String run() { return super.run() + CClass.class.getSimpleName(); } @AroundInvoke // does not override aroundinvoke method of BClass - both will be run public Object aroundInvokeCClass(final InvocationContext context) throws Exception { return CClass.class.getSimpleName() + ".method " + context.proceed().toString(); } }
1,801
35.77551
88
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inheritorder/CParentInterceptor.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.inheritorder; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.InvocationContext; /** * @author Ondrej Chaloupka */ public class CParentInterceptor extends CGrandparentInterceptor { @AroundInvoke public Object interceptParent(final InvocationContext context) throws Exception { return "CParent " + context.proceed().toString(); } }
1,446
38.108108
85
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inheritorder/AClass.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.inheritorder; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.Interceptors; import jakarta.interceptor.InvocationContext; /** * @author Ondrej Chaloupka */ @Interceptors({ A1Interceptor.class, A2Interceptor.class }) public class AClass { public String run() { return AClass.class.getSimpleName(); } @AroundInvoke public Object aroundInvoke(final InvocationContext context) throws Exception { return AClass.class.getSimpleName() + ".method " + context.proceed().toString(); } }
1,609
36.44186
88
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inheritorder/BMethodInterceptor.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.inheritorder; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.InvocationContext; /** * @author Ondrej Chaloupka */ public class BMethodInterceptor { @AroundInvoke public Object intercept(final InvocationContext context) throws Exception { return "Bmethod " + context.proceed().toString(); } }
1,408
37.081081
79
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inheritorder/CChildInterceptor.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.inheritorder; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.InvocationContext; /** * @author Ondrej Chaloupka */ public class CChildInterceptor extends CParentInterceptor { // overriding parent interceptor method = won't be invoked public Object interceptParent(final InvocationContext context) throws Exception { return "CChild-Parent " + context.proceed().toString(); } @AroundInvoke public Object interceptChild(final InvocationContext context) throws Exception { return "CChild " + context.proceed().toString(); } }
1,659
37.604651
85
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inheritorder/CGrandparentInterceptor.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.inheritorder; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.InvocationContext; /** * @author Ondrej Chaloupka */ public class CGrandparentInterceptor { @AroundInvoke public Object interceptGrandparent(final InvocationContext context) throws Exception { return "CGrandparent " + context.proceed().toString(); } }
1,429
37.648649
90
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inheritorder/A1Interceptor.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.inheritorder; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.InvocationContext; /** * @author Ondrej Chaloupka */ public class A1Interceptor { @AroundInvoke public Object intercept(final InvocationContext context) throws Exception { return "A1 " + context.proceed().toString(); } }
1,398
36.810811
79
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inheritorder/CMethodInterceptor.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.inheritorder; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.InvocationContext; /** * @author Ondrej Chaloupka */ public class CMethodInterceptor { @AroundInvoke public Object intercept(final InvocationContext context) throws Exception { return "Cmethod " + context.proceed().toString(); } }
1,408
37.081081
79
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inheritorder/A2Interceptor.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.inheritorder; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.InvocationContext; /** * @author Ondrej Chaloupka */ public class A2Interceptor { @AroundInvoke public Object intercept(final InvocationContext context) throws Exception { return "A2 " + context.proceed().toString(); } }
1,398
36.810811
79
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/inheritorder/BClass.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.inheritorder; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.Interceptors; import jakarta.interceptor.InvocationContext; /** * @author Ondrej Chaloupka */ public class BClass extends AClass { @Override @Interceptors({ BMethodInterceptor.class }) // won't be invoked - overriden in CClass public String run() { return super.run() + BClass.class.getSimpleName(); } @AroundInvoke // override aroundinvoke method of AClass - only this will be run public Object aroundInvoke(final InvocationContext context) throws Exception { return BClass.class.getSimpleName() + ".method " + context.proceed().toString(); } }
1,756
37.195652
88
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/annotatedejbclient/ClientInterceptor.java
package org.jboss.as.test.integration.ejb.interceptor.annotatedejbclient; import org.jboss.ejb.client.EJBClientInterceptor; import org.jboss.ejb.client.EJBClientInvocationContext; /** * Client side JBoss interceptor. */ public class ClientInterceptor implements EJBClientInterceptor { /** * Creates a new ClientInterceptor object. */ public ClientInterceptor() { } @Override public void handleInvocation(EJBClientInvocationContext context) throws Exception { context.getContextData().put("ClientInterceptorInvoked", this.getClass().getName() + " " + context.getViewClass() + " " + context.getLocator()); // count the number of times the interceptor is invoked if(context.getParameters().length > 0) { // String interceptorInvocationCounterKey = this.getClass().getName() + "-" + context.getViewClass() + "-" + context.getLocator() + "-" + context.getParameters()[0]; String id = (String) context.getParameters()[0]; String interceptorInvocationCounterKey = id + "-COUNT"; Integer count = (Integer) context.getContextData().get(interceptorInvocationCounterKey); if(count == null) count = 0; count++; context.getContextData().put(interceptorInvocationCounterKey, count); } // Must make this call context.sendRequest(); } @Override public Object handleInvocationResult(EJBClientInvocationContext context) throws Exception { context.getContextData().get("ClientInterceptorInvoked"); // Must make this call return context.getResult(); } }
1,592
35.204545
175
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/annotatedejbclient/AnnotatedEJBClientInterceptorTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.annotatedejbclient; import java.net.URL; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.shared.integration.ejb.security.Util; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.arquillian.test.api.ArquillianResource; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * AnnotatedEJBClientInterceptorTest * For more information visit <a href="issues.jboss.org/browse/JBEAP-14246">https://issues.jboss.org/browse/JBEAP-14246</a> * @author Petr Adamec */ @RunWith(Arquillian.class) @RunAsClient public class AnnotatedEJBClientInterceptorTestCase { private static final String JAR_FILE_NAME = "remote-interface-test-annotations-standalone"; @Deployment public static JavaArchive getDeployment() { return ShrinkWrap.create(JavaArchive.class, JAR_FILE_NAME+".jar") .addClasses(ClientInterceptor.class, TestRemote.class, TestSLSB.class); } public static Context getInitialContext(String host, Integer port, String username, String password) throws Exception { Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory"); props.put(Context.PROVIDER_URL, String.format("%s://%s:%d", "remote+http", host, port)); if(username != null && password != null) { props.put(Context.SECURITY_PRINCIPAL, username); props.put(Context.SECURITY_CREDENTIALS, password); } return new InitialContext(props); } @Test public void testConfiguration(@ArquillianResource URL url) throws Throwable { TestRemote bean = lookup(url, TestRemote.class, TestSLSB.class, JAR_FILE_NAME); if(bean.invoke("Test-" + System.currentTimeMillis()) > 1){ Assert.fail("Method was invoked more than once."); } } private <T> T lookup(URL url, final Class<T> remoteClass, final Class<?> beanClass, final String archiveName) throws NamingException, Throwable { String myContext = Util.createRemoteEjbJndiContext( "", archiveName, "", beanClass.getSimpleName(), remoteClass.getName(), false); return remoteClass.cast(getInitialContext(url.getHost(), url.getPort(), null, null).lookup(myContext)); } }
3,769
42.837209
149
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/annotatedejbclient/TestSLSB.java
package org.jboss.as.test.integration.ejb.interceptor.annotatedejbclient; import jakarta.annotation.Resource; import jakarta.ejb.SessionContext; import jakarta.ejb.Stateless; @Stateless public class TestSLSB implements TestRemote { @Resource private SessionContext context; private String wasClientInterceptorInvoked() { return (String) context.getContextData().get("ClientInterceptorInvoked"); } public int invoke(String id) { String interceptorInvocationCounterKey = id + "-COUNT"; String clientInterceptor = wasClientInterceptorInvoked(); context.getContextData().put("ClientInterceptorInvoked", clientInterceptor); return (Integer) context.getContextData().get(interceptorInvocationCounterKey); } }
775
27.740741
87
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/annotatedejbclient/TestRemote.java
package org.jboss.as.test.integration.ejb.interceptor.annotatedejbclient; import jakarta.ejb.Remote; import org.jboss.ejb.client.annotation.ClientInterceptors; @ClientInterceptors({ClientInterceptor.class}) @Remote public interface TestRemote { int invoke(String id); }
276
24.181818
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/order/InterceptorOrderUnitTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2009, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.order; import javax.naming.InitialContext; import org.junit.Test; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.runner.RunWith; /** * Test migrated from EJB3 testsuite [JBQA-5451] - from test ejbthree1852 * * @author Carlo de Wolf, Ondrej Chaloupka */ @RunWith(Arquillian.class) public class InterceptorOrderUnitTestCase { @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "interceptor-descriptor-test.jar"); jar.addPackage(InterceptorOrderUnitTestCase.class.getPackage()); jar.addAsManifestResource(InterceptorOrderUnitTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml"); return jar; } @Test public void test() throws Exception { GreeterRemote greeter = (GreeterRemote) new InitialContext().lookup("java:module/" + GreeterBean.class.getSimpleName() + "!" + GreeterRemote.class.getName()); String result = greeter.sayHi("ejbthree1852"); Assert.assertEquals("SecondFirstHi ejbthree1852", result); } }
2,389
38.180328
126
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/order/SecondCustomInterceptor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2009, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.order; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ public class SecondCustomInterceptor extends AbstractCustomInterceptor { public SecondCustomInterceptor() { super("Second"); } }
1,313
38.818182
72
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/order/GreeterRemote.java
/* * JBoss, Home of Professional Open Source. * Copyright 2009, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.order; import jakarta.ejb.Remote; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ @Remote public interface GreeterRemote { String sayHi(String name); }
1,269
37.484848
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/order/FirstCustomInterceptor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2009, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.order; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ public class FirstCustomInterceptor extends AbstractCustomInterceptor { public FirstCustomInterceptor() { super("First"); } }
1,309
39.9375
71
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/interceptor/order/AbstractCustomInterceptor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2009, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ejb.interceptor.order; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.InvocationContext; /** * @author <a href="mailto:[email protected]">Carlo de Wolf</a> */ public abstract class AbstractCustomInterceptor { private String tag; protected AbstractCustomInterceptor(String tag) { this.tag = tag; } @AroundInvoke public Object invoke(InvocationContext ctx) throws Exception { return tag + ctx.proceed(); } }
1,544
35.785714
70
java