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/stateful/passivation/PassivationInterceptor.java
|
package org.jboss.as.test.integration.ejb.stateful.passivation;
import java.io.Serializable;
import jakarta.ejb.PostActivate;
import jakarta.ejb.PrePassivate;
import jakarta.interceptor.InvocationContext;
/**
* @author Stuart Douglas
*/
public class PassivationInterceptor implements Serializable {
private static final long serialVersionUID = 1L;
private static volatile Object postActivateTarget, prePassivateTarget;
@PostActivate
public void postActivate(final InvocationContext ctx) throws Exception {
postActivateTarget = ctx.getTarget();
ctx.proceed();
}
@PrePassivate
public void prePassivate(final InvocationContext ctx) throws Exception {
prePassivateTarget = ctx.getTarget();
ctx.proceed();
}
public static void reset() {
postActivateTarget = prePassivateTarget = null;
}
public static Object getPostActivateTarget() {
return postActivateTarget;
}
public static Object getPrePassivateTarget() {
return prePassivateTarget;
}
}
| 1,057 | 26.128205 | 76 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/DDBasedSFSB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.stateful.passivation;
import jakarta.ejb.Local;
import jakarta.ejb.PostActivate;
import jakarta.ejb.PrePassivate;
import jakarta.ejb.Remove;
import jakarta.ejb.Stateful;
import org.jboss.ejb3.annotation.Cache;
/**
* @author Jaikiran Pai
*/
@Stateful
@Cache("distributable")
@Local(Bean.class)
public class DDBasedSFSB implements Bean {
private boolean prePrePassivateInvoked;
private boolean postActivateInvoked;
@PrePassivate
private void beforePassivate() {
this.prePrePassivateInvoked = true;
}
@PostActivate
private void afterActivate() {
this.postActivateInvoked = true;
}
@Override
public boolean wasPassivated() {
return this.prePrePassivateInvoked;
}
@Override
public boolean wasActivated() {
return this.postActivateInvoked;
}
@Remove
@Override
public void close() {
}
}
| 1,961 | 27.434783 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/BeanWithSerializationIssue.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, 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.stateful.passivation;
import java.io.Serializable;
import jakarta.ejb.EJB;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateful;
import org.jboss.ejb3.annotation.Cache;
/**
* @author Tomas Hofman ([email protected])
*/
@Stateful
@Cache("distributable")
@Remote(TestPassivationRemote.class)
public class BeanWithSerializationIssue extends TestPassivationBean {
private Object object;
@EJB
private NestledBean nestledBean;
public BeanWithSerializationIssue() {
object = new Serializable() {
private static final long serialVersionUID = 1L;
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
throw new RuntimeException("Test");
}
};
}
}
| 1,847 | 30.862069 | 95 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/PassivationTestCase.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.stateful.passivation;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import java.util.PropertyPermission;
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.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
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;
/**
* Tests various scenarios for stateful bean passivation
*
* @author ALR, Stuart Douglas, Ondrej Chaloupka, Jaikiran Pai
*/
@RunWith(Arquillian.class)
@ServerSetup(PassivationTestCaseSetup.class)
public class PassivationTestCase {
@ArquillianResource
private InitialContext ctx;
@Deployment
public static Archive<?> deploy() throws Exception {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, PassivationTestCase.class.getSimpleName() + ".jar");
jar.addPackage(PassivationTestCase.class.getPackage());
jar.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr \n"), "MANIFEST.MF");
jar.addAsManifestResource(PassivationTestCase.class.getPackage(), "persistence.xml", "persistence.xml");
jar.addAsManifestResource(PassivationTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
jar.addAsManifestResource(createPermissionsXmlAsset(new PropertyPermission("ts.timeout.factor", "read")), "jboss-permissions.xml");
return jar;
}
@Test
public void testPassivationMaxSize() throws Exception {
PassivationInterceptor.reset();
try (TestPassivationRemote remote1 = (TestPassivationRemote) ctx.lookup("java:module/" + TestPassivationBean.class.getSimpleName())) {
Assert.assertEquals("Returned remote1 result was not expected", TestPassivationRemote.EXPECTED_RESULT, remote1.returnTrueString());
remote1.addEntity(1, "Bob");
remote1.setManagedBeanMessage("bar");
Assert.assertTrue(remote1.isPersistenceContextSame());
Assert.assertFalse("@PrePassivate called, check cache configuration and client sleep time", remote1.hasBeenPassivated());
Assert.assertFalse("@PostActivate called, check cache configuration and client sleep time", remote1.hasBeenActivated());
Assert.assertTrue(remote1.isPersistenceContextSame());
Assert.assertEquals("Super", remote1.getSuperEmployee().getName());
Assert.assertEquals("bar", remote1.getManagedBeanMessage());
// create another bean. This should force the other bean to passivate, as only one bean is allowed in the cache at a time
try (TestPassivationRemote remote2 = (TestPassivationRemote) ctx.lookup("java:module/" + TestPassivationBean.class.getSimpleName())) {
Assert.assertEquals("Returned remote2 result was not expected", TestPassivationRemote.EXPECTED_RESULT, remote2.returnTrueString());
Assert.assertTrue(remote2.isPersistenceContextSame());
Assert.assertFalse("@PrePassivate called, check cache configuration and client sleep time", remote2.hasBeenPassivated());
Assert.assertFalse("@PostActivate called, check cache configuration and client sleep time", remote2.hasBeenActivated());
Assert.assertTrue(remote2.isPersistenceContextSame());
Assert.assertEquals("Super", remote2.getSuperEmployee().getName());
Assert.assertEquals("bar", remote2.getManagedBeanMessage());
Assert.assertTrue("@PrePassivate not called, check cache configuration and client sleep time", remote1.hasBeenPassivated());
Assert.assertTrue("@PostActivate not called, check cache configuration and client sleep time", remote1.hasBeenActivated());
Assert.assertTrue(remote1.isPersistenceContextSame());
Assert.assertEquals("Super", remote1.getSuperEmployee().getName());
Assert.assertEquals("bar", remote1.getManagedBeanMessage());
Assert.assertTrue("@PrePassivate not called, check cache configuration and client sleep time", remote2.hasBeenPassivated());
Assert.assertTrue("@PostActivate not called, check cache configuration and client sleep time", remote2.hasBeenActivated());
Assert.assertTrue(remote2.isPersistenceContextSame());
Assert.assertEquals("Super", remote2.getSuperEmployee().getName());
Assert.assertEquals("bar", remote2.getManagedBeanMessage());
} finally {
remote1.removeEntity(1);
}
}
Assert.assertTrue("invalid: " + PassivationInterceptor.getPrePassivateTarget(), PassivationInterceptor.getPrePassivateTarget() instanceof TestPassivationBean);
Assert.assertTrue("invalid: " + PassivationInterceptor.getPostActivateTarget(), PassivationInterceptor.getPostActivateTarget() instanceof TestPassivationBean);
PassivationInterceptor.reset();
}
}
| 6,490 | 55.443478 | 167 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/ManagedBean.java
|
package org.jboss.as.test.integration.ejb.stateful.passivation;
import jakarta.enterprise.context.ApplicationScoped;
/**
* @author Marek Schmidt
*/
@ApplicationScoped
public class ManagedBean {
private String message = "foo";
public void setMessage(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}
| 384 | 18.25 | 63 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/NestledBean.java
|
package org.jboss.as.test.integration.ejb.stateful.passivation;
import jakarta.ejb.Remove;
import jakarta.ejb.Stateful;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.PersistenceContextType;
import org.jboss.ejb3.annotation.Cache;
/**
* @author Stuart Douglas
*/
@Stateful
@Cache("distributable")
public class NestledBean {
@PersistenceContext(type = PersistenceContextType.EXTENDED)
private EntityManager entityManager;
public Employee get(int id) {
return (Employee) entityManager.createQuery("select e from Employee e where e.id=:id").setParameter("id", id)
.getSingleResult();
}
@Remove
public void close() {
}
}
| 746 | 23.9 | 117 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/PassivationDisabledBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.stateful.passivation;
import jakarta.ejb.Local;
import jakarta.ejb.PostActivate;
import jakarta.ejb.PrePassivate;
import jakarta.ejb.Remove;
import jakarta.ejb.Stateful;
import org.jboss.ejb3.annotation.Cache;
/**
* @author Jaikiran Pai
*/
@Stateful(passivationCapable = false)
@Cache("distributable")
@Local(Bean.class)
public class PassivationDisabledBean implements Bean {
private boolean prePrePassivateInvoked;
private boolean postActivateInvoked;
@PrePassivate
private void beforePassivate() {
this.prePrePassivateInvoked = true;
}
@PostActivate
private void afterActivate() {
this.postActivateInvoked = true;
}
@Override
public boolean wasPassivated() {
return this.prePrePassivateInvoked;
}
@Override
public boolean wasActivated() {
return this.postActivateInvoked;
}
@Remove
@Override
public void close() {
}
}
| 2,001 | 28.014493 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/TestPassivationRemote.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.stateful.passivation;
/**
* @author <a href="mailto:[email protected]">ALR</a>
*/
public interface TestPassivationRemote extends AutoCloseable {
String EXPECTED_RESULT = "true";
/**
* Returns the expected result exposed as a static final variable by this interface
*/
String returnTrueString();
/**
* Returns whether or not this instance has been passivated
*/
boolean hasBeenPassivated();
/**
* Returns whether or not this instance has been activated
*/
boolean hasBeenActivated();
/**
* returns true if the beans still share the same XPC
*/
boolean isPersistenceContextSame();
void addEntity(int id, String name);
void removeEntity(int id);
Employee getSuperEmployee();
/**
* returns a value of a property of a Jakarta Contexts and Dependency Injection bean
*/
String getManagedBeanMessage();
void setManagedBeanMessage(String message);
@Override
void close();
}
| 2,070 | 29.910448 | 88 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/PassivationDisabledTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, 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.stateful.passivation;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import java.util.PropertyPermission;
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.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
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;
/**
* Tests to validate behavior of EJB 3.2 passivationCapable flag.
* @author Paul Ferraro
*/
@RunWith(Arquillian.class)
@ServerSetup(PassivationTestCaseSetup.class)
public class PassivationDisabledTestCase {
@ArquillianResource
private InitialContext ctx;
@Deployment
public static Archive<?> deploy() throws Exception {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, PassivationDisabledTestCase.class.getSimpleName() + ".jar");
jar.addPackage(PassivationTestCase.class.getPackage());
jar.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr \n"), "MANIFEST.MF");
jar.addAsManifestResource(PassivationTestCase.class.getPackage(), "persistence.xml", "persistence.xml");
jar.addAsManifestResource(PassivationTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
jar.addAsManifestResource(createPermissionsXmlAsset(new PropertyPermission("ts.timeout.factor", "read")), "jboss-permissions.xml");
return jar;
}
/**
* Tests that an EJB 3.2 stateful bean which is marked as <code>passivationCapable=false</code> isn't passivated or activated
*
* @throws Exception
*/
@Test
public void testPassivationDisabledBean() throws Exception {
try (Bean bean = (Bean) ctx.lookup("java:module/" + PassivationDisabledBean.class.getSimpleName() + "!" + Bean.class.getName())) {
bean.doNothing();
// now do the same with a deployment descriptor configured stateful bean
try (Bean ddBean = (Bean) ctx.lookup("java:module/passivation-disabled-bean" + "!" + Bean.class.getName())) {
ddBean.doNothing();
try (Bean bean2 = (Bean) ctx.lookup("java:module/" + PassivationDisabledBean.class.getSimpleName() + "!" + Bean.class.getName())) {
bean2.doNothing();
// now do the same with a deployment descriptor configured stateful bean
try (Bean ddBean2 = (Bean) ctx.lookup("java:module/passivation-disabled-bean" + "!" + Bean.class.getName())) {
ddBean2.doNothing();
// make sure bean's passivation and activation callbacks weren't invoked
Assert.assertFalse("(Annotation based) Stateful bean marked as passivation disabled was incorrectly passivated", bean.wasPassivated());
Assert.assertFalse("(Annotation based) Stateful bean marked as passivation disabled was incorrectly activated", bean.wasActivated());
Assert.assertFalse("(Deployment descriptor based) Stateful bean marked as passivation disabled was incorrectly passivated", ddBean.wasPassivated());
Assert.assertFalse("(Deployment descriptor based) Stateful bean marked as passivation disabled was incorrectly activated", ddBean.wasActivated());
}
}
}
}
}
/**
* Tests that an EJB 3.2 stateful bean which is marked as <code>passivationCapable=true</code> is passivated or activated
*
* @throws Exception
*/
@Test
public void testPassivationEnabledBean() throws Exception {
try (Bean bean = (Bean) ctx.lookup("java:module/" + PassivationEnabledBean.class.getSimpleName() + "!" + Bean.class.getName())) {
// make an invocation
bean.doNothing();
// now do the same with a deployment descriptor configured stateful bean
try (Bean ddBean = (Bean) ctx.lookup("java:module/passivation-enabled-bean" + "!" + Bean.class.getName())) {
ddBean.doNothing();
// Create a 2nd set of beans, forcing the first set to passivate
try (Bean bean2 = (Bean) ctx.lookup("java:module/" + PassivationEnabledBean.class.getSimpleName() + "!" + Bean.class.getName())) {
bean2.doNothing();
try (Bean ddBean2 = (Bean) ctx.lookup("java:module/passivation-enabled-bean" + "!" + Bean.class.getName())) {
ddBean2.doNothing();
Assert.assertTrue("(Annotation based) Stateful bean marked as passivation enabled was not passivated", bean.wasPassivated());
Assert.assertTrue("(Annotation based) Stateful bean marked as passivation enabled was not activated", bean.wasActivated());
Assert.assertTrue("(Deployment descriptor based) Stateful bean marked as passivation enabled was not passivated", ddBean.wasPassivated());
Assert.assertTrue("(Deployment descriptor based) Stateful bean marked as passivation enabled was not activated", ddBean.wasActivated());
}
}
}
}
}
/**
* Tests that an EJB 3.2 stateful bean which is marked as <code>passivationCapable=true</code> via annotation but overridden
* as passivation disabled via deployment descriptor, isn't passivated or activated
*
* @throws Exception
*/
@Test
public void testPassivationDDOverrideBean() throws Exception {
try (Bean passivationOverrideBean = (Bean) ctx.lookup("java:module/passivation-override-bean" + "!" + Bean.class.getName())) {
// make an invocation
passivationOverrideBean.doNothing();
// Create a 2nd set of beans, that would normally force the first set to passivate
try (Bean passivationOverrideBean2 = (Bean) ctx.lookup("java:module/passivation-override-bean" + "!" + Bean.class.getName())) {
passivationOverrideBean2.doNothing();
// make sure bean's passivation and activation callbacks weren't invoked
Assert.assertFalse("(Annotation based) Stateful bean marked as passivation disabled was incorrectly passivated", passivationOverrideBean.wasPassivated());
Assert.assertFalse("(Annotation based) Stateful bean marked as passivation disabled was incorrectly activated", passivationOverrideBean.wasActivated());
}
}
}
}
| 8,016 | 51.398693 | 172 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/TestPassivationBean.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.stateful.passivation;
import java.util.Random;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.ejb.EJB;
import jakarta.ejb.PostActivate;
import jakarta.ejb.PrePassivate;
import jakarta.ejb.Remote;
import jakarta.ejb.Remove;
import jakarta.ejb.Stateful;
import jakarta.inject.Inject;
import jakarta.interceptor.Interceptors;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.PersistenceContextType;
import org.jboss.ejb3.annotation.Cache;
import org.jboss.logging.Logger;
/**
* @author <a href="mailto:[email protected]">ALR</a>
*/
@Stateful
@Cache("distributable")
@Remote(TestPassivationRemote.class)
@Interceptors(PassivationInterceptor.class)
public class TestPassivationBean extends PassivationSuperClass implements TestPassivationRemote {
private static final Logger log = Logger.getLogger(TestPassivationBean.class);
@PersistenceContext(type = PersistenceContextType.EXTENDED)
private EntityManager entityManager;
@EJB
private NestledBean nestledBean;
@Inject
private ManagedBean managedBean;
private String identificator;
private boolean beenPassivated = false;
private boolean beenActivated = false;
/**
* Returns the expected result
*/
@Override
public String returnTrueString() {
return TestPassivationRemote.EXPECTED_RESULT;
}
/**
* Returns whether or not this instance has been passivated
*/
@Override
public boolean hasBeenPassivated() {
return this.beenPassivated;
}
/**
* Returns whether or not this instance has been activated
*/
@Override
public boolean hasBeenActivated() {
return this.beenActivated;
}
@Override
public boolean isPersistenceContextSame() {
Employee e2 = nestledBean.get(1);
Employee e1 = (Employee) entityManager.createQuery("select e from Employee e where e.id=:id").setParameter("id", 1)
.getSingleResult();
return e1 == e2;
}
@Override
public void addEntity(final int id, final String name) {
Employee e = new Employee();
e.setName(name);
e.setId(id);
entityManager.persist(e);
entityManager.flush();
}
@Override
public void removeEntity(final int id) {
Employee e = entityManager.find(Employee.class, id);
entityManager.remove(e);
entityManager.flush();
}
@Override
public void setManagedBeanMessage(String message) {
this.managedBean.setMessage(message);
}
@Override
public String getManagedBeanMessage() {
return managedBean.getMessage();
}
@PostConstruct
public void postConstruct() {
Random r = new Random();
this.identificator = new Integer(r.nextInt(999)).toString();
log.trace("Bean [" + this.identificator + "] created");
}
@PreDestroy
public void preDestroy() {
log.trace("Bean [" + this.identificator + "] destroyed");
}
@PrePassivate
public void setPassivateFlag() {
log.trace(this.toString() + " PrePassivation [" + this.identificator + "]");
this.beenPassivated = true;
}
@PostActivate
public void setActivateFlag() {
log.trace(this.toString() + " PostActivation [" + this.identificator + "]");
this.beenActivated = true;
}
@Remove
@Override
public void close() {
log.trace("Bean [" + this.identificator + "] removing");
this.nestledBean.close();
}
}
| 4,679 | 28.808917 | 123 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/store/MultiStatefulCachesTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, 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.stateful.passivation.store;
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.integration.ejb.stateful.passivation.Bean;
import org.jboss.as.test.integration.ejb.stateful.passivation.PassivationEnabledBean;
import org.jboss.as.test.shared.CLIServerSetupTask;
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 javax.naming.InitialContext;
/**
* Test configures two passivation stores per deployment and calls the passivation bean. The call should succeed.
* Test for [ WFLY-11612 ].
*
* @author Daniel Cihak
*/
@RunWith(Arquillian.class)
@ServerSetup(org.jboss.as.test.integration.ejb.stateful.passivation.store.MultiStatefulCachesTestCase.ServerSetupTask.class)
public class MultiStatefulCachesTestCase {
private static final String DEPLOYMENT = "DEPLOYMENT";
private static final String DEFAULT_CONNECTION_SERVER = "jboss";
@ArquillianResource
private InitialContext ctx;
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, DEPLOYMENT + ".jar");
jar.addClasses(DifferentCachePassivationBean.class, PassivationEnabledBean.class, Bean.class, CLIServerSetupTask.class);
return jar;
}
@Test
public void testTwoPassivationStores() throws Exception {
try (Bean bean = (Bean) ctx.lookup("java:module/" + PassivationEnabledBean.class.getSimpleName() + "!" + Bean.class.getName())) {
bean.doNothing();
try (Bean differentCacheBean1 = (Bean) ctx.lookup("java:module/" + DifferentCachePassivationBean.class.getSimpleName() + "!" + Bean.class.getName())) {
differentCacheBean1.doNothing();
// Create a 2nd set of beans, forcing the first set to passivate
try (Bean bean2 = (Bean) ctx.lookup("java:module/" + PassivationEnabledBean.class.getSimpleName() + "!" + Bean.class.getName())) {
bean2.doNothing();
try (Bean differentCacheBean2 = (Bean) ctx.lookup("java:module/" + DifferentCachePassivationBean.class.getSimpleName() + "!" + Bean.class.getName())) {
differentCacheBean2.doNothing();
Assert.assertTrue("(Annotation based) Stateful bean marked as passivation enabled was not passivated", bean.wasPassivated());
Assert.assertTrue("(Annotation based) Stateful bean marked as passivation enabled was not activated", bean.wasActivated());
Assert.assertTrue("(Deployment descriptor based) Stateful bean marked as passivation enabled was not passivated", differentCacheBean1.wasPassivated());
Assert.assertTrue("(Deployment descriptor based) Stateful bean marked as passivation enabled was not activated", differentCacheBean1.wasActivated());
}
}
}
}
}
public static class ServerSetupTask extends CLIServerSetupTask {
/**
* This test setup originally depended upon manipulating the passivation-store for the default (passivating) cache.
* However, since WFLY-14953, passivation stores have been superseded by bean-management-providers
* i.e. use /subsystem=distributable-ejb/infinispan-bean-management=default instead of /subsystem=ejb3/passivation-store=infinispan
*/
public ServerSetupTask() {
this.builder.node(DEFAULT_CONNECTION_SERVER)
.reloadOnSetup(true)
.reloadOnTearDown(true)
.setup("/subsystem=distributable-ejb/infinispan-bean-management=another-bean-manager:add(cache-container=ejb, cache=passivation, max-active-beans=1)")
.setup("/subsystem=ejb3/distributable-cache=another-passivating-cache:add(bean-management=another-bean-manager)")
.setup("/subsystem=distributable-ejb/infinispan-bean-management=default:write-attribute(name=max-active-beans,value=1)")
.teardown("/subsystem=distributable-ejb/infinispan-bean-management=default:write-attribute(name=max-active-beans,value=10000)")
.teardown("/subsystem=ejb3/distributable-cache=another-passivating-cache:remove")
.teardown("/subsystem=distributable-ejb/infinispan-bean-management=another-bean-manager:remove");
}
}
}
| 5,767 | 51.917431 | 175 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/store/DifferentCachePassivationBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, 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.stateful.passivation.store;
import org.jboss.as.test.integration.ejb.stateful.passivation.Bean;
import org.jboss.ejb3.annotation.Cache;
import jakarta.ejb.Local;
import jakarta.ejb.PostActivate;
import jakarta.ejb.PrePassivate;
import jakarta.ejb.Remove;
import jakarta.ejb.Stateful;
@Stateful
@Cache("another-passivating-cache")
@Local(Bean.class)
public class DifferentCachePassivationBean implements Bean {
private boolean prePrePassivateInvoked;
private boolean postActivateInvoked;
@PrePassivate
private void beforePassivate() {
this.prePrePassivateInvoked = true;
}
@PostActivate
private void afterActivate() {
this.postActivateInvoked = true;
}
@Override
public boolean wasPassivated() {
return this.prePrePassivateInvoked;
}
@Override
public boolean wasActivated() {
return this.postActivateInvoked;
}
@Remove
@Override
public void close() {
}
}
| 2,033 | 29.358209 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/ejb2/PassivationSucceedsEJB2TestCase.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.stateful.passivation.ejb2;
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.integration.ejb.stateful.passivation.PassivationTestCaseSetup;
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;
/**
* Tests that passivation succeeds for ejb2 beans.
* @see org.jboss.as.test.integration.ejb.stateful.passivation.PassivationTestCase
*
* @author Ondrej Chaloupka
*/
@RunWith(Arquillian.class)
@ServerSetup(PassivationTestCaseSetup.class)
public class PassivationSucceedsEJB2TestCase {
private static String jndi;
@ArquillianResource
private InitialContext ctx;
static {
jndi = "java:module/" + TestPassivationBean.class.getSimpleName() + "!" + TestPassivationRemoteHome.class.getName();
}
@Deployment
public static Archive<?> deploy() throws Exception {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "passivation-ejb2-test.jar");
jar.addPackage(PassivationSucceedsEJB2TestCase.class.getPackage());
jar.addClasses(PassivationTestCaseSetup.class);
jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr"), "MANIFEST.MF");
return jar;
}
@Test
public void testPassivationMaxSize() throws Exception {
TestPassivationRemoteHome home = (TestPassivationRemoteHome) ctx.lookup(jndi);
TestPassivationRemote remote1 = home.create();
try {
Assert.assertEquals("Returned remote1 result was not expected", TestPassivationRemote.EXPECTED_RESULT,
remote1.returnTrueString());
Assert.assertFalse("ejbPassivate not called on remote1, check cache configuration and client sleep time", remote1.hasBeenPassivated());
Assert.assertFalse("ejbActivate not called on remote1", remote1.hasBeenActivated());
// create another bean. This should force the other bean to passivate, as only one bean is allowed in the pool at a time
TestPassivationRemote remote2 = home.create();
try {
Assert.assertEquals("Returned remote2 result was not expected", TestPassivationRemote.EXPECTED_RESULT,
remote2.returnTrueString());
Assert.assertFalse("ejbPassivate not called on remote2, check cache configuration and client sleep time",
remote2.hasBeenPassivated());
Assert.assertFalse("ejbActivate not called on remote2", remote2.hasBeenActivated());
Assert.assertTrue("ejbPassivate not called on remote1, check cache configuration and client sleep time",
remote1.hasBeenPassivated());
Assert.assertTrue("ejbActivate not called on remote1", remote1.hasBeenActivated());
Assert.assertTrue("ejbPassivate not called on remote2, check cache configuration and client sleep time",
remote2.hasBeenPassivated());
Assert.assertTrue("ejbActivate not called on remote2", remote2.hasBeenActivated());
} finally {
remote2.remove();
}
} finally {
remote1.remove();
}
}
}
| 4,668 | 44.330097 | 147 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/ejb2/TestPassivationBeanParent.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.stateful.passivation.ejb2;
import java.rmi.RemoteException;
import jakarta.ejb.EJBException;
import org.jboss.logging.Logger;
/**
* @author Ondrej Chaloupka
*/
public abstract class TestPassivationBeanParent {
private static final Logger log = Logger.getLogger(TestPassivationBeanParent.class);
protected String identificator;
protected boolean beenPassivated = false;
protected boolean beenActivated = false;
/**
* Overriding the ejbPassivate method of SessionBean on child class
*/
public void ejbPassivate() throws EJBException, RemoteException {
log.trace(this.toString() + " ejbPassivate [" + this.identificator + "]");
this.beenPassivated = true;
}
/**
* Overriding the ejbActivate method of SessionBean on child class
*/
public void ejbActivate() throws EJBException, RemoteException {
log.trace(this.toString() + " ejbActivate [" + this.identificator + "]");
this.beenActivated = true;
}
/**
* Overriding the ejbRemove method of SessionBean on child class
*/
public void ejbRemove() throws EJBException, RemoteException {
log.trace("Bean [" + this.identificator + "] destroyed");
}
}
| 2,289 | 35.349206 | 88 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/ejb2/TestPassivationRemoteHome.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.stateful.passivation.ejb2;
import jakarta.ejb.EJBHome;
/**
* @author Ondrej Chaloupka
*/
public interface TestPassivationRemoteHome extends EJBHome {
TestPassivationRemote create() throws java.rmi.RemoteException, jakarta.ejb.CreateException;
}
| 1,319 | 39 | 96 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/ejb2/TestPassivationRemote.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.stateful.passivation.ejb2;
/**
* @author Ondrej Chaloupka
*/
public interface TestPassivationRemote extends jakarta.ejb.EJBObject {
String EXPECTED_RESULT = "true";
/**
* Returns the expected result exposed as a static final variable by this interface
*/
String returnTrueString();
/**
* Returns whether or not this instance has been passivated
*/
boolean hasBeenPassivated();
/**
* Returns whether or not this instance has been activated
*/
boolean hasBeenActivated();
}
| 1,602 | 33.847826 | 87 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/passivation/ejb2/TestPassivationBean.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.stateful.passivation.ejb2;
import java.rmi.RemoteException;
import java.util.Random;
import jakarta.ejb.EJBException;
import jakarta.ejb.RemoteHome;
import jakarta.ejb.SessionBean;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateful;
import org.jboss.ejb3.annotation.Cache;
import org.jboss.logging.Logger;
/**
* @author Ondrej Chaloupka
*/
@Stateful
@Cache("distributable")
@RemoteHome(TestPassivationRemoteHome.class)
public class TestPassivationBean extends TestPassivationBeanParent implements SessionBean {
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(TestPassivationBean.class);
/**
* Returns the expected result
*/
public String returnTrueString() {
return TestPassivationRemote.EXPECTED_RESULT;
}
/**
* Returns whether or not this instance has been passivated
*/
public boolean hasBeenPassivated() {
return this.beenPassivated;
}
/**
* Returns whether or not this instance has been activated
*/
public boolean hasBeenActivated() {
return this.beenActivated;
}
/**
* "Called" by create() method of home interface.
*/
public void ejbCreate() {
Random r = new Random();
this.identificator = new Integer(r.nextInt(999)).toString();
log.trace("Bean [" + this.identificator + "] created");
}
@Override
public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException {
}
}
| 2,598 | 30.695122 | 93 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/serialization/AnnotatedBean.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.stateful.serialization;
import jakarta.ejb.Stateful;
/**
* stateful session bean
*
*/
@Stateful
public class AnnotatedBean {
private int value;
public int getValue() {
return value;
}
public void setValue(final int value) {
this.value = value;
}
}
| 1,358 | 29.886364 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/stateful/serialization/StatefulSerializationTestCase.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.stateful.serialization;
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.Test;
import org.junit.runner.RunWith;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Tests that the stateful timeout annotation works
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class StatefulSerializationTestCase {
private static final String ARCHIVE_NAME = "StatefulTimeoutTestCase";
@ArquillianResource
private InitialContext iniCtx;
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar");
jar.addPackage(StatefulSerializationTestCase.class.getPackage());
return jar;
}
protected <T> T lookup(Class<T> beanType) throws NamingException {
return beanType.cast(iniCtx.lookup("java:global/" + ARCHIVE_NAME + "/" + beanType.getSimpleName() + "!" + beanType.getName()));
}
@Test
public void testSerializingSfsbProxy() throws Exception {
AnnotatedBean sfsb1 = lookup(AnnotatedBean.class);
sfsb1.setValue(10);
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ObjectOutputStream stream = new ObjectOutputStream(bytes);
stream.writeObject(sfsb1);
stream.close();
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
AnnotatedBean bean = (AnnotatedBean) in.readObject();
in.close();
Assert.assertEquals(10, bean.getValue());
}
}
| 3,047 | 34.858824 | 135 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/RemoveTestCase.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.remove;
import jakarta.ejb.NoSuchEJBException;
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.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;
/**
* @author Scott Marlow
* @author Jan Martiska
* @Remove tests
*/
@RunWith(Arquillian.class)
public class RemoveTestCase {
private static final String ARCHIVE_NAME = "RemoveTestCase";
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar");
jar.addClasses(RemoveTestCase.class,
SFSB1.class
);
return jar;
}
@ArquillianResource
private InitialContext iniCtx;
protected <T> T lookup(String beanName, Class<T> interfaceType) throws NamingException {
return interfaceType.cast(iniCtx.lookup("java:global/" + ARCHIVE_NAME + "/" + beanName + "!" + interfaceType.getName()));
}
/**
* Ensure that invoked a bean method with the @Remove annotation, destroys the bean.
*
* @throws Exception
*/
@Test
public void testRemoveDestroysBean() throws Exception {
SFSB1 sfsb1 = lookup("SFSB1", SFSB1.class);
sfsb1.done(); // first call is expected to work
try {
sfsb1.done(); // second call is expected to fail since we are calling a destroyed bean
Assert.fail("Expecting NoSuchEJBException");
} catch (NoSuchEJBException expectedException) {
// good
}
Assert.assertTrue(SFSB1.preDestroyCalled);
}
/**
* Ensure that a Stateful bean gets properly @Remove-d even if it throws an exception within its @PreDestroy method
* Required by EJB 3.1 spec
*
* @throws Exception
*/
@Test
public void testRemoveDestroysBeanWhichDeniesRemoval() throws Exception {
SFSB1 sfsb1 = lookup("SFSB1", SFSB1.class);
sfsb1.doneAndDenyDestruction(); // first call is expected to work
try {
sfsb1.doneAndDenyDestruction(); // second call is expected to fail since we are calling a destroyed bean
Assert.fail("Expecting NoSuchEJBException");
} catch (NoSuchEJBException expectedException) {
// good
}
Assert.assertTrue(SFSB1.preDestroyCalled);
}
}
| 3,698 | 33.896226 | 129 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/SFSB1.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.remove;
import jakarta.annotation.PreDestroy;
import jakarta.ejb.Remove;
import jakarta.ejb.Stateful;
/**
* stateful session bean
*
* @author Scott Marlow
*/
@Stateful
public class SFSB1 {
public static volatile boolean preDestroyCalled = false;
private boolean shouldDenyDestruction = false;
@PreDestroy
private void preDestroy() {
preDestroyCalled = true;
if (shouldDenyDestruction) { throw new RuntimeException("Denying bean destruction"); }
}
// always throws a TransactionRequiredException
@Remove
public void done() {
}
@Remove
public void doneAndDenyDestruction() {
shouldDenyDestruction = true;
}
}
| 1,757 | 29.310345 | 94 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/Ejb21View.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.remove.method;
import java.rmi.RemoteException;
import jakarta.ejb.EJBObject;
/**
* An Ejb21View.
*
* @author <a href="[email protected]">ALR</a>
*/
public interface Ejb21View extends EJBObject {
String test() throws RemoteException;
}
| 1,313 | 36.542857 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/RemoveMethodInvocationTracker.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.remove.method;
/**
* @author Jaikiran Pai
*/
public interface RemoveMethodInvocationTracker {
boolean wasEjbRemoveCallbackInvoked();
void ejbRemoveCallbackInvoked();
}
| 1,247 | 35.705882 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/RemoveStatefulLocal.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.remove.method;
import jakarta.ejb.Local;
/**
* Local implementation of "Remove"
*
* @author <a href="mailto:[email protected]">ALR</a>
*/
@Local
public interface RemoveStatefulLocal extends Remove {
}
| 1,274 | 36.5 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/Ejb21ViewHome.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.remove.method;
import java.rmi.RemoteException;
import jakarta.ejb.EJBHome;
/**
* @author carlo
*/
public interface Ejb21ViewHome extends EJBHome {
Ejb21View create() throws RemoteException;
}
| 1,266 | 37.393939 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/RemoveMethodUnitTestCase.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.remove.method;
import java.rmi.NoSuchObjectException;
import jakarta.ejb.EJBObject;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
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.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Migration test from EJB Testsuite (ejbthree-786) to AS7 [JIRA JBQA-5483].
* We want a remove action on a backing bean.
*
* @author Carlo de Wolf, Ondrej Chaloupka
*/
@RunWith(Arquillian.class)
public class RemoveMethodUnitTestCase {
private static final String DD_BASED_MODULE_NAME = "remove-method-dd-test";
private static final String ANNOTATION_BASED_MODULE_NAME = "remove-method-test";
@ArquillianResource
InitialContext ctx;
@Deployment
public static Archive<?> deployment() {
final JavaArchive ejb3Jar = ShrinkWrap.create(JavaArchive.class, ANNOTATION_BASED_MODULE_NAME + ".jar").addPackage(
RemoveMethodUnitTestCase.class.getPackage());
final JavaArchive ejb2Jar = ShrinkWrap.create(JavaArchive.class, DD_BASED_MODULE_NAME + ".jar").addClasses(Ejb21ViewDDBean.class,
Ejb21View.class, Ejb21ViewHome.class, RemoveMethodUnitTestCase.class)
.addAsManifestResource(RemoveMethodUnitTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "remove-method-test.ear");
ear.addAsModules(ejb2Jar, ejb3Jar);
return ear;
}
@Test
public void testRemoveStatefulRemote() throws Exception {
RemoveStatefulRemote session = (RemoveStatefulRemote) ctx.lookup("java:app/" + ANNOTATION_BASED_MODULE_NAME + "/" + StatefulRemoveBean.class.getSimpleName() + "!" + RemoveStatefulRemote.class.getName());
String result = session.remove();
Assert.assertEquals(AbstractRemoveBean.RETURN_STRING, result);
}
@Test
public void testRemoveStatelessRemote() throws Exception {
RemoveStatelessRemote session = (RemoveStatelessRemote) ctx.lookup("java:app/" + ANNOTATION_BASED_MODULE_NAME + "/" + StatelessRemoveBean.class.getSimpleName() + "!" + RemoveStatelessRemote.class.getName());
String result = session.remove();
Assert.assertEquals(AbstractRemoveBean.RETURN_STRING, result);
}
@Test
public void testRemoveStatefulLocalViaDelegate() throws Exception {
Delegate session = (Delegate) ctx.lookup("java:app/" + ANNOTATION_BASED_MODULE_NAME + "/" + DelegateBean.class.getSimpleName() + "!" + Delegate.class.getName());
String result = session.invokeStatefulRemove();
Assert.assertEquals(AbstractRemoveBean.RETURN_STRING, result);
}
@Test
public void testRemoveStatelessLocalViaDelegate() throws Exception {
Delegate session = (Delegate) ctx.lookup("java:app/" + ANNOTATION_BASED_MODULE_NAME + "/" + DelegateBean.class.getSimpleName() + "!" + Delegate.class.getName());
String result = session.invokeStatelessRemove();
Assert.assertEquals(AbstractRemoveBean.RETURN_STRING, result);
}
@Test
public void testExplicitExtensionEjbObjectInProxy() throws Exception {
// Obtain stub
Object obj = ctx.lookup("java:app/" + ANNOTATION_BASED_MODULE_NAME + "/" + Ejb21ViewBean.class.getSimpleName() + "!" + Ejb21ViewHome.class.getName());
Ejb21ViewHome home = (Ejb21ViewHome) PortableRemoteObject.narrow(obj, Ejb21ViewHome.class);
Ejb21View session = home.create();
// Ensure EJBObject
Assert.assertTrue(session instanceof EJBObject);
// Cast and remove appropriately, ensuring removed
boolean removed = false;
String result = session.test();
Assert.assertEquals(Ejb21ViewBean.TEST_STRING, result);
session.remove();
try {
session.test();
} catch (Exception e) {
if (e instanceof NoSuchObjectException || e.getCause() instanceof NoSuchObjectException) {
removed = true;
} else {
Assert.fail("Exception received, " + e + ", was not expected and should have had root cause of " + NoSuchObjectException.class);
}
}
Assert.assertTrue("SFSB instance was not removed as expected", removed);
}
/**
* Test that ejbRemove() method was invoked on the bean when the remove() is invoked on the EJBObject
* of an EJB2.x view of a bean
*
* @throws Exception
*/
@Test
public void testEjbRemoveInvokedOnRemoval() throws Exception {
// Obtain stub
Object obj = ctx.lookup("java:app/" + DD_BASED_MODULE_NAME + "/" + Ejb21ViewDDBean.class.getSimpleName() + "!" + Ejb21ViewHome.class.getName());
Ejb21ViewHome home = (Ejb21ViewHome) PortableRemoteObject.narrow(obj, Ejb21ViewHome.class);
Ejb21View bean = home.create();
// Ensure EJBObject
Assert.assertTrue(bean instanceof EJBObject);
String result = bean.test();
bean.remove();
try {
bean.test();
Assert.fail("Invocation on a removed bean was expected to fail");
} catch (NoSuchObjectException e) {
// expected
}
final RemoveMethodInvocationTracker ejbRemoveMethodInvocationTracker = (RemoveMethodInvocationTracker) ctx.lookup("java:app/" + ANNOTATION_BASED_MODULE_NAME + "/" + RemoveMethodInvocationTrackerBean.class.getSimpleName() + "!" + RemoveMethodInvocationTracker.class.getName());
Assert.assertTrue("ejbRemove() method was not invoked after bean removal", ejbRemoveMethodInvocationTracker.wasEjbRemoveCallbackInvoked());
}
}
| 7,044 | 44.746753 | 284 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/Delegate.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.remove.method;
import jakarta.ejb.Remote;
/**
* A Delegate to invoke upon local views of the Remove EJBs
*
* @author <a href="[email protected]">ALR</a>
*/
@Remote
public interface Delegate {
String invokeStatelessRemove();
String invokeStatefulRemove();
}
| 1,339 | 35.216216 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/RemoveStatelessLocal.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.remove.method;
import jakarta.ejb.Local;
/**
* Local implementation of "Remove"
*
* @author <a href="mailto:[email protected]">ALR</a>
*/
@Local
public interface RemoveStatelessLocal extends Remove {
}
| 1,275 | 36.529412 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/Ejb21ViewDDBean.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.remove.method;
import java.rmi.RemoteException;
import jakarta.ejb.EJBException;
import jakarta.ejb.SessionBean;
import jakarta.ejb.SessionContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* @author Jaikiran Pai
*/
public class Ejb21ViewDDBean implements SessionBean {
@Override
public void setSessionContext(SessionContext sessionContext) throws EJBException, RemoteException {
}
public void ejbCreate() {
}
@Override
public void ejbRemove() throws EJBException, RemoteException {
try {
final Context ctx = new InitialContext();
final RemoveMethodInvocationTracker removeMethodInvocationTracker = (RemoveMethodInvocationTracker) ctx.lookup("java:app/remove-method-test/" + RemoveMethodInvocationTrackerBean.class.getSimpleName() + "!" + RemoveMethodInvocationTracker.class.getName());
removeMethodInvocationTracker.ejbRemoveCallbackInvoked();
} catch (NamingException ne) {
throw new RuntimeException(ne);
}
}
@Override
public void ejbActivate() throws EJBException, RemoteException {
}
@Override
public void ejbPassivate() throws EJBException, RemoteException {
}
public String test() throws RemoteException {
return this.getClass().getName();
}
}
| 2,438 | 33.352113 | 267 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/RemoveMethodInvocationTrackerBean.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.remove.method;
import jakarta.ejb.Remote;
import jakarta.ejb.Singleton;
/**
* @author Jaikiran Pai
*/
@Singleton
@Remote(RemoveMethodInvocationTracker.class)
public class RemoveMethodInvocationTrackerBean implements RemoveMethodInvocationTracker {
private boolean ejbRemoveCallbackInvoked;
@Override
public boolean wasEjbRemoveCallbackInvoked() {
return this.ejbRemoveCallbackInvoked;
}
@Override
public void ejbRemoveCallbackInvoked() {
this.ejbRemoveCallbackInvoked = true;
}
}
| 1,598 | 32.3125 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/AbstractRemoveBean.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.remove.method;
/**
* AbstractRemoveBean.
*
* @author <a href="[email protected]">ALR</a>
*/
public class AbstractRemoveBean implements Remove {
// Class Members
public static final String RETURN_STRING = "Remove";
// Required Implementations
public String remove() {
return AbstractRemoveBean.RETURN_STRING;
}
}
| 1,413 | 36.210526 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/RemoveStatefulRemote.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.remove.method;
import jakarta.ejb.Remote;
/**
* Remote implementation of "Remove"
*
* @author <a href="mailto:[email protected]">ALR</a>
*/
@Remote
public interface RemoveStatefulRemote extends Remove {
}
| 1,278 | 36.617647 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/StatefulRemoveBean.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.remove.method;
import jakarta.ejb.Stateful;
/**
* Defines a custom "remove" method that is not associated w/ EJBOBject/EJBLocalObject.remove
*
* @author <a href="mailto:[email protected]">ALR</a>
*/
@Stateful
public class StatefulRemoveBean extends AbstractRemoveBean implements RemoveStatefulRemote, RemoveStatefulLocal {
}
| 1,399 | 39 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/Remove.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.remove.method;
/**
* Defines a method named "remove" of return type "String"
*
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
* @author <a href="mailto:[email protected]">ALR</a>
*/
public interface Remove {
String remove();
}
| 1,325 | 39.181818 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/StatelessRemoveBean.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.remove.method;
import jakarta.ejb.Stateless;
/**
* Defines a custom "remove" method that is not associated w/ EJBOBject/EJBLocalObject.remove
*
* @author <a href="mailto:[email protected]">ALR</a>
*/
@Stateless
public class StatelessRemoveBean extends AbstractRemoveBean implements RemoveStatelessRemote, RemoveStatelessLocal {
}
| 1,403 | 40.294118 | 116 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/DelegateBean.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.remove.method;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
@Stateless
public class DelegateBean implements Delegate {
// Instance Members
@EJB
private RemoveStatefulLocal stateful;
@EJB
private RemoveStatelessLocal stateless;
// Required Implementations
public String invokeStatefulRemove() {
return stateful.remove();
}
public String invokeStatelessRemove() {
return stateless.remove();
}
}
| 1,531 | 30.916667 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/Ejb21ViewBean.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.remove.method;
import java.rmi.RemoteException;
import jakarta.ejb.RemoteHome;
import jakarta.ejb.Stateful;
@Stateful
@RemoteHome(Ejb21ViewHome.class)
public class Ejb21ViewBean {
// Class Members
public static final String TEST_STRING = "Test";
// Required Implementations
public String test() throws RemoteException {
return Ejb21ViewBean.TEST_STRING;
}
public void ejbCreate() {
}
}
| 1,493 | 32.954545 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remove/method/RemoveStatelessRemote.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.remove.method;
import jakarta.ejb.Remote;
/**
* Remote implementation of "Remove"
*
* @author <a href="mailto:[email protected]">ALR</a>
*/
@Remote
public interface RemoveStatelessRemote extends Remove {
}
| 1,279 | 36.647059 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/SingleMethodsAnnSLSBTestCase.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;
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.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.authorization.SingleMethodsAnnOnlyCheckSLSB;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
/**
* Checks whether basic EJB authorization works from EJB client to remote stateful EJB.
*
* @author <a href="mailto:[email protected]">Peter Skopek</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
@Category(CommonCriteria.class)
public class SingleMethodsAnnSLSBTestCase extends AnnSBTest {
private static final Logger log = Logger.getLogger(testClass());
private static final String MODULE = "singleMethodsAnnOnlySLSB";
private static Class testClass() {
return SingleMethodsAnnSLSBTestCase.class;
}
private static Class beanClass() {
return SingleMethodsAnnOnlyCheckSLSB.class;
}
@Deployment(name = MODULE + ".jar", order = 1, testable = false)
public static Archive<JavaArchive> deployment() {
return testAppDeployment(Logger.getLogger(testClass()), MODULE, beanClass());
}
@Test
public void testSingleMethodAnnotationsNoUser() throws Exception {
testSingleMethodAnnotationsNoUserTemplate(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser1() throws Exception {
testSingleMethodAnnotationsUser1Template(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser2() throws Exception {
testSingleMethodAnnotationsUser2Template(MODULE, log, beanClass());
}
}
| 2,935 | 36.641026 | 94 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/WhoAmIServlet.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;
import java.io.IOException;
import java.io.Writer;
import java.util.concurrent.Callable;
import jakarta.annotation.security.DeclareRoles;
import jakarta.ejb.EJB;
import jakarta.ejb.EJBException;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.HttpConstraint;
import jakarta.servlet.annotation.ServletSecurity;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jboss.as.test.shared.integration.ejb.security.Util;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
@WebServlet(urlPatterns = "/whoAmI", loadOnStartup = 1)
@ServletSecurity(@HttpConstraint(rolesAllowed = { "Users" }))
@DeclareRoles("Users")
public class WhoAmIServlet extends HttpServlet {
@EJB
private Entry bean;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Writer writer = resp.getWriter();
String method = req.getParameter("method");
String username = req.getParameter("username");
String password = req.getParameter("password");
String role = req.getParameter("role");
if ("whoAmI".equals(method)) {
try {
Callable<Void> callable = () -> {
writer.write(bean.whoAmI());
return null;
};
Util.switchIdentity(username, password, callable);
} catch (Exception e) {
throw new IOException("Unexpected failure", e);
}
} else if ("doubleWhoAmI".equals(method)) {
String[] response;
try {
if (username != null && password != null) {
response = bean.doubleWhoAmI(username, password);
} else {
response = bean.doubleWhoAmI();
}
} catch (EJBException e) {
resp.sendError(HttpServletResponse.SC_FORBIDDEN, e.toString());
return;
} catch (Exception e) {
throw new ServletException("Unexpected failure", e);
}
writer.write(response[0] + "," + response[1]);
} else if ("doIHaveRole".equals(method)) {
try {
Callable<Void> callable = () -> {
writer.write(String.valueOf(bean.doIHaveRole(role)));
return null;
};
Util.switchIdentity(username, password, callable);
} catch (Exception e) {
throw new IOException("Unexpected failure", e);
}
} else if ("doubleDoIHaveRole".equals(method)) {
try {
boolean[] response = null;
if (username != null && password != null) {
response = bean.doubleDoIHaveRole(role, username, password);
} else {
response = bean.doubleDoIHaveRole(role);
}
writer.write(String.valueOf(response[0]) + "," + String.valueOf(response[1]));
} catch (Exception e) {
throw new ServletException("Unexpected Failure", e);
}
} else {
throw new IllegalArgumentException("Parameter 'method' either missing or invalid method='" + method + "'");
}
}
}
| 4,619 | 39.526316 | 119 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/BeanWithoutExplicitSecurityDomain.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;
import jakarta.annotation.Resource;
import jakarta.annotation.security.DenyAll;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.Local;
import jakarta.ejb.LocalBean;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
/**
* @author Jaikiran Pai
*/
@Stateless
@Local({Restriction.class, FullAccess.class})
@LocalBean
public class BeanWithoutExplicitSecurityDomain implements Restriction, FullAccess {
@Resource
private SessionContext sessionContext;
@Override
@DenyAll
public void restrictedMethod() {
throw new RuntimeException("No one was expected to be able to call this method");
}
@Override
@PermitAll
public void doAnything() {
}
@RolesAllowed("Role1")
public void allowOnlyRoleOneToAccess() {
if (!this.sessionContext.isCallerInRole("Role1")) {
throw new RuntimeException("Only user(s) in role1 were expected to have access to this method");
}
}
@RolesAllowed("Role2")
public void allowOnlyRoleTwoToAccess() {
if (!this.sessionContext.isCallerInRole("Role2")) {
throw new RuntimeException("Only user(s) in role2 were expected to have access to this method");
}
}
}
| 2,363 | 32.295775 | 108 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/Entry.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;
import jakarta.ejb.Local;
/**
* Interface for the bean used as the entry point to verify EJB3 security behaviour.
*
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
@Local
public interface Entry {
/**
* @return The name of the Principal obtained from a call to EJBContext.getCallerPrincipal()
*/
String whoAmI();
/**
* Obtains the name of the Principal obtained from a call to EJBContext.getCallerPrincipal()
* both for the bean called and also from a call to a second bean.
*
* @return An array containing the name from the local call first followed by the name from
* the second call.
*/
String[] doubleWhoAmI();
/**
* As doubleWhoAmI except the user is switched before the second call.
*
* @see this.doubleWhoAmI()
* @param username - The username to use for the second call.
* @param password - The password to use for the second call.
* @return An array containing the name from the local call first followed by the name from
* the second call.
* @throws Exception - If there is an unexpected failure establishing the security context for
* the second call.
*/
String[] doubleWhoAmI(String username, String password) throws Exception;
/**
* @param roleName - The role to check.
* @return the response from EJBContext.isCallerInRole() with the supplied role name.
*/
boolean doIHaveRole(String roleName);
/**
* Calls EJBContext.isCallerInRole() with the supplied role name and then calls a second bean
* which makes the same call.
*
* @param roleName - the role name to check.
* @return the values from the isCallerInRole() calls, the EntryBean is first and the second bean
* second.
*/
boolean[] doubleDoIHaveRole(String roleName);
/**
* As doubleDoIHaveRole except the user is switched before the second call.
*
* @see this.doubleDoIHaveRole(String)
* @param roleName - The role to check.
* @param username - The username to use for the second call.
* @param password - The password to use for the second call.
* @return @return the values from the isCallerInRole() calls, the EntryBean is first and the second bean
* second.
* @throws Exception - If their is an unexpected failure.
*/
boolean[] doubleDoIHaveRole(String roleName, String username, String password) throws Exception;
}
| 3,550 | 38.021978 | 109 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/MixedSecurityAnnotationAuthorizationTestCase.java
|
package org.jboss.as.test.integration.ejb.security;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.authorization.DenyAllOverrideBean;
import org.jboss.as.test.integration.ejb.security.authorization.PermitAllOverrideBean;
import org.jboss.as.test.integration.ejb.security.authorization.RolesAllowedOverrideBean;
import org.jboss.as.test.integration.ejb.security.authorization.RolesAllowedOverrideBeanBase;
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.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.security.auth.server.SecurityDomain;
import org.wildfly.security.auth.server.SecurityIdentity;
import org.wildfly.security.evidence.PasswordGuessEvidence;
import org.wildfly.security.permission.ElytronPermission;
import org.wildfly.test.security.common.elytron.EjbElytronDomainSetup;
import org.wildfly.test.security.common.elytron.ElytronDomainSetup;
import org.wildfly.test.security.common.elytron.ServletElytronDomainSetup;
import jakarta.ejb.EJB;
import jakarta.ejb.EJBAccessException;
import java.io.File;
import java.util.concurrent.Callable;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* Test case to test the general authorization requirements for annotated beans. The server setup has both
* an application-security-domain backed by Elytron security domain and legacy security domain with the same name.
*
* @author <a href="mailto:[email protected]">Michal Jurc</a> (c) 2017 Red Hat, Inc.
*/
@RunWith(Arquillian.class)
@ServerSetup({
MixedSecurityAnnotationAuthorizationTestCase.OverridingElytronDomainSetup.class,
MixedSecurityAnnotationAuthorizationTestCase.OverridingEjbElytronDomainSetup.class,
MixedSecurityAnnotationAuthorizationTestCase.OverridingServletElytronDomainSetup.class})
public class MixedSecurityAnnotationAuthorizationTestCase {
@Deployment
public static Archive<?> runAsDeployment() {
final Package currentPackage = AnnotationAuthorizationTestCase.class.getPackage();
final WebArchive war = ShrinkWrap.create(WebArchive.class, "ejb3security.war")
.addClasses(RolesAllowedOverrideBean.class, RolesAllowedOverrideBeanBase.class, PermitAllOverrideBean.class, DenyAllOverrideBean.class).addClass(Util.class)
.addClasses(MixedSecurityAnnotationAuthorizationTestCase.class)
.addClasses(AbstractSecurityDomainSetup.class, EjbSecurityDomainSetup.class, ElytronDomainSetup.class, EjbElytronDomainSetup.class, ServletElytronDomainSetup.class)
.addAsWebInfResource(currentPackage, "jboss-web.xml", "jboss-web.xml");
war.addAsManifestResource(createPermissionsXmlAsset(
new ElytronPermission("getSecurityDomain"),
new ElytronPermission("authenticate")
), "permissions.xml");
war.addPackage(CommonCriteria.class.getPackage());
return war;
}
@EJB(mappedName = "java:global/ejb3security/RolesAllowedOverrideBean")
private RolesAllowedOverrideBean rolesAllowedOverridenBean;
/*
* Test overrides within a bean annotated @RolesAllowed at bean level.
*/
@Test
public void testRolesAllowedOverriden_NoUser() throws Exception {
Assert.assertNotNull("An Elytron security domain should be associated with test EJB deployment.", SecurityDomain.getCurrent());
try {
rolesAllowedOverridenBean.defaultEcho("1");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
try {
rolesAllowedOverridenBean.denyAllEcho("2");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
String response = rolesAllowedOverridenBean.permitAllEcho("3");
assertEquals("3", response);
try {
rolesAllowedOverridenBean.role2Echo("4");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
}
@Test
public void testRolesAllowedOverriden_User1() throws Exception {
Assert.assertNotNull("An Elytron security domain should be associated with test EJB deployment.", SecurityDomain.getCurrent());
final Callable<Void> callable = () -> {
String response = rolesAllowedOverridenBean.defaultEcho("1");
assertEquals("1", response);
try {
rolesAllowedOverridenBean.denyAllEcho("2");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
response = rolesAllowedOverridenBean.permitAllEcho("3");
assertEquals("3", response);
try {
rolesAllowedOverridenBean.role2Echo("4");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
return null;
};
runAsElytronIdentity("user1", "elytronPassword1", callable);
}
@Test
public void testRolesAllowedOverridenInBaseClass_Admin() throws Exception {
Assert.assertNotNull("An Elytron security domain should be associated with test EJB deployment.", SecurityDomain.getCurrent());
final Callable<Void> callable = () -> {
try {
rolesAllowedOverridenBean.aMethod("aMethod");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
String response = rolesAllowedOverridenBean.bMethod("bMethod");
assertEquals("bMethod", response);
return null;
};
runAsElytronIdentity("admin", "elytronAdmin", callable);
}
@Test
public void testRolesAllowedOverridenInBaseClass_HR() throws Exception {
Assert.assertNotNull("An Elytron security domain should be associated with test EJB deployment.", SecurityDomain.getCurrent());
final Callable<Void> callable = () -> {
String response = rolesAllowedOverridenBean.aMethod("aMethod");
assertEquals("aMethod", response);
try {
rolesAllowedOverridenBean.bMethod("bMethod");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
return null;
};
runAsElytronIdentity("hr", "elytronHr", callable);
}
@Test
public void testRolesAllowedOverriden_User2() throws Exception {
Assert.assertNotNull("An Elytron security domain should be associated with test EJB deployment.", SecurityDomain.getCurrent());
final Callable<Void> callable = () -> {
try {
rolesAllowedOverridenBean.defaultEcho("1");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
try {
rolesAllowedOverridenBean.denyAllEcho("2");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
String response = rolesAllowedOverridenBean.permitAllEcho("3");
assertEquals("3", response);
response = rolesAllowedOverridenBean.role2Echo("4");
assertEquals("4", response);
return null;
};
runAsElytronIdentity("user2", "elytronPassword2", callable);
}
/*
* Test overrides of bean annotated at bean level with @PermitAll
*/
@EJB(mappedName = "java:global/ejb3security/PermitAllOverrideBean")
private PermitAllOverrideBean permitAllOverrideBean;
@Test
public void testPermitAllOverride_NoUser() throws Exception {
Assert.assertNotNull("An Elytron security domain should be associated with test EJB deployment.", SecurityDomain.getCurrent());
String response = permitAllOverrideBean.defaultEcho("1");
assertEquals("1", response);
try {
permitAllOverrideBean.denyAllEcho("2");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
try {
permitAllOverrideBean.role1Echo("3");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
}
@Test
public void testPermitAllOverride_User1() throws Exception {
Assert.assertNotNull("An Elytron security domain should be associated with test EJB deployment.", SecurityDomain.getCurrent());
final Callable<Void> callable = () -> {
String response = permitAllOverrideBean.defaultEcho("1");
assertEquals("1", response);
try {
permitAllOverrideBean.denyAllEcho("2");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
response = permitAllOverrideBean.role1Echo("3");
assertEquals("3", response);
return null;
};
runAsElytronIdentity("user1", "elytronPassword1", callable);
}
/*
* Test overrides of ben annotated at bean level with @DenyAll
*/
@EJB(mappedName = "java:global/ejb3security/DenyAllOverrideBean")
private DenyAllOverrideBean denyAllOverrideBean;
@Test
public void testDenyAllOverride_NoUser() throws Exception {
Assert.assertNotNull("An Elytron security domain should be associated with test EJB deployment.", SecurityDomain.getCurrent());
try {
denyAllOverrideBean.defaultEcho("1");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
String response = denyAllOverrideBean.permitAllEcho("2");
assertEquals("2", response);
try {
denyAllOverrideBean.role1Echo("3");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
}
@Test
public void testDenyAllOverride_User1() throws Exception {
Assert.assertNotNull("An Elytron security domain should be associated with test EJB deployment.", SecurityDomain.getCurrent());
final Callable<Void> callable = () -> {
try {
denyAllOverrideBean.defaultEcho("1");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
String response = denyAllOverrideBean.permitAllEcho("2");
assertEquals("2", response);
response = denyAllOverrideBean.role1Echo("3");
assertEquals("3", response);
return null;
};
runAsElytronIdentity("user1", "elytronPassword1", callable);
}
/**
* Tests that a method which accepts an array as a parameter and is marked with @PermitAll is allowed to be invoked by clients.
*
* @throws Exception
*/
@Test
public void testPermitAllMethodWithArrayParams() throws Exception {
Assert.assertNotNull("An Elytron security domain should be associated with test EJB deployment.", SecurityDomain.getCurrent());
final Callable<Void> callable = () -> {
final String[] messages = new String[] {"foo", "bar"};
final String[] echoes = denyAllOverrideBean.permitAllEchoWithArrayParams(messages);
assertArrayEquals("Unexpected echoes returned by bean method", messages, echoes);
return null;
};
runAsElytronIdentity("user1", "elytronPassword1", callable);
}
private static <T> T runAsElytronIdentity(final String username, final String password, final Callable<T> callable) throws Exception {
if (username != null && password != null) {
final SecurityDomain securityDomain = SecurityDomain.getCurrent();
final SecurityIdentity securityIdentity = securityDomain.authenticate(username, new PasswordGuessEvidence(password.toCharArray()));
return securityIdentity.runAs(callable);
}
return callable.call();
}
public static class OverridingElytronDomainSetup extends ElytronDomainSetup {
public OverridingElytronDomainSetup() {
super(new File(MixedSecurityAnnotationAuthorizationTestCase.class.getResource("elytronusers.properties").getFile()).getAbsolutePath(),
new File(MixedSecurityAnnotationAuthorizationTestCase.class.getResource("roles.properties").getFile()).getAbsolutePath());
}
}
public static class OverridingEjbElytronDomainSetup extends EjbElytronDomainSetup {
@Override
protected String getEjbDomainName() {
return "ejb3-tests";
}
}
public static class OverridingServletElytronDomainSetup extends ServletElytronDomainSetup {
@Override
protected String getUndertowDomainName() {
return "ejb3-tests";
}
}
}
| 13,679 | 40.454545 | 180 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/FullAccess.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;
/**
* User: jpai
*/
public interface FullAccess {
void doAnything();
}
| 1,155 | 35.125 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/RunAsPrincipalTestCase.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;
import java.util.Arrays;
import java.util.Collection;
import java.util.PropertyPermission;
import java.util.concurrent.Callable;
import jakarta.ejb.EJBAccessException;
import javax.naming.InitialContext;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
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.test.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.runasprincipal.Caller;
import org.jboss.as.test.integration.ejb.security.runasprincipal.CallerRunAsPrincipal;
import org.jboss.as.test.integration.ejb.security.runasprincipal.CallerWithIdentity;
import org.jboss.as.test.integration.ejb.security.runasprincipal.SingletonBean;
import org.jboss.as.test.integration.ejb.security.runasprincipal.StatelessBBean;
import org.jboss.as.test.integration.ejb.security.runasprincipal.WhoAmI;
import org.jboss.as.test.integration.ejb.security.runasprincipal.transitive.SimpleSingletonBean;
import org.jboss.as.test.integration.ejb.security.runasprincipal.transitive.SingletonStartupBean;
import org.jboss.as.test.integration.ejb.security.runasprincipal.transitive.StatelessSingletonUseBean;
import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup;
import org.jboss.as.test.shared.TestLogHandlerSetupTask;
import org.jboss.as.test.shared.integration.ejb.security.PermissionUtils;
import org.jboss.as.test.shared.integration.ejb.security.Util;
import org.jboss.as.test.shared.util.LoggingUtil;
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.WebArchive;
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;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
/**
* Migration of test from EJB3 testsuite [JBQA-5451] Testing calling with runasprincipal annotation (ejbthree1945)
*
* @author Carlo de Wolf, Ondrej Chaloupka
*/
@RunWith(Arquillian.class)
@ServerSetup({EjbSecurityDomainSetup.class, RunAsPrincipalTestCase.TestLogHandlerSetup.class})
@Category(CommonCriteria.class)
public class RunAsPrincipalTestCase {
private static final Logger log = Logger.getLogger(RunAsPrincipalTestCase.class);
private static final String STARTUP_SINGLETON_DEPLOYMENT = "startup-transitive-singleton";
private static final String DEPLOYMENT = "runasprincipal-test";
@ArquillianResource
public Deployer deployer;
@Deployment(name = STARTUP_SINGLETON_DEPLOYMENT, managed = false, testable = false)
public static Archive<?> runAsStartupTransitiveDeployment() {
// using JavaArchive doesn't work, because of a bug in Arquillian, it only deploys wars properly
final WebArchive war = ShrinkWrap.create(WebArchive.class, STARTUP_SINGLETON_DEPLOYMENT + ".war")
.addClass(WhoAmI.class)
.addClass(StatelessBBean.class)
.addClass(SingletonStartupBean.class)
.addPackage(Assert.class.getPackage())
.addClass(Util.class)
.addClass(Entry.class)
.addClass(RunAsPrincipalTestCase.class)
.addClasses(AbstractSecurityDomainSetup.class, EjbSecurityDomainSetup.class)
.addAsWebInfResource(RunAsPrincipalTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml")
.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client,org.jboss.dmr\n"), "MANIFEST.MF")
.addAsManifestResource(createPermissionsXmlAsset(new ElytronPermission("getSecurityDomain"),
new ElytronPermission("authenticate")), "permissions.xml");
war.addPackage(CommonCriteria.class.getPackage());
return war;
}
@Deployment
public static Archive<?> runAsDeployment() {
// using JavaArchive doesn't work, because of a bug in Arquillian, it only deploys wars properly
final WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT + ".war")
.addPackage(WhoAmI.class.getPackage())
.addClass(SimpleSingletonBean.class)
.addClass(StatelessSingletonUseBean.class)
.addClass(Util.class)
.addClass(Entry.class)
.addClass(RunAsPrincipalTestCase.class)
.addClass(TestLogHandlerSetupTask.class)
.addClass(LoggingUtil.class)
.addClasses(AbstractSecurityDomainSetup.class, EjbSecurityDomainSetup.class)
.addAsWebInfResource(RunAsPrincipalTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml")
.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client,org.jboss.dmr\n"), "MANIFEST.MF")
// TODO WFLY-15289 The Elytron permissions need to be checked, should a deployment really need these?
.addAsManifestResource(createPermissionsXmlAsset(new ElytronPermission("getSecurityDomain"),
new PropertyPermission("jboss.server.log.dir", "read"),
PermissionUtils.createFilePermission("read", "standalone", "log", TEST_LOG_FILE_NAME),
new ElytronPermission("authenticate"),
new ElytronPermission("getIdentity"),
new ElytronPermission("createAdHocIdentity"),
new ChangeRoleMapperPermission("ejb"),
new ElytronPermission("setRunAsPrincipal")), "permissions.xml");
war.addPackage(CommonCriteria.class.getPackage());
return war;
}
private WhoAmI lookupCallerWithIdentity() throws Exception {
return (WhoAmI)new InitialContext().lookup("java:module/" + CallerWithIdentity.class.getSimpleName() + "!" + WhoAmI.class.getName());
}
private WhoAmI lookupSingleCallerWithIdentity() throws Exception {
return (WhoAmI)new InitialContext().lookup("java:module/" + SingletonBean.class.getSimpleName() + "!" + WhoAmI.class.getName());
}
private WhoAmI lookupCaller() throws Exception {
return (WhoAmI)new InitialContext().lookup("java:module/" + Caller.class.getSimpleName() + "!" + WhoAmI.class.getName());
}
private WhoAmI lookupCallerRunAsPrincipal() throws Exception {
return (WhoAmI)new InitialContext().lookup("java:module/" + CallerRunAsPrincipal.class.getSimpleName() + "!" + WhoAmI.class.getName());
}
private WhoAmI lookupSingletonUseBeanWithIdentity() throws Exception {
return (WhoAmI) new InitialContext().lookup("java:module/" + StatelessSingletonUseBean.class.getSimpleName() + "!" + WhoAmI.class.getName());
}
@Test
public void testJackInABox() throws Exception {
final Callable<Void> callable = () -> {
WhoAmI bean = lookupCallerWithIdentity();
String actual = bean.getCallerPrincipal();
Assert.assertEquals("jackinabox", actual);
return null;
};
Util.switchIdentitySCF("user1", "password1", callable);
}
@Test
public void testSingletonPostconstructSecurity() throws Exception {
final Callable<Void> callable = () -> {
WhoAmI bean = lookupSingleCallerWithIdentity();
String actual = bean.getCallerPrincipal();
Assert.assertEquals("Helloween", actual);
return null;
};
Util.switchIdentitySCF("user1", "password1", callable);
}
/**
* Test when only RunAsPrincipal is defined, it should fail but also warn the user about
* configuration problem.
* @throws Exception
*/
@Test
public void testRunAsPrincipal() throws Exception {
WhoAmI bean = lookupCallerRunAsPrincipal();
try {
String actual = bean.getCallerPrincipal();
Assert.fail("Expected EJBAccessException and it was get identity: " + actual);
} catch (EJBAccessException e) {
// good
Assert.assertTrue("@RunAs warning not found", LoggingUtil.hasLogMessage(TEST_LOG_FILE_NAME, LOG_MESSAGE));
}
}
@Test
public void testAnonymous() throws Exception {
final Callable<Void> callable = () -> {
WhoAmI bean = lookupCaller();
String actual = bean.getCallerPrincipal();
Assert.assertEquals("anonymous", actual);
return null;
};
Util.switchIdentitySCF("user1", "password1", callable);
}
@Test
@OperateOnDeployment(STARTUP_SINGLETON_DEPLOYMENT)
public void testStartupSingletonPostconstructSecurityNotPropagating() {
try {
deployer.deploy(STARTUP_SINGLETON_DEPLOYMENT);
Assert.fail("Deployment should fail");
} catch (Exception dex) {
Throwable t = checkEjbException(dex);
log.trace("Expected deployment error because the Singleton has nosecurity context per itself", dex.getCause());
MatcherAssert.assertThat(t.getMessage(), t.getMessage(), CoreMatchers.containsString("WFLYEJB0364"));
} finally {
deployer.undeploy(STARTUP_SINGLETON_DEPLOYMENT);
}
}
@Test
public void testSingletonPostconstructSecurityNotPropagating() throws Exception {
final Callable<Void> callable = () -> {
WhoAmI bean = lookupSingletonUseBeanWithIdentity(); //To load the singleton
bean.getCallerPrincipal();
Assert.fail("EJB call should fail - identity should not be propagated from @PostConstruct method");
return null;
};
try {
Util.switchIdentitySCF("user1", "password1", callable);
} catch (Exception dex) {
Throwable t = checkEjbException(dex);
log.trace("Expected EJB call fail because identity should not be propagated from @PostConstruct method", dex.getCause());
MatcherAssert.assertThat(t.getMessage(), t.getMessage(), CoreMatchers.containsString("WFLYEJB0364"));
}
}
private Throwable checkEjbException(Throwable ex) {
if (ex instanceof EJBAccessException) {
return ex;
}
if (ex.getCause() != null) {
return checkEjbException(ex.getCause());
}
return ex;
}
private static final String TEST_HANDLER_NAME;
private static final String TEST_LOG_FILE_NAME;
private static final String LOG_MESSAGE;
static {
/*
* Make both the test handler name and the test log file specific for this class and execution so that we do not
* interfere with other test classes or multiple subsequent executions of this class against the same container
*/
TEST_HANDLER_NAME = "test-" + RunAsPrincipalTestCase.class.getSimpleName();
TEST_LOG_FILE_NAME = TEST_HANDLER_NAME + ".log";
LOG_MESSAGE = "WFLYEJB0510";
}
public static class TestLogHandlerSetup extends TestLogHandlerSetupTask {
@Override
public Collection<String> getCategories() {
return Arrays.asList("org.jboss.as.ejb3.deployment");
}
@Override
public String getLevel() {
return "WARN";
}
@Override
public String getHandlerName() {
return TEST_HANDLER_NAME;
}
@Override
public String getLogFileName() {
return TEST_LOG_FILE_NAME;
}
}
}
| 13,125 | 45.21831 | 149 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/AnnSBTest.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;
import java.util.HashMap;
import java.util.Map;
import javax.naming.Context;
import javax.naming.NamingException;
import jakarta.ejb.EJBAccessException;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.authorization.AnnOnlyCheckSFSBForInjection;
import org.jboss.as.test.integration.ejb.security.authorization.AnnOnlyCheckSLSBForInjection;
import org.jboss.as.test.integration.ejb.security.authorization.ParentAnnOnlyCheck;
import org.jboss.as.test.integration.ejb.security.authorization.SimpleAuthorizationRemote;
import org.jboss.as.test.shared.integration.ejb.security.Util;
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.junit.Assert;
import org.wildfly.security.auth.client.AuthenticationConfiguration;
import org.wildfly.security.auth.client.AuthenticationContext;
import org.wildfly.security.auth.client.MatchRule;
import org.wildfly.security.auth.principal.AnonymousPrincipal;
import org.wildfly.security.sasl.SaslMechanismSelector;
import org.xnio.OptionMap;
import org.xnio.Options;
import org.xnio.Property;
import org.xnio.Sequence;
/**
* This is a common parent for test cases to check whether basic EJB authorization works from an EJB client to a remote EJB.
*
* @author <a href="mailto:[email protected]">Jan Lanik</a>
*/
public abstract class AnnSBTest {
@ContainerResource
private ManagementClient managementClient;
public static Archive<JavaArchive> testAppDeployment(final Logger LOG, final String MODULE, final Class SB_TO_TEST) {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE + ".jar")
.addClass(SB_TO_TEST)
.addClass(SimpleAuthorizationRemote.class)
.addClass(ParentAnnOnlyCheck.class)
.addClass(AnnOnlyCheckSLSBForInjection.class)
.addClass(AnnOnlyCheckSFSBForInjection.class);
jar.addAsManifestResource(AnnSBTest.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
jar.addPackage(CommonCriteria.class.getPackage());
return jar;
}
private SimpleAuthorizationRemote getBean(final String MODULE, final Logger log, final Class SB_CLASS, Context ctx) throws NamingException {
String myContext = Util.createRemoteEjbJndiContext(
"",
MODULE,
"",
SB_CLASS.getSimpleName(),
SimpleAuthorizationRemote.class.getName(),
isBeanClassStatefull(SB_CLASS));
log.trace("JNDI name=" + myContext);
return (SimpleAuthorizationRemote) ctx.lookup(myContext);
}
/**
* Test objective:
* Check if default, @RolesAllowed, @PermitAll, @DenyAll and @RolesAllowed with multiple roles
* works on method level without user logged in as described in EJB 3.1 spec.
* The target session bean is given as parameter
* Expected results:
* Test has to finish without any exception or error.
*
* @throws Exception
*/
public void testSingleMethodAnnotationsNoUserTemplate(final String MODULE, final Logger log, final Class SB_CLASS) throws Exception {
final Context ctx = Util.createNamingContext();
final AuthenticationContext authenticationContext = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.empty().useAuthorizationPrincipal(AnonymousPrincipal.getInstance()));
authenticationContext.runCallable(() -> {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).defaultAccess("alohomora");
Assert.assertEquals(echoValue, "alohomora");
try {
echoValue = getBean(MODULE, log, SB_CLASS, ctx).roleBasedAccessOne("alohomora");
Assert.fail("Method cannot be successfully called without logged in user");
} catch (Exception e) {
// expected
Assert.assertTrue("Thrown exception must be EJBAccessException, but was " + e.getClass().getSimpleName(), e instanceof EJBAccessException);
}
try {
echoValue = getBean(MODULE, log, SB_CLASS, ctx).roleBasedAccessMore("alohomora");
Assert.fail("Method cannot be successfully called without logged in user");
} catch (EJBAccessException e) {
// expected
}
try {
echoValue = getBean(MODULE, log, SB_CLASS, ctx).permitAll("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (Exception e) {
Assert.fail("@PermitAll annotation must allow all users and no users to call the method");
}
try {
echoValue = getBean(MODULE, log, SB_CLASS, ctx).denyAll("alohomora");
Assert.fail("@DenyAll annotation must allow all users and no users to call the method");
} catch (Exception e) {
// expected
Assert.assertTrue("Thrown exception must be EJBAccessException, but was " + e.getClass().getSimpleName(), e instanceof EJBAccessException);
}
return null;
});
}
/**
* Test objective:
* Check if default, @RolesAllowed, @PermitAll, @DenyAll and @RolesAllowed with multiple roles
* works on method level with user1 logged in as described in EJB 3.1 spec.
* user1 has "Users,Role1" roles.
* The target session bean is given as parameter.
* Expected results:
* Test has to finish without any exception or error.
* <p/>
*
* @throws Exception
*/
public void testSingleMethodAnnotationsUser1Template(final String MODULE, final Logger log, final Class SB_CLASS) throws Exception {
final Context ctx = Util.createNamingContext();
final AuthenticationContext authenticationContext = setupAuthenticationContext("user1", "password1");
authenticationContext.runCallable(() -> {
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).defaultAccess("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (EJBAccessException e) {
Assert.fail("EJBAccessException not expected");
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).roleBasedAccessOne("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (EJBAccessException e) {
Assert.fail("EJBAccessException not expected");
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).roleBasedAccessMore("alohomora");
Assert.fail("Method cannot be successfully called with logged in principal.");
} catch (Exception e) {
// expected
Assert.assertTrue("Thrown exception must be EJBAccessException, but was different", e instanceof EJBAccessException);
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).permitAll("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (Exception e) {
Assert.fail("@PermitAll annotation must allow all users and no users to call the method - principal.");
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).denyAll("alohomora");
Assert.fail("@DenyAll annotation must allow all users and no users to call the method");
} catch (Exception e) {
// expected
Assert.assertTrue("Thrown exception must be EJBAccessException, but was different", e instanceof EJBAccessException);
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).starRoleAllowed("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (Exception e) {
Assert.fail(
"@RolesAllowed(\"**\") annotation must allow all authenticated users to the method.");
}
return null;
});
}
/**
* Test objective:
* Check if default, @RolesAllowed, @PermitAll, @DenyAll and @RolesAllowed with multiple roles
* works on method level with user1 logged in as described in EJB 3.1 spec.
* user2 has "Users,Role2" roles.
* The target session bean is given as parameter.
* Expected results:
* Test has to finish without any exception or error.
* <p/>
*
* @throws Exception
*/
public void testSingleMethodAnnotationsUser2Template(final String MODULE, final Logger log, final Class SB_CLASS) throws Exception {
final Context ctx = Util.createNamingContext();
final AuthenticationContext authenticationContext = setupAuthenticationContext("user2", "password2");
authenticationContext.runCallable(() -> {
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).defaultAccess("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (EJBAccessException e) {
Assert.fail("EJBAccessException not expected");
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).roleBasedAccessOne("alohomora");
Assert.fail("Method cannot be successfully called with logged in user2");
} catch (Exception e) {
// expected
Assert.assertTrue("Thrown exception must be EJBAccessException, but was different", e instanceof EJBAccessException);
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).roleBasedAccessMore("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (EJBAccessException e) {
Assert.fail("EJBAccessException not expected");
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).permitAll("alohomora");
Assert.assertEquals(echoValue, "alohomora");
} catch (Exception e) {
Assert.fail("@PermitAll annotation must allow all users and no users to call the method - principal.");
}
try {
String echoValue = getBean(MODULE, log, SB_CLASS, ctx).denyAll("alohomora");
Assert.fail("@DenyAll annotation must allow all users and no users to call the method");
} catch (Exception e) {
// expected
Assert.assertTrue("Thrown exception must be EJBAccessException, but was different", e instanceof EJBAccessException);
}
return null;
});
}
protected AuthenticationContext setupAuthenticationContext(String username, String password) {
OptionMap.Builder builder = OptionMap.builder().set(Options.SASL_POLICY_NOANONYMOUS, true);
builder.set(Options.SASL_POLICY_NOPLAINTEXT, false);
if (password != null) {
builder.set(Options.SASL_DISALLOWED_MECHANISMS, Sequence.of("JBOSS-LOCAL-USER"));
} else {
builder.set(Options.SASL_MECHANISMS, Sequence.of("JBOSS-LOCAL-USER"));
}
final AuthenticationContext authenticationContext = AuthenticationContext.empty()
.with(
MatchRule.ALL,
AuthenticationConfiguration.empty()
.useName(username == null ? "$local" : username)
.usePassword(password)
.useRealm(null)
.setSaslMechanismSelector(SaslMechanismSelector.fromString(password != null ? "DIGEST-MD5" : "JBOSS-LOCAL-USER"))
.useMechanismProperties(getSaslProperties(builder.getMap()))
.useProvidersFromClassLoader(AnnSBTest.class.getClassLoader()));
return authenticationContext;
}
private Map<String, String> getSaslProperties(final OptionMap connectionCreationOptions) {
Map<String, String> saslProperties = null;
Sequence<Property> value = connectionCreationOptions.get(Options.SASL_PROPERTIES);
if (value != null) {
saslProperties = new HashMap<>(value.size());
for (Property property : value) {
saslProperties.put(property.getKey(), (String) property.getValue());
}
}
return saslProperties;
}
protected static boolean isBeanClassStatefull(Class bean) {
if (bean.getName().contains("toSLSB")) {
return false;
} else if (bean.getName().contains("toSFSB")) {
return true;
} else if (bean.getName().contains("SFSB")) {
return true;
} else if (bean.getName().contains("SLSB")) {
return false;
} else {
throw new AssertionError("Session bean class has a wrong name!: " + bean.getCanonicalName());
}
}
}
| 14,407 | 44.594937 | 207 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/AuthenticationTestCase.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;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.hamcrest.CoreMatchers.containsString;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.SocketPermission;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.Principal;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import jakarta.ejb.EJB;
import javax.security.auth.AuthPermission;
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.ejb.security.authentication.EntryBean;
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.TestSuiteEnvironment;
import org.jboss.as.test.shared.integration.ejb.security.Util;
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.WebArchive;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.wildfly.security.auth.server.SecurityDomain;
import org.wildfly.security.permission.ElytronPermission;
/**
* Test case to hold the authentication scenarios, these range from calling a servlet which calls a bean to calling a bean which
* calls another bean to calling a bean which re-authenticated before calling another bean.
*
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
@RunWith(Arquillian.class)
@ServerSetup({EjbSecurityDomainSetup.class})
@Category(CommonCriteria.class)
public class AuthenticationTestCase {
private static final Logger log = Logger.getLogger(AuthenticationTestCase.class.getName());
/*
* Authentication Scenarios
*
* Client -> Bean
* Client -> Bean -> Bean
* Client -> Bean (Re-auth) -> Bean
* Client -> Servlet -> Bean
* Client -> Servlet (Re-auth) -> Bean
* Client -> Servlet -> Bean -> Bean
* Client -> Servlet -> Bean (Re Auth) -> Bean
*/
@ArquillianResource
private URL url;
@Deployment
public static Archive<?> deployment() {
final String SERVER_HOST_PORT = TestSuiteEnvironment.getHttpAddress() + ":" + TestSuiteEnvironment.getHttpPort();
final Package currentPackage = AuthenticationTestCase.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())
.addClass(WhoAmI.class).addClass(Util.class).addClass(Entry.class)
.addClasses(WhoAmIServlet.class, AuthenticationTestCase.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(createPermissionsXmlAsset(
// login module needs to modify principal to commit logging in
new AuthPermission("modifyPrincipals"),
// AuthenticationTestCase#execute calls ExecutorService#shutdownNow
new RuntimePermission("modifyThread"),
// AuthenticationTestCase#execute calls sun.net.www.http.HttpClient#openServer under the hood
new SocketPermission(SERVER_HOST_PORT, "connect,resolve"),
new ElytronPermission("getSecurityDomain"),
new ElytronPermission("authenticate")
),
"permissions.xml");
war.addPackage(CommonCriteria.class.getPackage());
return war;
}
@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.Entry")
private Entry entryBean;
@Test
public void testAuthentication() throws Exception {
final Callable<Void> callable = () -> {
String response = entryBean.whoAmI();
assertEquals("user1", response);
return null;
};
Util.switchIdentity("user1", "password1", callable);
}
@Test
public void testAuthentication_BadPwd() throws Exception {
Util.switchIdentity("user1", "wrong_password", () -> entryBean.whoAmI(), true);
}
@Test
public void testAuthentication_TwoBeans() throws Exception {
final Callable<Void> callable = () -> {
String[] response = entryBean.doubleWhoAmI();
assertEquals("user1", response[0]);
assertEquals("user1", response[1]);
return null;
};
Util.switchIdentity("user1", "password1", callable);
}
@Test
public void testAuthentication_TwoBeans_ReAuth() throws Exception {
final Callable<Void> callable = () -> {
String[] response = entryBean.doubleWhoAmI("user2", "password2");
assertEquals("user1", response[0]);
assertEquals("user2", response[1]);
return null;
};
Util.switchIdentity("user1", "password1", callable);
}
// TODO - Similar test with first bean @RunAs - does it make sense to also manually switch?
@Test
public void testAuthentication_TwoBeans_ReAuth_BadPwd() throws Exception {
Util.switchIdentity("user1", "password1", () -> entryBean.doubleWhoAmI("user2", "wrong_password"), true);
}
@Test
public void testAuthenticatedCall() throws Exception {
// TODO: this is not spec
final Callable<Void> callable = () -> {
try {
final Principal principal = whoAmIBean.getCallerPrincipal();
assertNotNull("EJB 3.1 FR 17.6.5 The container must never return a null from the getCallerPrincipal method.",
principal);
assertEquals("user1", principal.getName());
} catch (RuntimeException e) {
e.printStackTrace();
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() + ")");
}
return null;
};
Util.switchIdentitySCF("user1", "password1", callable);
}
@Test
public void testUnauthenticated() throws Exception {
try {
final Principal principal = whoAmIBean.getCallerPrincipal();
assertNotNull("EJB 3.1 FR 17.6.5 The container must never return a null from the getCallerPrincipal method.",
principal);
// TODO: where is 'anonymous' configured?
assertEquals("anonymous", principal.getName());
} catch (RuntimeException e) {
e.printStackTrace();
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() + ")");
}
}
@Test
public void testAuthentication_ViaServlet() throws Exception {
final String result = getWhoAmI("?method=whoAmI");
assertEquals("user1", result);
}
@Test
public void testAuthentication_ReAuth_ViaServlet() throws Exception {
final String result = getWhoAmI("?method=whoAmI&username=user2&password=password2");
assertEquals("user2", result);
}
@Test
public void testAuthentication_TwoBeans_ViaServlet() throws Exception {
final String result = getWhoAmI("?method=doubleWhoAmI");
assertEquals("user1,user1", result);
}
@Test
public void testAuthentication_TwoBeans_ReAuth_ViaServlet() throws Exception {
final String result = getWhoAmI("?method=doubleWhoAmI&username=user2&password=password2");
assertEquals("user1,user2", result);
}
@Test
public void testAuthentication_TwoBeans_ReAuth__BadPwd_ViaServlet() throws Exception {
try {
getWhoAmI("?method=doubleWhoAmI&username=user2&password=bad_password");
fail("Expected IOException");
} catch (IOException e) {
if (SecurityDomain.getCurrent() == null) {
assertThat(e.getMessage(), containsString("jakarta.ejb.EJBAccessException"));
} else {
assertThat(e.getMessage(), containsString("jakarta.ejb.EJBException: java.lang.SecurityException: ELY01151"));
}
}
}
/*
* isCallerInRole Scenarios
*/
@Test
public void testICIRSingle() throws Exception {
final Callable<Void> callable = () -> {
assertTrue(entryBean.doIHaveRole("Users"));
assertTrue(entryBean.doIHaveRole("Role1"));
assertFalse(entryBean.doIHaveRole("Role2"));
return null;
};
Util.switchIdentity("user1", "password1", callable);
}
@Test
public void testICIR_TwoBeans() throws Exception {
final Callable<Void> callable = () -> {
boolean[] response;
response = entryBean.doubleDoIHaveRole("Users");
assertTrue(response[0]);
assertTrue(response[1]);
response = entryBean.doubleDoIHaveRole("Role1");
assertTrue(response[0]);
assertTrue(response[1]);
response = entryBean.doubleDoIHaveRole("Role2");
assertFalse(response[0]);
assertFalse(response[1]);
return null;
};
Util.switchIdentity("user1", "password1", callable);
}
@Test
public void testICIR_TwoBeans_ReAuth() throws Exception {
final Callable<Void> callable = () -> {
boolean[] response;
response = entryBean.doubleDoIHaveRole("Users", "user2", "password2");
assertTrue(response[0]);
assertTrue(response[1]);
response = entryBean.doubleDoIHaveRole("Role1", "user2", "password2");
assertTrue(response[0]);
assertFalse(response[1]);
response = entryBean.doubleDoIHaveRole("Role2", "user2", "password2");
assertFalse(response[0]);
assertTrue(response[1]);
return null;
};
Util.switchIdentity("user1", "password1", callable);
}
private static String read(final InputStream in) throws IOException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
return out.toString();
}
private static String processResponse(HttpURLConnection conn) throws IOException {
int responseCode = conn.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
final InputStream err = conn.getErrorStream();
try {
String response = err != null ? read(err) : null;
throw new IOException(String.format("HTTP Status %d Response: %s", responseCode, response));
} finally {
if (err != null) {
err.close();
}
}
}
final InputStream in = conn.getInputStream();
try {
return read(in);
} finally {
in.close();
}
}
private String getWhoAmI(String queryString) throws Exception {
return get(url + "whoAmI" + queryString, "user1", "password1", 10, SECONDS);
}
public static String get(final String spec, final String username, final String password, final long timeout, final TimeUnit unit) throws IOException, TimeoutException {
final URL url = new URL(spec);
Callable<String> task = new Callable<String>() {
@Override
public String call() throws IOException {
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (username != null) {
final String userpassword = username + ":" + password;
final String basicAuthorization = java.util.Base64.getEncoder().encodeToString(userpassword.getBytes(StandardCharsets.UTF_8));
conn.setRequestProperty("Authorization", "Basic " + basicAuthorization);
}
conn.setDoInput(true);
return processResponse(conn);
}
};
return execute(task, timeout, unit);
}
private static String execute(final Callable<String> task, final long timeout, final TimeUnit unit) throws TimeoutException, IOException {
final ExecutorService executor = Executors.newSingleThreadExecutor();
final Future<String> result = executor.submit(task);
try {
return result.get(timeout, unit);
} catch (TimeoutException e) {
result.cancel(true);
throw e;
} catch (InterruptedException e) {
// should not happen
throw new RuntimeException(e);
} catch (ExecutionException e) {
// by virtue of the Callable redefinition above I can cast
throw new IOException(e);
} finally {
executor.shutdownNow();
try {
executor.awaitTermination(timeout, unit);
} catch (InterruptedException e) {
// ignore
}
}
}
@Test
public void testICIR_ViaServlet() throws Exception {
String result = getWhoAmI("?method=doIHaveRole&role=Users");
assertEquals("true", result);
result = getWhoAmI("?method=doIHaveRole&role=Role1");
assertEquals("true", result);
result = getWhoAmI("?method=doIHaveRole&role=Role2");
assertEquals("false", result);
}
@Test
public void testICIR_ReAuth_ViaServlet() throws Exception {
String result = getWhoAmI("?method=doIHaveRole&role=Users&username=user2&password=password2");
assertEquals("true", result);
result = getWhoAmI("?method=doIHaveRole&role=Role1&username=user2&password=password2");
assertEquals("false", result);
result = getWhoAmI("?method=doIHaveRole&role=Role2&username=user2&password=password2");
assertEquals("true", result);
}
@Test
public void testICIR_TwoBeans_ViaServlet() throws Exception {
String result = getWhoAmI("?method=doubleDoIHaveRole&role=Users");
assertEquals("true,true", result);
result = getWhoAmI("?method=doubleDoIHaveRole&role=Role1");
assertEquals("true,true", result);
result = getWhoAmI("?method=doubleDoIHaveRole&role=Role2");
assertEquals("false,false", result);
}
@Test
public void testICIR_TwoBeans_ReAuth_ViaServlet() throws Exception {
String result = getWhoAmI("?method=doubleDoIHaveRole&role=Users&username=user2&password=password2");
assertEquals("true,true", result);
result = getWhoAmI("?method=doubleDoIHaveRole&role=Role1&username=user2&password=password2");
assertEquals("true,false", result);
result = getWhoAmI("?method=doubleDoIHaveRole&role=Role2&username=user2&password=password2");
assertEquals("false,true", result);
}
/*
* 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.
*/
// 17.2.5 - Programatic Access to Caller's Security Context
// Include tests for methods not implemented to pick up if later they are implemented.
// 17.2.5.1 - Use of getCallerPrincipal
// 17.6.5 - Security Methods on EJBContext
// 17.2.5.2 - Use of isCallerInRole
// 17.2.5.3 - Declaration of Security Roles Referenced from the Bean's Code
// 17.3.1 - Security Roles
// 17.3.2.1 - Specification of Method Permissions with Metadata Annotation
// 17.3.2.2 - Specification of Method Permissions in the Deployment Descriptor
// 17.3.2.3 - Unspecified Method Permission
// 17.3.3 - Linking Security Role References to Security Roles
// 17.3.4 - Specification on Security Identities in the Deployment Descriptor
// (Include permutations for overrides esp where deployment descriptor removes access)
// 17.3.4.1 - Run-as
// 17.5 EJB Client Responsibilities
// A transactional client can not change principal association within transaction.
// A session bean client must not change the principal association for the duration of the communication.
// If transactional requests within a single transaction arrive from multiple clients all must be associated
// with the same security context.
// 17.6.3 - Security Mechanisms
// 17.6.4 - Passing Principals on EJB Calls
// 17.6.6 - Secure Access to Resource Managers
// 17.6.7 - Principal Mapping
// 17.6.9 - Runtime Security Enforcement
// 17.6.10 - Audit Trail
}
| 19,873 | 42.017316 | 173 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/HelloRemote.java
|
package org.jboss.as.test.integration.ejb.security;
import java.rmi.RemoteException;
import jakarta.ejb.EJBObject;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public interface HelloRemote extends EJBObject {
String sayHello(String name) throws RemoteException;
}
| 298 | 23.916667 | 64 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/HelloBean.java
|
package org.jboss.as.test.integration.ejb.security;
import java.rmi.RemoteException;
import jakarta.ejb.EJBException;
import jakarta.ejb.RemoteHome;
import jakarta.ejb.SessionBean;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@Stateless
@SecurityDomain("other")
@RemoteHome(HelloHome.class)
public class HelloBean implements SessionBean {
private SessionContext ctx;
@Override
public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException {
this.ctx = ctx;
}
@Override
public void ejbRemove() throws EJBException, RemoteException {
}
@Override
public void ejbActivate() throws EJBException, RemoteException {
}
@Override
public void ejbPassivate() throws EJBException, RemoteException {
}
public String sayHello(final String name) {
return "Hello " + name;
}
}
| 1,012 | 23.119048 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/SaslLegacyMechanismConfigurationTestCase.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;
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.container.ManagementClient;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.test.integration.ejb.security.authorization.SaslLegacyMechanismBean;
import org.jboss.as.test.integration.ejb.security.authorization.SaslLegacyMechanismBeanRemote;
import org.jboss.as.test.integration.management.base.AbstractCliTestBase;
import org.jboss.as.test.integration.management.util.CLIOpResult;
import org.jboss.as.test.shared.ServerReload;
import org.jboss.as.test.shared.SnapshotRestoreSetupTask;
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.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import jakarta.ejb.EJBException;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
/**
* Security is configured via legacy security options in remoting subsystem. Test asserts, that anonymous authentication/plain authentication is used.
*
* @author Jiri Ondrusek ([email protected])
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup(SaslLegacyMechanismConfigurationTestCase.LegacyMechanismConfigurationSetupTask.class)
public class SaslLegacyMechanismConfigurationTestCase extends AbstractCliTestBase {
private static final Logger log = Logger.getLogger(SaslLegacyMechanismConfigurationTestCase.class);
private static final String MODULE = "SaslLegacyMechanismConfigurationTestCase";
public static final String ANONYMOUS_PLAIN_SASL_MECHANISMS = "PLAIN,ANONYMOUS";
public static final String ANONYMOUS_PLAIN_SASL_MECHANISMS_REVERSED = "ANONYMOUS,PLAIN";
public static final String SASL_DISALLOWED_MECHANISMS = "DIGEST,DIGEST-MD5,JBOSS-LOCAL-USER";
@ContainerResource
private ManagementClient managementClient;
//if this is true, tests are ignored as legacy security is not allowed
private static boolean ignoreTest = false;
@Deployment(name = MODULE + ".jar", order = 1, testable = false)
public static Archive<JavaArchive> testAppDeployment() {
if(!ignoreTest) {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE + ".jar")
.addClass(SaslLegacyMechanismBean.class)
.addClass(SaslLegacyMechanismBeanRemote.class);
return jar;
} else {
return null;
}
}
@BeforeClass
public static void before() throws Exception {
initCLI();
}
@Before
public void beforeMethod() {
org.junit.Assume.assumeTrue(!ignoreTest);
}
@AfterClass
public static void after() throws Exception {
closeCLI();
}
@Test
public void testAnonymous() throws Exception {
String echoValue = getBean(log, null, null, true).getPrincipal();
Assert.assertEquals("anonymous", echoValue);
}
@Test
public void testAuthorized() throws Exception {
String echoValue = getBean(log, "user1", "password1", true).getPrincipal();
Assert.assertEquals("user1", echoValue);
}
@Test
public void testAuthorizedReversed() throws Exception {
tryReloadWithSaslMechanism(ANONYMOUS_PLAIN_SASL_MECHANISMS_REVERSED);
try {
String echoValue = getBean(log, "user1", "password1", true).getPrincipal();
Assert.assertEquals("user1", echoValue);
} finally {
tryReloadWithSaslMechanism(ANONYMOUS_PLAIN_SASL_MECHANISMS);
}
}
@Test
public void testFakeParameter() throws Exception {
Exception ex = null;
try {
tryReloadWithSaslMechanism("FAKE_MECHANISM,PLAIN,ANONYMOUS");
getBean(log, null, null, true).getPrincipal();
} catch (EJBException e) {
ex = e;
} finally {
//in case that one of previous statements fails and changes server
tryReloadWithSaslMechanism(ANONYMOUS_PLAIN_SASL_MECHANISMS);
}
Assert.assertNotNull("Call to ejb should fail, because http-connector is not valid", ex);
}
@Test
public void testDisallowedParameter() throws Exception {
Exception ex = null;
try {
tryReloadWithSaslMechanism("EXTERNAL,PLAIN,ANONYMOUS");
getBean(log, null, null, true).getPrincipal();
} catch (EJBException e) {
ex = e;
} finally {
//in case that one of previous statements fails and changes server
tryReloadWithSaslMechanism(ANONYMOUS_PLAIN_SASL_MECHANISMS);
}
Assert.assertNotNull("Call to ejb should fail, because http-connector is not valid", ex);
}
@Test
public void testDigest() throws Exception {
try {
tryReloadWithSaslMechanism("DIGEST-MD5");
String echoValue = getBean(log, "user1", "password1", false).getPrincipal();
Assert.assertEquals("user1", echoValue);
} finally {
tryReloadWithSaslMechanism(ANONYMOUS_PLAIN_SASL_MECHANISMS);
}
}
private void tryReloadWithSaslMechanism(String mechanismName) throws Exception {
cli.sendLine("/subsystem=remoting/http-connector=http-remoting-connector/property=SASL_MECHANISMS:write-attribute(name=\"value\", value=\""+mechanismName+"\")");
CLIOpResult opResult = cli.readAllAsOpResult();
Assert.assertTrue(opResult.isIsOutcomeSuccess());
cli.sendLine("reload");
cli.readAllAsOpResult();
}
// ejb client code
private SaslLegacyMechanismBeanRemote getBean(final Logger log, String username, String password, boolean addDisallowed) throws Exception {
log.trace("**** creating InitialContext");
InitialContext ctx = new InitialContext(setupEJBClientProperties(username, password, addDisallowed));
try {
log.trace("**** looking up StatelessBean through JNDI");
SaslLegacyMechanismBeanRemote bean = (SaslLegacyMechanismBeanRemote)
ctx.lookup("ejb:/" + MODULE + "/" + SaslLegacyMechanismBean.class.getSimpleName() + "!" + SaslLegacyMechanismBeanRemote.class.getCanonicalName());
return bean;
} finally {
ctx.close();
}
}
private Properties setupEJBClientProperties(String username, String password, boolean addDisallowed) throws IOException {
log.trace("*** reading EJBClientContextSelector properties");
// setup the properties
final String clientPropertiesFile = "org/jboss/as/test/integration/ejb/security/jboss-ejb-client.properties";
final InputStream inputStream = SaslLegacyMechanismConfigurationTestCase.class.getClassLoader().getResourceAsStream(clientPropertiesFile);
if (inputStream == null) {
throw new IllegalStateException("Could not find " + clientPropertiesFile + " in classpath");
}
final Properties properties = new Properties();
properties.load(inputStream);
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
if(username != null && password != null) {
properties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "true");
properties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
} else {
properties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
properties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
}
if (addDisallowed) {
properties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", SASL_DISALLOWED_MECHANISMS);
}
if(username != null && password != null) {
properties.put(Context.SECURITY_PRINCIPAL, username);
properties.put(Context.SECURITY_CREDENTIALS, password);
}
return properties;
}
/**
* Setup task which adds legacy remoting properties and restores it afterwards.
*/
public static class LegacyMechanismConfigurationSetupTask extends SnapshotRestoreSetupTask {
private ModelNode localAuthentication, propsAuthentication;
private String saslAuthenticationFactory;
private static final PathAddress AUTHENTICATION_PROPS = PathAddress.pathAddress(ModelDescriptionConstants.CORE_SERVICE, "management")
.append("security-realm", "ApplicationRealm").append("authentication", "properties");
private static final PathAddress LOCAL_AUTHENTICATION = PathAddress.pathAddress(ModelDescriptionConstants.CORE_SERVICE, "management")
.append("security-realm", "ApplicationRealm").append("authentication", "local");
private static final PathAddress HTTP_REMOTING_CONNECTOR = PathAddress.pathAddress(ModelDescriptionConstants.SUBSYSTEM, "remoting")
.append("http-connector", "http-remoting-connector");
private static final PathAddress SASL_MECHANISMS = PathAddress.pathAddress(ModelDescriptionConstants.SUBSYSTEM, "remoting")
.append("http-connector", "http-remoting-connector").append("property", "SASL_MECHANISMS");
private static final PathAddress SASL_POLICY_NOANONYMOUS = PathAddress.pathAddress(ModelDescriptionConstants.SUBSYSTEM, "remoting")
.append("http-connector", "http-remoting-connector").append("property", "SASL_POLICY_NOANONYMOUS");
@Override
protected void doSetup(ManagementClient managementClient, String containerId) throws Exception {
ModelControllerClient mcc = managementClient.getControllerClient();
ModelNode authentication;
String securityRealm =null;
authentication = execute(Operations.createReadAttributeOperation(HTTP_REMOTING_CONNECTOR.append().toModelNode(), "security-realm"), mcc);
if(SUCCESS.equals(authentication.get(OUTCOME).asString())) {
securityRealm = authentication.get(RESULT).asString();
}
if("undefined".equals(securityRealm)) {
securityRealm = null;
}
ignoreTest = securityRealm == null;
//if security-realm on htt-remoting-connector is emoty,it means that legacy security is not allowed and this test should be ignored
org.junit.Assume.assumeTrue(securityRealm != null);
authentication = execute(Operations.createReadResourceOperation(LOCAL_AUTHENTICATION.append().toModelNode()), mcc);
if(SUCCESS.equals(authentication.get(OUTCOME).asString())) {
localAuthentication = authentication.get(RESULT);
}
authentication = execute(Operations.createReadResourceOperation(AUTHENTICATION_PROPS.append().toModelNode()), mcc);
if(SUCCESS.equals(authentication.get(OUTCOME).asString())) {
propsAuthentication = authentication.get(RESULT);
}
authentication = execute(Operations.createReadAttributeOperation(HTTP_REMOTING_CONNECTOR.append().toModelNode(), "sasl-authentication-factory"), mcc);
if(SUCCESS.equals(authentication.get(OUTCOME).asString())) {
saslAuthenticationFactory = authentication.get(RESULT).asString();
}
if("undefined".equals(saslAuthenticationFactory)) {
saslAuthenticationFactory = null;
}
ModelNode compositeOperation = Operations.createCompositeOperation();
if(localAuthentication != null) {
compositeOperation.get(ModelDescriptionConstants.STEPS).add(Operations.createRemoveOperation(LOCAL_AUTHENTICATION.toModelNode()));
}
compositeOperation.get(ModelDescriptionConstants.STEPS).add(addSaslMechanisms());
compositeOperation.get(ModelDescriptionConstants.STEPS).add(addPolicyNoanonymous());
String users = new File(SaslLegacyMechanismConfigurationTestCase.class.getResource("users.properties").getFile()).getAbsolutePath();
compositeOperation.get(ModelDescriptionConstants.STEPS).add(Operations.createWriteAttributeOperation(AUTHENTICATION_PROPS.toModelNode(),"path", users));
compositeOperation.get(ModelDescriptionConstants.STEPS).add(Operations.createWriteAttributeOperation(AUTHENTICATION_PROPS.toModelNode(),"plain-text", "true"));
compositeOperation.get(ModelDescriptionConstants.STEPS).add(Operations.createUndefineAttributeOperation(AUTHENTICATION_PROPS.toModelNode(),"relative-to"));
if(saslAuthenticationFactory != null) {
compositeOperation.get(ModelDescriptionConstants.STEPS).add(Operations.createUndefineAttributeOperation(HTTP_REMOTING_CONNECTOR.append().toModelNode(), "sasl-authentication-factory"));
}
ModelNode response = execute(compositeOperation, mcc);
Assert.assertEquals(response.toString(), SUCCESS, response.get(OUTCOME).asString());
ServerReload.reloadIfRequired(managementClient);
}
private ModelNode addSaslMechanisms() throws IOException {
ModelNode addRaOperation = Operations.createAddOperation(SASL_MECHANISMS.toModelNode());
addRaOperation.get("name").set("value");
addRaOperation.get("value").set(ANONYMOUS_PLAIN_SASL_MECHANISMS);
return addRaOperation;
}
private ModelNode addPolicyNoanonymous() throws IOException {
ModelNode addRaOperation = Operations.createAddOperation(SASL_POLICY_NOANONYMOUS.toModelNode());
addRaOperation.get("name").set("value");
addRaOperation.get("value").set("false");
return addRaOperation;
}
private ModelNode execute(ModelNode operation, ModelControllerClient client) throws IOException {
return client.execute(operation);
}
}
}
| 15,586 | 44.311047 | 196 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/HelloHome.java
|
package org.jboss.as.test.integration.ejb.security;
import java.rmi.RemoteException;
import jakarta.ejb.CreateException;
import jakarta.ejb.EJBHome;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public interface HelloHome extends EJBHome {
HelloRemote create() throws CreateException, RemoteException;
}
| 337 | 25 | 65 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/FullyRestrictedBean.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;
import jakarta.annotation.security.DenyAll;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Singleton;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* User: jpai
*/
@Singleton
@DenyAll
@LocalBean
@SecurityDomain("other")
public class FullyRestrictedBean extends AnnotatedSLSB {
@Override
public void overriddenMethod() {
// the @DenyAll on the class level of this bean should have been applied
// and the invocation to this method shouldn't have been allowed
throw new RuntimeException("Access to this method shouldn't have been allowed!");
}
}
| 1,671 | 34.574468 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/InjectionAnnSLSBtoSFSBTestCase.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;
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.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.authorization.InjectionSLSBtoSFSB;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
/**
* Checks whether basic EJB authorization works from EJB client to injected stateless remote EJB.
*
* @author <a href="mailto:[email protected]">Jan Lanik</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
@Category(CommonCriteria.class)
public class InjectionAnnSLSBtoSFSBTestCase extends AnnSBTest {
private static final Logger log = Logger.getLogger(testClass());
private static final String MODULE = "injectionAnnOnlySLSBtoSFSB";
private static Class testClass(){
return InjectionAnnSLSBtoSFSBTestCase.class;
}
private static Class beanClass(){
return InjectionSLSBtoSFSB.class;
}
@Deployment(name = MODULE + ".jar", order = 1, testable = false)
public static Archive<JavaArchive> deployment() {
return testAppDeployment(Logger.getLogger(testClass()), MODULE, beanClass());
}
@Test
public void testSingleMethodAnnotationsNoUser() throws Exception {
testSingleMethodAnnotationsNoUserTemplate(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser1() throws Exception {
testSingleMethodAnnotationsUser1Template(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser2() throws Exception {
testSingleMethodAnnotationsUser2Template(MODULE, log, beanClass());
}
}
| 2,925 | 36.512821 | 97 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/AnnotatedSLSB.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;
import jakarta.annotation.security.DeclareRoles;
import jakarta.annotation.security.DenyAll;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.Local;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* User: jpai
*/
@Stateless
@DeclareRoles(value = {"Role1", "Role2", "Role3"})
@Local ({Restriction.class, FullAccess.class})
@LocalBean
@SecurityDomain("other")
public class AnnotatedSLSB extends Base implements Restriction, FullAccess {
@Override
@DenyAll
public void restrictedMethod() {
throw new RuntimeException("This method was supposed to be restricted to all!");
}
@Override
public void overriddenMethod() {
}
@RolesAllowed({}) // this should act like a @DenyAll
public void methodWithEmptyRolesAllowedAnnotation() {
throw new RuntimeException("This method was supposed to be restricted to all!");
}
}
| 2,034 | 31.822581 | 88 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/DDBasedSLSB.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;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* User: jpai
*/
@SecurityDomain("other")
public class DDBasedSLSB implements FullAccess {
public void accessDenied() {
}
public void onlyTestRoleCanAccess() {
}
@Override
public void doAnything() {
}
}
| 1,369 | 28.782609 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/Base.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;
import jakarta.annotation.security.DenyAll;
/**
* User: jpai
*/
public class Base implements FullAccess {
@Override
public void doAnything() {
}
@DenyAll
public void restrictedBaseClassMethod() {
}
@DenyAll
public void overriddenMethod() {
}
}
| 1,366 | 28.085106 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/InjectionAnnSLSBtoSLSBTestCase.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;
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.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.authorization.InjectionSLSBtoSLSB;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
/**
* This test case check whether basic EJB authorization works from EJB client to injected stateless remote EJB.
*
* @author <a href="mailto:[email protected]">Jan Lanik</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
@Category(CommonCriteria.class)
public class InjectionAnnSLSBtoSLSBTestCase extends AnnSBTest {
private static final Logger log = Logger.getLogger(testClass());
private static final String MODULE = "injectionAnnOnlySLSBtoSLSB";
private static Class testClass(){
return InjectionAnnSLSBtoSLSBTestCase.class;
}
private static Class beanClass(){
return InjectionSLSBtoSLSB.class;
}
@Deployment(name = MODULE + ".jar", order = 1, testable = false)
public static Archive<JavaArchive> deployment() {
return testAppDeployment(Logger.getLogger(testClass()), MODULE, beanClass());
}
@Test
public void testSingleMethodAnnotationsNoUser() throws Exception {
testSingleMethodAnnotationsNoUserTemplate(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser1() throws Exception {
testSingleMethodAnnotationsUser1Template(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser2() throws Exception {
testSingleMethodAnnotationsUser2Template(MODULE, log, beanClass());
}
}
| 2,940 | 36.227848 | 111 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/AnnotationAuthorizationTestCase.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;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.authorization.AttendanceRegistry;
import org.jboss.as.test.integration.ejb.security.authorization.AttendanceRegistrySLSB;
import org.jboss.as.test.integration.ejb.security.authorization.DenyAllOverrideBean;
import org.jboss.as.test.integration.ejb.security.authorization.PermitAllOverrideBean;
import org.jboss.as.test.integration.ejb.security.authorization.RolesAllowedOverrideBean;
import org.jboss.as.test.integration.ejb.security.authorization.RolesAllowedOverrideBeanBase;
import org.jboss.as.test.integration.ejb.security.authorization.TimeProvider;
import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup;
import org.jboss.as.test.shared.integration.ejb.security.Util;
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.WebArchive;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import jakarta.ejb.EJB;
import jakarta.ejb.EJBAccessException;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.concurrent.Callable;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* Test case to test the general authorization requirements for annotated beans, more specific requirements such as RunAs
* handling will be in their own test case.
* <p/>
* EJB 3.1 Section 17.3.2.1
*
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
@RunWith(Arquillian.class)
@ServerSetup({EjbSecurityDomainSetup.class})
@Category(CommonCriteria.class)
public class AnnotationAuthorizationTestCase {
private static final Logger log = Logger.getLogger(AnnotationAuthorizationTestCase.class.getName());
@Deployment
public static Archive<?> runAsDeployment() {
final Package currentPackage = AnnotationAuthorizationTestCase.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")
// Explicitly listing these classes to prevent EJBs that are used by other tests and that use different security domains from being added here
.addClasses(RolesAllowedOverrideBean.class, RolesAllowedOverrideBeanBase.class, PermitAllOverrideBean.class, DenyAllOverrideBean.class).addClass(Util.class)
.addClasses(AttendanceRegistry.class, TimeProvider.class, AttendanceRegistrySLSB.class)
.addClasses(AnnotationAuthorizationTestCase.class)
.addClasses(AbstractSecurityDomainSetup.class, EjbSecurityDomainSetup.class)
.addAsWebInfResource(currentPackage, "jboss-web.xml", "jboss-web.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;
}
@EJB(mappedName = "java:global/ejb3security/RolesAllowedOverrideBean")
private RolesAllowedOverrideBean rolesAllowedOverridenBean;
@EJB(mappedName = "java:global/ejb3security/AttendanceRegistrySLSB!org.jboss.as.test.integration.ejb.security.authorization.AttendanceRegistry")
private AttendanceRegistry attendanceRegistryBean;
/*
* Test overrides within a bean annotated @RolesAllowed at bean level.
*/
@Test
public void testRolesAllowedOverriden_NoUser() throws Exception {
try {
rolesAllowedOverridenBean.defaultEcho("1");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
try {
rolesAllowedOverridenBean.denyAllEcho("2");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
String response = rolesAllowedOverridenBean.permitAllEcho("3");
assertEquals("3", response);
try {
rolesAllowedOverridenBean.role2Echo("4");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
}
@Test
public void testRolesAllowedOverriden_User1() throws Exception {
final Callable<Void> callable = () -> {
String response = rolesAllowedOverridenBean.defaultEcho("1");
assertEquals("1", response);
try {
rolesAllowedOverridenBean.denyAllEcho("2");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
response = rolesAllowedOverridenBean.permitAllEcho("3");
assertEquals("3", response);
try {
rolesAllowedOverridenBean.role2Echo("4");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
return null;
};
Util.switchIdentity("user1", "password1", callable);
}
@Test
public void testRolesAllowedOverridenInBaseClass_Admin() throws Exception {
final Callable<Void> callable = () -> {
try {
rolesAllowedOverridenBean.aMethod("aMethod");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
String response = rolesAllowedOverridenBean.bMethod("bMethod");
assertEquals("bMethod", response);
return null;
};
Util.switchIdentity("admin", "admin", callable);
}
@Test
public void testRolesAllowedOverridenInBaseClass_HR() throws Exception {
final Callable<Void> callable = () -> {
String response = rolesAllowedOverridenBean.aMethod("aMethod");
assertEquals("aMethod", response);
try {
rolesAllowedOverridenBean.bMethod("bMethod");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
return null;
};
Util.switchIdentity("hr", "hr", callable);
}
@Test
public void testRolesAllowedOverriden_User2() throws Exception {
final Callable<Void> callable = () -> {
try {
rolesAllowedOverridenBean.defaultEcho("1");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
try {
rolesAllowedOverridenBean.denyAllEcho("2");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
String response = rolesAllowedOverridenBean.permitAllEcho("3");
assertEquals("3", response);
response = rolesAllowedOverridenBean.role2Echo("4");
assertEquals("4", response);
return null;
};
Util.switchIdentity("user2", "password2", callable);
}
/*
* Test overrides of bean annotated at bean level with @PermitAll
*/
@EJB(mappedName = "java:global/ejb3security/PermitAllOverrideBean")
private PermitAllOverrideBean permitAllOverrideBean;
@Test
public void testPermitAllOverride_NoUser() throws Exception {
String response = permitAllOverrideBean.defaultEcho("1");
assertEquals("1", response);
try {
permitAllOverrideBean.denyAllEcho("2");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
try {
permitAllOverrideBean.role1Echo("3");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
}
@Test
public void testPermitAllOverride_User1() throws Exception {
final Callable<Void> callable = () -> {
String response = permitAllOverrideBean.defaultEcho("1");
assertEquals("1", response);
try {
permitAllOverrideBean.denyAllEcho("2");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
response = permitAllOverrideBean.role1Echo("3");
assertEquals("3", response);
return null;
};
Util.switchIdentity("user1", "password1", callable);
}
/*
* Test overrides of ben annotated at bean level with @DenyAll
*/
@EJB(mappedName = "java:global/ejb3security/DenyAllOverrideBean")
private DenyAllOverrideBean denyAllOverrideBean;
@Test
public void testDenyAllOverride_NoUser() throws Exception {
try {
denyAllOverrideBean.defaultEcho("1");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
String response = denyAllOverrideBean.permitAllEcho("2");
assertEquals("2", response);
try {
denyAllOverrideBean.role1Echo("3");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
}
@Test
public void testDenyAllOverride_User1() throws Exception {
final Callable<Void> callable = () -> {
try {
denyAllOverrideBean.defaultEcho("1");
fail("Expected EJBAccessException not thrown");
} catch (EJBAccessException ignored) {
}
String response = denyAllOverrideBean.permitAllEcho("2");
assertEquals("2", response);
response = denyAllOverrideBean.role1Echo("3");
assertEquals("3", response);
return null;
};
Util.switchIdentity("user1", "password1", callable);
}
/**
* Tests that a method which accepts an array as a parameter and is marked with @PermitAll is allowed to be invoked by clients.
*
* @throws Exception
*/
@Test
public void testPermitAllMethodWithArrayParams() throws Exception {
final Callable<Void> callable = () -> {
final String[] messages = new String[] {"foo", "bar"};
final String[] echoes = denyAllOverrideBean.permitAllEchoWithArrayParams(messages);
assertArrayEquals("Unexpected echoes returned by bean method", messages, echoes);
return null;
};
Util.switchIdentity("user1", "password1", callable);
}
/**
* Tests that, when a EJB has overloaded methods with the same number of arguments but with different parameter types
* and when there's a {@link Method#isBridge() bridge method} involved (due to Java generics), then the security annotations
* on such methods are properly processed and the right method is assigned for the correct set of allowed access roles.
*
* @throws Exception
* @see <a href="https://issues.jboss.org/browse/WFLY-8548">WFLY-8548</a> for more details
*/
@Test
public void testOverloadedMethodsWithDifferentAuthorization() throws Exception {
final String user = "Jane Doe";
final Date date = new Date();
// expected to pass through fine (since the invocation is expected to happen on a @PermitAll method)
final String entryForPermitAll = attendanceRegistryBean.recordEntry(user, new AttendanceRegistrySLSB.DefaultTimeProvider(date));
assertEquals("Unexpected entry returned for @PermitAll invocation", "(PermitAll) - User " + user + " logged in at " + date.getTime(), entryForPermitAll);
// now call the (overloaded) method on the bean, after switching to a specific role that's allowed to access that method
final Callable<String> specificRoleMethodCall = () -> attendanceRegistryBean.recordEntry(user, date.getTime());
final String entryForSpecificRole = Util.switchIdentity("user2", "password2", specificRoleMethodCall);
assertEquals("Unexpected entry returned for @RolesAllowed invocation", "User " + user + " logged in at " + date.getTime(), entryForSpecificRole);
}
}
| 13,737 | 40.504532 | 172 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/LifecycleTestCase.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;
import static org.junit.Assert.fail;
import java.util.Map;
import java.util.concurrent.Callable;
import org.jboss.logging.Logger;
import jakarta.ejb.EJB;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.lifecycle.BaseBean;
import org.jboss.as.test.integration.ejb.security.lifecycle.EntryBean;
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.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
/**
* EJB 3.1 Section 17.2.5 - This test case is to test the programmatic access to the callers's security context for the various
* bean methods.
*
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
@RunWith(Arquillian.class)
@ServerSetup({EjbSecurityDomainSetup.class})
@Category(CommonCriteria.class)
public class LifecycleTestCase {
private static final Logger log = Logger.getLogger(LifecycleTestCase.class.getName());
private static final String USER1 = "user1";
private static final String TRUE = "true";
private static final String ILLEGAL_STATE = "IllegalStateException";
@EJB(mappedName = "java:global/ejb3security/EntryBean")
private EntryBean entryBean;
@Deployment
public static Archive<?> runAsDeployment() {
final Package currentPackage = LifecycleTestCase.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(EntryBean.class.getPackage())
.addClasses(Util.class) // TODO - Should not need to exclude the interfaces.
.addClasses(AbstractSecurityDomainSetup.class, EjbSecurityDomainSetup.class)
.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 testStatefulBean() throws Exception {
StringBuilder failureMessages = new StringBuilder();
final Callable<Void> callable = () -> {
Map<String, String> result = entryBean.testStatefulBean();
verifyResult(result, BaseBean.LIFECYCLE_CALLBACK, USER1, TRUE, failureMessages);
verifyResult(result, BaseBean.BUSINESS, USER1, TRUE, failureMessages);
verifyResult(result, BaseBean.AFTER_BEGIN, USER1, TRUE, failureMessages);
return null;
};
Util.switchIdentity("user1", "password1", callable);
if (failureMessages.length() > 0) {
fail(failureMessages.toString());
}
}
@Test
public void testStatefulBeanDependencyInjection() throws Exception {
StringBuilder failureMessages = new StringBuilder();
final Callable<Void> callable = () -> {
Map<String, String> result = entryBean.testStatefulBean();
verifyResult(result, BaseBean.DEPENDENCY_INJECTION, ILLEGAL_STATE, ILLEGAL_STATE,
failureMessages);
return null;
};
Util.switchIdentity("user1", "password1", callable);
if (failureMessages.length() > 0) {
fail(failureMessages.toString());
}
}
@Test
public void testStatelessBean() throws Exception {
StringBuilder failureMessages = new StringBuilder();
final Callable<Void> callable = () -> {
Map<String, String> result = entryBean.testStatlessBean();
logResult(result);
verifyResult(result, BaseBean.BUSINESS, USER1, TRUE, failureMessages);
return null;
};
Util.switchIdentity("user1", "password1", callable);
if (failureMessages.length() > 0) {
fail(failureMessages.toString());
}
}
@Test
public void testStatelessBeanDependencyInjection() throws Exception {
StringBuilder failureMessages = new StringBuilder();
final Callable<Void> callable = () -> {
Map<String, String> result = entryBean.testStatlessBean();
logResult(result);
verifyResult(result, BaseBean.DEPENDENCY_INJECTION, ILLEGAL_STATE, ILLEGAL_STATE,
failureMessages);
return null;
};
Util.switchIdentity("user1", "password1", callable);
if (failureMessages.length() > 0) {
fail(failureMessages.toString());
}
}
private static void logResult(Map<String, String> result) {
for (Map.Entry<String, String> entry : result.entrySet()) {
log.trace(entry.getKey() + " = " + entry.getValue());
}
}
// TODO - Add test for Message Driven Bean
private void verifyResult(Map<String, String> result, String beanMethod, String getCallerPrincipalResponse,
String isCallerInRoleResponse, StringBuilder errors) {
verify(beanMethod, BaseBean.GET_CALLER_PRINCIPAL, getCallerPrincipalResponse,
result.get(beanMethod + ":" + BaseBean.GET_CALLER_PRINCIPAL), errors);
verify(beanMethod, BaseBean.IS_CALLER_IN_ROLE, isCallerInRoleResponse, result.get(beanMethod + ":" + BaseBean.IS_CALLER_IN_ROLE), errors);
}
private void verify(String beanMethod, String ejbContextMethod, String expected, String actual, StringBuilder errors) {
if (expected.equals(actual) == false) {
errors.append('{');
errors.append(ejbContextMethod).append(" for ").append(beanMethod);
errors.append(" returned '").append(actual).append("' but we expected '");
errors.append(expected).append("'}");
}
}
}
| 7,577 | 41.573034 | 157 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/InjectionAnnSFSBtoSLSBTestCase.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;
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.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.authorization.InjectionSFSBtoSLSB;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
/**
* This test case check whether basic EJB authorization works from EJB client to injected stateless remote EJB.
*
* @author <a href="mailto:[email protected]">Jan Lanik</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
@Category(CommonCriteria.class)
public class InjectionAnnSFSBtoSLSBTestCase extends AnnSBTest {
private static final Logger log = Logger.getLogger(testClass());
private static final String MODULE = "injectionAnnOnlySFSBtoSLSB";
private static Class testClass(){
return InjectionAnnSFSBtoSLSBTestCase.class;
}
private static Class beanClass(){
return InjectionSFSBtoSLSB.class;
}
@Deployment(name = MODULE + ".jar", order = 1, testable = false)
public static Archive<JavaArchive> deployment() {
return testAppDeployment(Logger.getLogger(testClass()), MODULE, beanClass());
}
@Test
public void testSingleMethodAnnotationsNoUser() throws Exception {
testSingleMethodAnnotationsNoUserTemplate(MODULE,log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser1() throws Exception {
testSingleMethodAnnotationsUser1Template(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser2() throws Exception {
testSingleMethodAnnotationsUser2Template(MODULE, log, beanClass());
}
}
| 2,939 | 36.21519 | 111 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/InjectionAnnSFSBtoSFSBTestCase.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;
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.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.authorization.InjectionSFSBtoSFSB;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
/**
* This test case check whether basic EJB authorization works from EJB client to injected stateless remote EJB.
*
* @author <a href="mailto:[email protected]">Jan Lanik</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
@Category(CommonCriteria.class)
public class InjectionAnnSFSBtoSFSBTestCase extends AnnSBTest {
private static final Logger log = Logger.getLogger(testClass());
private static final String MODULE = "injectionAnnOnlySFSBtoSFSB";
private static Class testClass(){
return InjectionAnnSFSBtoSFSBTestCase.class;
}
private static Class beanClass(){
return InjectionSFSBtoSFSB.class;
}
@Deployment(name = MODULE + ".jar", order = 1, testable = false)
public static Archive<JavaArchive> deployment() {
return testAppDeployment(Logger.getLogger(testClass()), MODULE, beanClass());
}
@Test
public void testSingleMethodAnnotationsNoUser() throws Exception {
testSingleMethodAnnotationsNoUserTemplate(MODULE,log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser1() throws Exception {
testSingleMethodAnnotationsUser1Template(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser2() throws Exception {
testSingleMethodAnnotationsUser2Template(MODULE, log, beanClass());
}
}
| 2,939 | 36.21519 | 111 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/EJBSecurityTestCase.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;
import static org.junit.Assert.assertEquals;
import jakarta.ejb.EJBAccessException;
import javax.naming.Context;
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.as.test.categories.CommonCriteria;
import org.jboss.shrinkwrap.api.ShrinkWrap;
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;
/**
* User: jpai
*/
@RunWith(Arquillian.class)
@Category(CommonCriteria.class)
public class EJBSecurityTestCase {
@ArquillianResource
private Context ctx;
@Deployment
public static JavaArchive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejb-security-test.jar");
jar.addPackage(AnnotatedSLSB.class.getPackage());
jar.addAsManifestResource(EJBSecurityTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
jar.addAsManifestResource(EJBSecurityTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
jar.addPackage(CommonCriteria.class.getPackage());
return jar;
}
private <T> T lookup(final Class<?> beanClass, final Class<T> viewClass) throws NamingException {
return viewClass.cast(ctx.lookup("java:module/" + beanClass.getSimpleName() + "!" + viewClass.getName()));
}
@Test
public void testDenyAllAnnotation() throws Exception {
final Context ctx = new InitialContext();
final Restriction restrictedBean = (Restriction) ctx.lookup("java:module/" + AnnotatedSLSB.class.getSimpleName() + "!" + Restriction.class.getName());
try {
restrictedBean.restrictedMethod();
Assert.fail("Call to restrictedMethod() method was expected to fail");
} catch (EJBAccessException ejbae) {
// expected
}
final FullAccess fullAccessBean = (FullAccess) ctx.lookup("java:module/" + AnnotatedSLSB.class.getSimpleName() + "!" + FullAccess.class.getName());
fullAccessBean.doAnything();
final AnnotatedSLSB annotatedBean = (AnnotatedSLSB) ctx.lookup("java:module/" + AnnotatedSLSB.class.getSimpleName() + "!" + AnnotatedSLSB.class.getName());
try {
annotatedBean.restrictedMethod();
Assert.fail("Call to restrictedMethod() method was expected to fail");
} catch (EJBAccessException ejbae) {
//expected
}
// full access, should work
annotatedBean.doAnything();
try {
annotatedBean.restrictedBaseClassMethod();
Assert.fail("Call to restrictedBaseClassMethod() method was expected to fail");
} catch (EJBAccessException ejbae) {
//expected
}
// should be accessible, since the overridden method isn't annotated with @DenyAll
annotatedBean.overriddenMethod();
final FullyRestrictedBean fullyRestrictedBean = (FullyRestrictedBean) ctx.lookup("java:module/" + FullyRestrictedBean.class.getSimpleName() + "!" + FullyRestrictedBean.class.getName());
try {
fullyRestrictedBean.overriddenMethod();
Assert.fail("Call to overriddenMethod() method was expected to fail");
} catch (EJBAccessException ejae) {
// expected
}
}
@Test
public void testEJB2() throws Exception {
// AS7-2809: if it deploys we're good
final HelloRemote bean = lookup(HelloBean.class, HelloHome.class).create();
final String result = bean.sayHello("EJB2");
assertEquals("Hello EJB2", result);
}
@Test
public void testExcludeList() throws Exception {
final Context ctx = new InitialContext();
final FullAccess fullAccessDDBean = (FullAccess) ctx.lookup("java:module/" + DDBasedSLSB.class.getSimpleName() + "!" + FullAccess.class.getName());
fullAccessDDBean.doAnything();
final DDBasedSLSB ddBasedSLSB = (DDBasedSLSB) ctx.lookup("java:module/" + DDBasedSLSB.class.getSimpleName() + "!" + DDBasedSLSB.class.getName());
try {
ddBasedSLSB.accessDenied();
Assert.fail("Call to accessDenied() method was expected to fail");
} catch (EJBAccessException ejbae) {
// expected
}
try {
ddBasedSLSB.onlyTestRoleCanAccess();
Assert.fail("Call to onlyTestRoleCanAccess() method was expected to fail");
} catch (EJBAccessException ejbae) {
// expected since only TestRole can call that method
}
}
/**
* Tests that a bean which doesn't explicitly have a security domain configured, but still has EJB security related
* annotations on it, is still considered secured and the security annotations are honoured
*
* @throws Exception
*/
@Test
public void testSecurityOnBeanInAbsenceOfExplicitSecurityDomain() throws Exception {
final Context ctx = new InitialContext();
// lookup the bean which doesn't explicitly have any security domain configured
final Restriction restrictedBean = (Restriction) ctx.lookup("java:module/" + BeanWithoutExplicitSecurityDomain.class.getSimpleName() + "!" + Restriction.class.getName());
try {
// try invoking a method annotated @DenyAll (expected to fail)
restrictedBean.restrictedMethod();
Assert.fail("Call to restrictedMethod() method was expected to fail");
} catch (EJBAccessException ejbae) {
// expected
}
// lookup the bean which doesn't explicitly have any security domain configured
final FullAccess fullAccessBean = (FullAccess) ctx.lookup("java:module/" + BeanWithoutExplicitSecurityDomain.class.getSimpleName() + "!" + FullAccess.class.getName());
// invoke a @PermitAll method
fullAccessBean.doAnything();
// lookup the bean which doesn't explicitly have any security domain configured
final BeanWithoutExplicitSecurityDomain specificRoleAccessBean = (BeanWithoutExplicitSecurityDomain) ctx.lookup("java:module/" + BeanWithoutExplicitSecurityDomain.class.getSimpleName() + "!" + BeanWithoutExplicitSecurityDomain.class.getName());
try {
// invoke a method which only a specific role can access.
// this is expected to fail since we haven't logged in as any user
specificRoleAccessBean.allowOnlyRoleTwoToAccess();
Assert.fail("Invocation was expected to fail since only a specific role was expected to be allowed to access the bean method");
} catch (EJBAccessException ejbae) {
// expected
}
}
/**
* Tests that if a method of an EJB is annotated with a {@link jakarta.annotation.security.RolesAllowed} with empty value for the annotation
* <code>@RolesAllowed({})</code> then access to that method by any user MUST throw an EJBAccessException. i.e. it should
* behave like a @DenyAll
*
* @throws Exception
*/
@Test
public void testEmptyRolesAllowedAnnotationValue() throws Exception {
final Context ctx = new InitialContext();
final AnnotatedSLSB annotatedBean = (AnnotatedSLSB) ctx.lookup("java:module/" + AnnotatedSLSB.class.getSimpleName() + "!" + AnnotatedSLSB.class.getName());
try {
annotatedBean.methodWithEmptyRolesAllowedAnnotation();
Assert.fail("Call to methodWithEmptyRolesAllowedAnnotation() method was expected to fail");
} catch (EJBAccessException ejbae) {
//expected
}
}
}
| 8,851 | 43.93401 | 252 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/MDBRoleTestCase.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;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.PropertyPermission;
import jakarta.jms.Destination;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageProducer;
import jakarta.jms.Queue;
import jakarta.jms.QueueConnection;
import jakarta.jms.QueueConnectionFactory;
import jakarta.jms.QueueReceiver;
import jakarta.jms.QueueSession;
import jakarta.jms.Session;
import jakarta.jms.TextMessage;
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.as.arquillian.api.ServerSetup;
import org.jboss.as.test.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.authorization.MDBRole;
import org.jboss.as.test.integration.ejb.security.authorization.Simple;
import org.jboss.as.test.integration.ejb.security.authorization.SimpleSLSB;
import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup;
import org.jboss.as.test.jms.auxiliary.CreateQueueSetupTask;
import org.jboss.as.test.shared.TimeoutUtil;
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.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;
/**
* Deploys a message driven bean and a stateless bean which is injected into MDB
* Then the cooperation of @RunAs annotation on MDB and @RolesAllowed annotation on SLSB is tested.
* <p/>
* https://issues.jboss.org/browse/JBQA-5628
*
* @author <a href="mailto:[email protected]">Jan Lanik</a>.
*/
@RunWith(Arquillian.class)
@ServerSetup({CreateQueueSetupTask.class, EjbSecurityDomainSetup.class})
@Category(CommonCriteria.class)
public class MDBRoleTestCase {
Logger logger = Logger.getLogger(MDBRoleTestCase.class);
@Deployment
public static Archive<?> deployment() {
final JavaArchive deployment = ShrinkWrap.create(JavaArchive.class, "ejb3mdb.jar")
.addClass(MDBRole.class)
.addClass(CreateQueueSetupTask.class)
.addClasses(AbstractSecurityDomainSetup.class, EjbSecurityDomainSetup.class)
.addClass(Simple.class)
.addClass(SimpleSLSB.class)
.addClass(TimeoutUtil.class);
deployment.addAsManifestResource(MDBRoleTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
deployment.addPackage(CommonCriteria.class.getPackage());
// grant necessary permissions
// TODO WFLY-15289 The Elytron permissions need to be checked, should a deployment really need these?
deployment.addAsResource(createPermissionsXmlAsset(new PropertyPermission("ts.timeout.factor", "read"),
new ElytronPermission("setRunAsPrincipal"),
new ElytronPermission("handleSecurityEvent"),
new ChangeRoleMapperPermission("ejb")), "META-INF/jboss-permissions.xml");
return deployment;
}
@Test
public void testIsMDBinRole() throws NamingException, JMSException {
final InitialContext ctx = new InitialContext();
final QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("java:/JmsXA");
final QueueConnection connection = factory.createQueueConnection();
connection.start();
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final Queue replyDestination = session.createTemporaryQueue();
final QueueReceiver receiver = session.createReceiver(replyDestination);
final Message message = session.createTextMessage("Let's test it!");
message.setJMSReplyTo(replyDestination);
final Destination destination = (Destination) ctx.lookup("queue/myAwesomeQueue");
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
producer.close();
final Message reply = receiver.receive(TimeoutUtil.adjust(5000));
assertNotNull(reply);
final String result = ((TextMessage) reply).getText();
assertEquals(SimpleSLSB.SUCCESS, result);
connection.close();
}
}
| 5,692 | 44.544 | 131 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/Restriction.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;
/**
* User: jpai
*/
public interface Restriction {
void restrictedMethod();
}
| 1,162 | 35.34375 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/EJBInWarDefaultSecurityDomainTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, 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;
import java.util.concurrent.Callable;
import jakarta.ejb.EJBAccessException;
import javax.naming.Context;
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.as.arquillian.api.ServerSetup;
import org.jboss.as.test.categories.CommonCriteria;
import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup;
import org.jboss.as.test.shared.integration.ejb.security.Util;
import org.jboss.shrinkwrap.api.ShrinkWrap;
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;
/**
* User: jpai
*/
@RunWith(Arquillian.class)
@Category(CommonCriteria.class)
@ServerSetup({EjbSecurityDomainSetup.class})
public class EJBInWarDefaultSecurityDomainTestCase {
@ArquillianResource
private Context ctx;
@Deployment
public static WebArchive createDeployment() {
final Package currentPackage = EJBInWarDefaultSecurityDomainTestCase.class.getPackage();
final WebArchive war = ShrinkWrap.create(WebArchive.class, "ejb-security-test.war")
.addClasses(BeanWithoutExplicitSecurityDomain.class, Restriction.class)
.addClasses(FullAccess.class, EjbSecurityDomainSetup.class, Util.class)
.addAsWebInfResource(currentPackage, "jboss-web.xml", "jboss-web.xml")
.addPackage(CommonCriteria.class.getPackage())
.addPackage(AbstractSecurityDomainSetup.class.getPackage())
.addAsManifestResource(currentPackage, "permissions.xml", "permissions.xml");
return war;
}
private <T> T lookup(final Class<?> beanClass, final Class<T> viewClass) throws NamingException {
return viewClass.cast(ctx.lookup("java:module/" + beanClass.getSimpleName() + "!" + viewClass.getName()));
}
/**
* Tests that a bean which doesn't explicitly have a security domain configured, but still has EJB security related
* annotations on it, is still considered secured and the security annotations are honoured
*
* @throws Exception
*/
@Test
public void testSecurityOnBeanInAbsenceOfExplicitSecurityDomain() throws Exception {
final Context ctx = new InitialContext();
// lookup the bean which doesn't explicitly have any security domain configured
final Restriction restrictedBean = (Restriction) ctx.lookup("java:module/" + BeanWithoutExplicitSecurityDomain.class.getSimpleName() + "!" + Restriction.class.getName());
try {
// try invoking a method annotated @DenyAll (expected to fail)
restrictedBean.restrictedMethod();
Assert.fail("Call to restrictedMethod() method was expected to fail");
} catch (EJBAccessException ejbae) {
// expected
}
// lookup the bean which doesn't explicitly have any security domain configured
final FullAccess fullAccessBean = (FullAccess) ctx.lookup("java:module/" + BeanWithoutExplicitSecurityDomain.class.getSimpleName() + "!" + FullAccess.class.getName());
// invoke a @PermitAll method
fullAccessBean.doAnything();
// lookup the bean which doesn't explicitly have any security domain configured
final BeanWithoutExplicitSecurityDomain specificRoleAccessBean = (BeanWithoutExplicitSecurityDomain) ctx.lookup("java:module/" + BeanWithoutExplicitSecurityDomain.class.getSimpleName() + "!" + BeanWithoutExplicitSecurityDomain.class.getName());
try {
// invoke a method which only a specific role can access.
// this is expected to fail since we haven't logged in as any user
specificRoleAccessBean.allowOnlyRoleTwoToAccess();
Assert.fail("Invocation was expected to fail since only a specific role was expected to be allowed to access the bean method");
} catch (EJBAccessException ejbae) {
// expected
}
// login as user1 and test
Callable<Void> callable = () -> {
// expected to pass since user1 belongs to Role1
specificRoleAccessBean.allowOnlyRoleOneToAccess();
// expected to fail since user1 *doesn't* belong to Role2
try {
specificRoleAccessBean.allowOnlyRoleTwoToAccess();
Assert.fail("Call to toBeInvokedByRole2() was expected to fail");
} catch (EJBAccessException ejbae) {
// expected
}
return null;
};
Util.switchIdentity("user1", "password1", callable);
// login as user2 and test
callable = () -> {
// expected to pass since user2 belongs to Role2
specificRoleAccessBean.allowOnlyRoleTwoToAccess();
// expected to fail since user2 *doesn't* belong to Role1
try {
specificRoleAccessBean.allowOnlyRoleOneToAccess();
Assert.fail("Call to toBeInvokedOnlyByRole1() was expected to fail");
} catch (EJBAccessException ejbae) {
// expected
}
return null;
};
Util.switchIdentity("user2", "password2", callable);
}
}
| 6,492 | 44.090278 | 252 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/SingleMethodsAnnSFSBTestCase.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;
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.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.authorization.SingleMethodsAnnOnlyCheckSFSB;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
/**
* This test case check whether basic EJB authorization works from EJB client to remote stateful EJB.
*
* @author <a href="mailto:[email protected]">Peter Skopek</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
@Category(CommonCriteria.class)
public class SingleMethodsAnnSFSBTestCase extends AnnSBTest {
private static final Logger log = Logger.getLogger(testClass());
private static final String MODULE = "singleMethodsAnnOnlySFSB";
private static Class testClass() {
return SingleMethodsAnnSFSBTestCase.class;
}
private static Class beanClass() {
return SingleMethodsAnnOnlyCheckSFSB.class;
}
@Deployment(name = MODULE + ".jar", order = 1, testable = false)
public static Archive<JavaArchive> deployment() {
return testAppDeployment(Logger.getLogger(testClass()), MODULE, beanClass());
}
@Test
public void testSingleMethodAnnotationsNoUser() throws Exception {
testSingleMethodAnnotationsNoUserTemplate(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser1() throws Exception {
testSingleMethodAnnotationsUser1Template(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser2() throws Exception {
testSingleMethodAnnotationsUser2Template(MODULE, log, beanClass());
}
}
| 2,952 | 36.379747 | 101 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/InherritanceAnnSLSBTestCase.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;
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.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.authorization.InherritanceAnnOnlyCheckSLSB;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
/**
* This test case check whether basic EJB authorization works from EJB client to inherrited stateless remote EJB.
*
* @author <a href="mailto:[email protected]">Jan Lanik</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
@Category(CommonCriteria.class)
public class InherritanceAnnSLSBTestCase extends AnnSBTest {
private static final Logger log = Logger.getLogger(testClass());
private static final String MODULE = "inherritanceAnnOnlySLSB";
private static Class testClass() {
return InherritanceAnnSLSBTestCase.class;
}
private static Class beanClass() {
return InherritanceAnnOnlyCheckSLSB.class;
}
@Deployment(name = MODULE + ".jar", order = 1, testable = false)
public static Archive<JavaArchive> deployment() {
return testAppDeployment(Logger.getLogger(testClass()), MODULE, beanClass());
}
@Test
public void testSingleMethodAnnotationsNoUser() throws Exception {
testSingleMethodAnnotationsNoUserTemplate(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser1() throws Exception {
testSingleMethodAnnotationsUser1Template(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser2() throws Exception {
testSingleMethodAnnotationsUser2Template(MODULE, log, beanClass());
}
}
| 2,952 | 36.858974 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/SecurityDDOverrideTestCase.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;
import java.util.concurrent.Callable;
import jakarta.ejb.EJBAccessException;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.dd.override.PartialDDBean;
import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup;
import org.jboss.as.test.shared.integration.ejb.security.Util;
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;
/**
* Tests that security configurations on an EJB, overriden through the use of ejb-jar.xml work as expected
* <p/>
* User: Jaikiran Pai
*/
@RunWith(Arquillian.class)
@ServerSetup({EjbSecurityDomainSetup.class})
@Category(CommonCriteria.class)
public class SecurityDDOverrideTestCase {
private static final Logger logger = Logger.getLogger(SecurityDDOverrideTestCase.class);
@Deployment
public static Archive<?> runAsDeployment() {
final Package currentPackage = SecurityDDOverrideTestCase.class.getPackage();
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejb3-security-partial-dd-test.jar")
.addPackage(PartialDDBean.class.getPackage())
.addClass(Util.class)
.addClasses(AbstractSecurityDomainSetup.class, EjbSecurityDomainSetup.class)
.addAsManifestResource(currentPackage, "partial-ejb-jar.xml", "ejb-jar.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")
.addPackage(CommonCriteria.class.getPackage());
return jar;
}
/**
* Tests that the overriden roles allowed, via ejb-jar.xml, on an EJB method are taken into account for EJB method
* invocations
*
* @throws Exception
*/
@Test
public void testDDOverride() throws Exception {
final Context ctx = new InitialContext();
final PartialDDBean partialDDBean = (PartialDDBean) ctx.lookup("java:module/" + PartialDDBean.class.getSimpleName() + "!" + PartialDDBean.class.getName());
try {
partialDDBean.denyAllMethod();
Assert.fail("Call to denyAllMethod() was expected to fail");
} catch (EJBAccessException ejbae) {
// expected
}
// expected to pass
partialDDBean.permitAllMethod();
// login as user1 and test
Callable<Void> callable = () -> {
// expected to pass since user1 belongs to Role1
partialDDBean.toBeInvokedOnlyByRole1();
// expected to fail since user1 *doesn't* belong to Role2
try {
partialDDBean.toBeInvokedByRole2();
Assert.fail("Call to toBeInvokedByRole2() was expected to fail");
} catch (EJBAccessException ejbae) {
// expected
}
return null;
};
Util.switchIdentity("user1", "password1", callable);
// login as user2 and test
callable = () -> {
// expected to pass since user2 belongs to Role2
partialDDBean.toBeInvokedByRole2();
// expected to fail since user2 *doesn't* belong to Role1
try {
partialDDBean.toBeInvokedOnlyByRole1();
Assert.fail("Call to toBeInvokedOnlyByRole1() was expected to fail");
} catch (EJBAccessException ejbae) {
// expected
}
return null;
};
Util.switchIdentity("user2", "password2", callable);
}
}
| 5,214 | 39.742188 | 163 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/WhoAmI.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;
import java.security.Principal;
import jakarta.ejb.Local;
/**
* The local interface to the simple WhoAmI bean.
*
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
@Local
public interface WhoAmI {
/**
* @return the caller principal obtained from the EJBContext.
*/
Principal getCallerPrincipal();
/**
* @param roleName - The role to check.
* @return The result of calling EJBContext.isCallerInRole() with the supplied role name.
*/
boolean doIHaveRole(String roleName);
}
| 1,628 | 33.659574 | 93 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/RunAsBean.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;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.Stateful;
/**
* User: jpai
*/
@Stateful
@RunAs("SpiderMan")
public class RunAsBean {
}
| 1,228 | 34.114286 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/EjbSecurityDomainSetup.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;
import java.io.File;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup;
import org.wildfly.test.security.common.elytron.EjbElytronDomainSetup;
import org.wildfly.test.security.common.elytron.ElytronDomainSetup;
import org.wildfly.test.security.common.elytron.ServletElytronDomainSetup;
/**
* Utility methods to create/remove simple security domains
*
* @author <a href="mailto:[email protected]">Marcus Moyses</a>
*/
public class EjbSecurityDomainSetup extends AbstractSecurityDomainSetup {
protected static final String DEFAULT_SECURITY_DOMAIN_NAME = "ejb3-tests";
private ElytronDomainSetup elytronDomainSetup;
private EjbElytronDomainSetup ejbElytronDomainSetup;
private ServletElytronDomainSetup servletElytronDomainSetup;
@Override
protected String getSecurityDomainName() {
return DEFAULT_SECURITY_DOMAIN_NAME;
}
protected String getUsersFile() {
return new File(EjbSecurityDomainSetup.class.getResource("users.properties").getFile()).getAbsolutePath();
}
protected String getGroupsFile() {
return new File(EjbSecurityDomainSetup.class.getResource("roles.properties").getFile()).getAbsolutePath();
}
public boolean isUsersRolesRequired() {
return true;
}
@Override
public void setup(final ManagementClient managementClient, final String containerId) throws Exception {
elytronDomainSetup = new ElytronDomainSetup(getUsersFile(), getGroupsFile(), getSecurityDomainName());
ejbElytronDomainSetup = new EjbElytronDomainSetup(getSecurityDomainName());
servletElytronDomainSetup = new ServletElytronDomainSetup(getSecurityDomainName());
elytronDomainSetup.setup(managementClient, containerId);
ejbElytronDomainSetup.setup(managementClient, containerId);
servletElytronDomainSetup.setup(managementClient, containerId);
}
@Override
public void tearDown(final ManagementClient managementClient, final String containerId) {
if (elytronDomainSetup != null) {
// if one of tearDown will fail, rest of them should be called through
Exception ex = null;
try {
servletElytronDomainSetup.tearDown(managementClient, containerId);
} catch (Exception e) {
ex = e;
}
try {
ejbElytronDomainSetup.tearDown(managementClient, containerId);
} catch (Exception e) {
if (ex == null) ex = e;
}
try {
elytronDomainSetup.tearDown(managementClient, containerId);
} catch (Exception e) {
if (ex == null) ex = e;
}
if (ex != null) throw new RuntimeException(ex);
}
}
}
| 3,937 | 39.597938 | 114 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/InherritanceAnnSFSBTestCase.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;
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.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.authorization.InherritanceAnnOnlyCheckSFSB;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
/**
* This test case check whether basic EJB authorization works from EJB client to inherrited stateless remote EJB.
*
* @author <a href="mailto:[email protected]">Jan Lanik</a>.
*/
@RunWith(Arquillian.class)
@RunAsClient
@Category(CommonCriteria.class)
public class InherritanceAnnSFSBTestCase extends AnnSBTest{
private static final Logger log = Logger.getLogger(testClass());
private static final String MODULE = "inherritanceAnnOnlySFSB";
private static Class testClass() {
return InherritanceAnnSFSBTestCase.class;
}
private static Class beanClass() {
return InherritanceAnnOnlyCheckSFSB.class;
}
@Deployment(name = MODULE + ".jar", order = 1, testable = false)
public static Archive<JavaArchive> deployment() {
return testAppDeployment(Logger.getLogger(testClass()), MODULE, beanClass());
}
@Test
public void testSingleMethodAnnotationsNoUser() throws Exception {
testSingleMethodAnnotationsNoUserTemplate(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser1() throws Exception {
testSingleMethodAnnotationsUser1Template(MODULE, log, beanClass());
}
@Test
public void testSingleMethodAnnotationsUser2() throws Exception {
testSingleMethodAnnotationsUser2Template(MODULE, log, beanClass());
}
}
| 2,953 | 36.392405 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/dd/override/PartialDDBean.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.dd.override;
import jakarta.annotation.Resource;
import jakarta.annotation.security.DenyAll;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* User: jpai
*/
@Stateless
@SecurityDomain("ejb3-tests")
public class PartialDDBean {
@Resource
private SessionContext sessionContext;
@DenyAll
public void denyAllMethod() {
throw new RuntimeException("Invocation on this method shouldn't have been allowed!");
}
@PermitAll
public void permitAllMethod() {
}
@RolesAllowed("Role1")
public void toBeInvokedOnlyByRole1() {
}
@RolesAllowed("Role1") // Role1 is set here but overriden as Role2 in ejb-jar.xml
public void toBeInvokedByRole2() {
}
}
| 1,949 | 29.952381 | 93 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/asynchronous/AsynchronousSecurityTestCase.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.asynchronous;
import java.io.File;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import jakarta.ejb.EJBAccessException;
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.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.test.categories.CommonCriteria;
import org.jboss.as.test.integration.ejb.security.AnnotationAuthorizationTestCase;
import org.jboss.as.test.integration.ejb.security.EjbSecurityDomainSetup;
import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup;
import org.jboss.as.test.shared.integration.ejb.security.Util;
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;
/**
* Migration test from EJB Testsuite (asynchronous) to AS7 [JIRA JBQA-5483].
*
* Test if asynchronous calls and security check works.
*/
@RunWith(Arquillian.class)
@ServerSetup({AsynchronousSecurityTestCase.AsynchronousSecurityTestCaseSetup.class})
@Category(CommonCriteria.class)
public class AsynchronousSecurityTestCase {
private static final Logger log = Logger.getLogger(AsynchronousSecurityTestCase.class);
private static final String ARCHIVE_NAME = "AsyncSecurityTestCase";
static class AsynchronousSecurityTestCaseSetup extends EjbSecurityDomainSetup {
@Override
protected String getSecurityDomainName() {
return "async-security-test";
}
@Override
protected String getUsersFile() {
return new File(AsynchronousSecurityTestCase.class.getResource("users.properties").getFile()).getAbsolutePath();
}
@Override
protected String getGroupsFile() {
return new File(AsynchronousSecurityTestCase.class.getResource("roles.properties").getFile()).getAbsolutePath();
}
}
@ArquillianResource
private InitialContext iniCtx;
@Deployment
public static Archive<?> deploy() {
final Package currentPackage = AsynchronousSecurityTestCase.class.getPackage();
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar")
.addPackage(currentPackage)
.addClass(AnnotationAuthorizationTestCase.class)
.addClasses(EjbSecurityDomainSetup.class, AbstractSecurityDomainSetup.class, ServerSetupTask.class, Util.class)
.addAsResource(currentPackage, "roles.properties", "roles.properties")
.addAsResource(currentPackage, "users.properties", "users.properties")
.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client,org.jboss.dmr\n"),"MANIFEST.MF")
.addAsManifestResource(currentPackage, "permissions.xml", "permissions.xml")
.addPackage(CommonCriteria.class.getPackage());
return jar;
}
protected <Q, T> Q lookupInterface(Class<T> bean, Class<Q> intf) throws NamingException {
log.trace("initctx: " + iniCtx);
return intf.cast(iniCtx.lookup("java:global/" + ARCHIVE_NAME + "/" + bean.getSimpleName() + "!"
+ intf.getName()));
}
@Test
public void testAsynchSecurityMethod() throws Exception {
SecuredStatelessRemote securedBean = lookupInterface(SecuredStatelessBean.class, SecuredStatelessRemote.class);
boolean result = false;
// Test 1
SecuredStatelessBean.reset();
Callable<Boolean> callable = () -> {
Future<Boolean> future = securedBean.method();
SecuredStatelessBean.startLatch.countDown();
return future.get();
};
result = Util.switchIdentity("somebody", "password", callable);
Assert.assertTrue(result);
// Test 2
SecuredStatelessBean.reset();
result = false;
callable = () -> {
Future<Boolean> future = securedBean.method();
SecuredStatelessBean.startLatch.countDown();
return future.get();
};
try {
result = Util.switchIdentity("rolefail", "password", callable);
} catch (ExecutionException ee) {
if(!(ee.getCause() instanceof EJBAccessException)) {
Assert.fail("Exception cause was not EJBAccessException and was " + ee);
}
} catch (EJBAccessException ejbe) {
// it's ok too
}
Assert.assertFalse(result);
// Test 3
SecuredStatelessBean.reset();
result = false;
callable = () -> {
Future<Boolean> future = securedBean.method();
SecuredStatelessBean.startLatch.countDown();
return future.get();
};
try {
result = Util.switchIdentity("nosuchuser", "password", callable);
} catch (ExecutionException ee) {
if(!(ee.getCause() instanceof EJBAccessException) && ! (ee.getCause() instanceof SecurityException)) {
Assert.fail("Exception cause was not EJBAccessException or SecurityException and was " + ee);
}
} catch (EJBAccessException | SecurityException ejbe) {
// it's ok too
}
Assert.assertFalse(result);
}
@Test
public void testAsyncSecurityPermition() throws Exception {
SecuredStatelessBean.reset();
SecuredStatelessRemote securedBean = lookupInterface(SecuredStatelessBean.class, SecuredStatelessRemote.class);
boolean result = false;
final Callable<Boolean> callable = () -> {
// Test 1
Future<Boolean> future = securedBean.uncheckedMethod();
SecuredStatelessBean.startLatch.countDown();
boolean test1Result = future.get();
Assert.assertTrue(test1Result);
// Test 2
future = null;
SecuredStatelessBean.reset();
future = securedBean.excludedMethod();
SecuredStatelessBean.startLatch.countDown();
return future.get();
};
try {
result = Util.switchIdentity("rolefail", "password", callable);
} catch (ExecutionException ee) {
if(!(ee.getCause() instanceof EJBAccessException)) {
Assert.fail("Exception cause was not EJBAccessException and was " + ee);
}
} catch (EJBAccessException ejbe) {
// it's ok too
}
Assert.assertFalse(result);
}
}
| 8,007 | 40.066667 | 133 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/asynchronous/SecuredStatelessBean.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.asynchronous;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.security.DenyAll;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.AsyncResult;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.Local;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.ejb3.annotation.SecurityDomain;
import org.junit.Assert;
/**
* @author <a href="mailto:[email protected]">Kabir Khan</a>
*/
@Stateless
@SecurityDomain("async-security-test")
@Remote(SecuredStatelessRemote.class)
@Local(SecuredStatelessLocal.class)
@Asynchronous
public class SecuredStatelessBean implements SecuredStatelessRemote, SecuredStatelessLocal {
public static volatile CountDownLatch startLatch = new CountDownLatch(1);
public static void reset() {
startLatch = new CountDownLatch(1);
}
@PermitAll
public Future<Boolean> uncheckedMethod() throws InterruptedException {
try {
if (!startLatch.await(5, TimeUnit.SECONDS)) {
throw new RuntimeException("Invocation was not asynchronous");
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return new AsyncResult<Boolean>(true);
}
@DenyAll
public Future<Boolean> excludedMethod() throws InterruptedException {
try {
if (!startLatch.await(5, TimeUnit.SECONDS)) {
throw new RuntimeException("Invocation was not asynchronous");
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return new AsyncResult<Boolean>(true);
}
@RolesAllowed("allowed")
public Future<Boolean> method() throws InterruptedException, ExecutionException {
try {
if (!startLatch.await(5, TimeUnit.SECONDS)) {
throw new RuntimeException("Invocation was not asynchronous");
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
SecuredStatelessLocal localSearchedBean = null;
try {
Context context = new InitialContext();
localSearchedBean = (SecuredStatelessLocal) context.lookup("java:module/" + SecuredStatelessBean.class.getSimpleName() + "!"
+ SecuredStatelessLocal.class.getName());
} catch (NamingException e) {
throw new RuntimeException(e);
}
final CountDownLatch latchLocal = new CountDownLatch(1);
final Future<Boolean> future = localSearchedBean.localSecured(latchLocal);
latchLocal.countDown();
boolean result = future.get();
Assert.assertTrue(result);
return new AsyncResult<Boolean>(true);
}
@RolesAllowed("allowed")
public Future<Boolean> localSecured(CountDownLatch latchLocal) throws InterruptedException {
latchLocal.await(5, TimeUnit.SECONDS);
return new AsyncResult<Boolean>(true);
}
}
| 4,324 | 35.041667 | 136 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/asynchronous/SecuredStatelessLocal.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.asynchronous;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
/**
* @author <a href="mailto:[email protected]">Kabir Khan</a>
*/
public interface SecuredStatelessLocal {
Future<Boolean> localSecured(CountDownLatch latchLocal) throws InterruptedException;
Future<Boolean> excludedMethod() throws InterruptedException;
}
| 1,442 | 39.083333 | 88 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/asynchronous/SecuredStatelessRemote.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.asynchronous;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/**
* @author <a href="mailto:[email protected]">Kabir Khan</a>
*/
public interface SecuredStatelessRemote {
Future<Boolean> uncheckedMethod() throws InterruptedException;
Future<Boolean> excludedMethod() throws InterruptedException;
Future<Boolean> method() throws InterruptedException, ExecutionException;
}
| 1,506 | 36.675 | 77 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runasprincipal/StatelessBBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2010, JBoss 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.security.runasprincipal;
import org.jboss.ejb3.annotation.SecurityDomain;
import jakarta.annotation.Resource;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.Local;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@Stateless
@Local(WhoAmI.class)
@RolesAllowed("Admin")
@SecurityDomain("other")
public class StatelessBBean implements WhoAmI {
@Resource
private SessionContext ctx;
public String getCallerPrincipal() {
return ctx.getCallerPrincipal().getName();
}
}
| 1,661 | 34.361702 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runasprincipal/CallerWithIdentity.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2010, JBoss 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.security.runasprincipal;
import org.jboss.ejb3.annotation.RunAsPrincipal;
import org.jboss.ejb3.annotation.SecurityDomain;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.EJB;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@Stateless
@Remote(WhoAmI.class)
@RunAs("Admin")
@RunAsPrincipal("jackinabox")
@SecurityDomain("other")
public class CallerWithIdentity implements WhoAmI {
@EJB(beanName = "StatelessABean")
private WhoAmI beanA;
public String getCallerPrincipal() {
return beanA.getCallerPrincipal();
}
}
| 1,695 | 34.333333 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runasprincipal/CallerRunAsPrincipal.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2010, JBoss 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.security.runasprincipal;
import jakarta.ejb.EJB;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
import org.jboss.ejb3.annotation.RunAsPrincipal;
import org.jboss.ejb3.annotation.SecurityDomain;
@Stateless
@Remote(WhoAmI.class)
@RunAsPrincipal("Admin")
@SecurityDomain("other")
public class CallerRunAsPrincipal implements WhoAmI {
@EJB(beanName = "StatelessBBean")
private WhoAmI beanB;
public String getCallerPrincipal() {
return beanB.getCallerPrincipal();
}
}
| 1,563 | 33.755556 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runasprincipal/Caller.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2010, JBoss 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.security.runasprincipal;
import org.jboss.ejb3.annotation.SecurityDomain;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.EJB;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@Stateless
@Remote(WhoAmI.class)
@RunAs("Admin")
@SecurityDomain("other")
public class Caller implements WhoAmI {
@EJB(beanName = "StatelessBBean")
private WhoAmI beanB;
public String getCallerPrincipal() {
return beanB.getCallerPrincipal();
}
}
| 1,604 | 33.891304 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runasprincipal/StatelessABean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2010, JBoss 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.security.runasprincipal;
import org.jboss.ejb3.annotation.SecurityDomain;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.EJB;
import jakarta.ejb.Local;
import jakarta.ejb.Stateless;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@Stateless
@Local(WhoAmI.class)
@RolesAllowed("Admin")
@SecurityDomain("other")
public class StatelessABean implements WhoAmI {
@EJB(beanName = "StatelessBBean")
private WhoAmI beanB;
public String getCallerPrincipal() {
return beanB.getCallerPrincipal();
}
}
| 1,624 | 34.326087 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runasprincipal/WhoAmI.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2010, JBoss 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.security.runasprincipal;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public interface WhoAmI {
String getCallerPrincipal();
}
| 1,220 | 39.7 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runasprincipal/SingletonBean.java
|
/*
* Copyright (C) 2013 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 library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.jboss.as.test.integration.ejb.security.runasprincipal;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.security.RolesAllowed;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.EJB;
import jakarta.ejb.Remote;
import jakarta.ejb.Singleton;
import jakarta.ejb.Startup;
import org.jboss.ejb3.annotation.RunAsPrincipal;
import org.jboss.ejb3.annotation.SecurityDomain;
import org.junit.Assert;
/**
* @author <a href="mailto:[email protected]">Emmanuel Hugonnet</a> (c) 2013 Red Hat, inc.
*/
@Singleton
@Startup
@Remote(WhoAmI.class)
@RolesAllowed("Users")
@RunAs("Admin")
@RunAsPrincipal("Helloween")
@SecurityDomain("other")
public class SingletonBean implements WhoAmI {
@EJB(beanName = "StatelessBBean")
private WhoAmI beanB;
private String principal;
@PostConstruct
public void init() {
principal = beanB.getCallerPrincipal();
Assert.assertEquals("Helloween", principal);
}
public String getCallerPrincipal() {
return principal;
}
}
| 1,992 | 31.672131 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runasprincipal/customdomain/EntryBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2010, JBoss 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.security.runasprincipal.customdomain;
import jakarta.annotation.Resource;
import jakarta.annotation.security.DeclareRoles;
import jakarta.annotation.security.RolesAllowed;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.EJB;
import jakarta.ejb.Remote;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import org.jboss.as.test.integration.ejb.security.runasprincipal.WhoAmI;
import org.jboss.ejb3.annotation.RunAsPrincipal;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* Entry WhoAmI implementation, uses default security domain and calls method on TargetBean which uses another domain.
*
* @author Josef Cacek
* @see TargetBean
*/
@Stateless
@Remote(WhoAmI.class)
@DeclareRoles({ "guest", "Target" })
@RunAs("Target")
@RunAsPrincipal("principalFromEntryBean")
@SecurityDomain("other")
public class EntryBean implements WhoAmI {
@EJB(beanName = "TargetBean")
private WhoAmI target;
@Resource
private SessionContext ctx;
@RolesAllowed("guest")
public String getCallerPrincipal() {
return target.getCallerPrincipal();
}
}
| 2,163 | 33.903226 | 118 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runasprincipal/customdomain/TargetBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2010, JBoss 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.security.runasprincipal.customdomain;
import jakarta.annotation.Resource;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.Local;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import org.jboss.as.test.integration.ejb.security.runasprincipal.WhoAmI;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* Target {@link WhoAmI} interface implementation, which uses a custom security domain.
*
* @author Josef Cacek
* @see EntryBean
*/
@Stateless
@Local(WhoAmI.class)
@SecurityDomain("runasprincipal-test")
public class TargetBean implements WhoAmI {
@Resource
private SessionContext ctx;
@RolesAllowed("Target")
public String getCallerPrincipal() {
return ctx.getCallerPrincipal().getName();
}
}
| 1,829 | 34.882353 | 87 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runasprincipal/transitive/StatelessSingletonUseBean.java
|
/*
* Copyright (C) 2013 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 library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.jboss.as.test.integration.ejb.security.runasprincipal.transitive;
import jakarta.annotation.security.RunAs;
import jakarta.ejb.EJB;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
import org.jboss.as.test.integration.ejb.security.runasprincipal.WhoAmI;
import org.jboss.ejb3.annotation.RunAsPrincipal;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
*
* @author <a href="mailto:[email protected]">Emmanuel Hugonnet</a> (c) 2013 Red Hat, inc.
*/
@Stateless
@Remote(WhoAmI.class)
@RunAs("Admin")
@RunAsPrincipal("IronMaiden")
@SecurityDomain("other")
public class StatelessSingletonUseBean implements WhoAmI {
@EJB(beanName = "SimpleSingletonBean")
private WhoAmI singleton;
public String getCallerPrincipal() {
return singleton.getCallerPrincipal();
}
}
| 1,766 | 33.647059 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runasprincipal/transitive/SingletonStartupBean.java
|
/*
* Copyright (C) 2013 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 library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.jboss.as.test.integration.ejb.security.runasprincipal.transitive;
import jakarta.annotation.PostConstruct;
import jakarta.ejb.EJB;
import jakarta.ejb.Remote;
import jakarta.ejb.Singleton;
import jakarta.ejb.Startup;
import org.jboss.as.test.integration.ejb.security.runasprincipal.WhoAmI;
import org.jboss.ejb3.annotation.SecurityDomain;
import org.junit.Assert;
/**
*
* @author <a href="mailto:[email protected]">Emmanuel Hugonnet</a> (c) 2013 Red Hat, inc.
*/
@Singleton
@Startup
@Remote(WhoAmI.class)
@SecurityDomain("other")
public class SingletonStartupBean implements WhoAmI {
@EJB(beanName = "StatelessBBean")
private WhoAmI beanB;
private String principal;
@PostConstruct
public void init() {
principal = beanB.getCallerPrincipal();
Assert.fail("beanB requires role Admin");
}
public String getCallerPrincipal() {
return principal;
}
}
| 1,876 | 31.362069 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/runasprincipal/transitive/SimpleSingletonBean.java
|
/*
* Copyright (C) 2013 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 library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.jboss.as.test.integration.ejb.security.runasprincipal.transitive;
import jakarta.annotation.PostConstruct;
import jakarta.ejb.EJB;
import jakarta.ejb.Remote;
import jakarta.ejb.Singleton;
import org.jboss.as.test.integration.ejb.security.runasprincipal.WhoAmI;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
*
* @author <a href="mailto:[email protected]">Emmanuel Hugonnet</a> (c) 2013 Red Hat, inc.
*/
@Singleton
@Remote(WhoAmI.class)
@SecurityDomain("other")
public class SimpleSingletonBean implements WhoAmI {
@EJB(beanName = "StatelessBBean")
private WhoAmI beanB;
private String principal;
@PostConstruct
public void init() {
principal = beanB.getCallerPrincipal();
}
public String getCallerPrincipal() {
return principal;
}
}
| 1,763 | 31.666667 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/rolelink/CallerRoleCheckerBean.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.rolelink;
import jakarta.annotation.Resource;
import jakarta.ejb.LocalBean;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* @author Jaikiran Pai
*/
@Stateless
@LocalBean
@SecurityDomain(value = CallerRoleCheckerBean.SECURITY_DOMAIN_NAME)
public class CallerRoleCheckerBean {
public static final String SECURITY_DOMAIN_NAME = "security-link-test-security-domain";
@Resource
private SessionContext sessionContext;
public boolean isCallerInRole(final String role) {
return this.sessionContext.isCallerInRole(role);
}
}
| 1,699 | 33.693878 | 91 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/rolelink/SecurityRoleLinkTestCase.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.rolelink;
import java.io.File;
import java.util.concurrent.Callable;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
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.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.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
/**
* Tests that the security role linking via the ejb-jar.xml and the jboss-ejb3.xml works as expected
*
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
@ServerSetup(SecurityRoleLinkTestCase.SecurityRoleLinkTestCaseSetup.class)
@Category(CommonCriteria.class)
public class SecurityRoleLinkTestCase {
private static final String MODULE_NAME = "security-role-link-test";
static class SecurityRoleLinkTestCaseSetup extends EjbSecurityDomainSetup {
@Override
protected String getSecurityDomainName() {
return CallerRoleCheckerBean.SECURITY_DOMAIN_NAME;
}
@Override
protected String getUsersFile() {
return new File(SecurityRoleLinkTestCase.class.getResource("users.properties").getFile()).getAbsolutePath();
}
@Override
protected String getGroupsFile() {
return new File(SecurityRoleLinkTestCase.class.getResource("roles.properties").getFile()).getAbsolutePath();
}
}
@Deployment
public static Archive createDeployment() throws Exception {
final Package currentPackage = SecurityRoleLinkTestCase.class.getPackage();
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar")
.addPackage(CallerRoleCheckerBean.class.getPackage())
.addClasses(Util.class, SecurityRoleLinkTestCaseSetup.class)
.addClasses(AbstractSecurityDomainSetup.class, EjbSecurityDomainSetup.class)
.addAsResource(currentPackage, "users.properties", "users.properties")
.addAsResource(currentPackage,"roles.properties", "roles.properties")
.addAsManifestResource(currentPackage,"ejb-jar.xml", "ejb-jar.xml")
.addAsManifestResource(currentPackage,"jboss-ejb3.xml", "jboss-ejb3.xml")
.addAsManifestResource(currentPackage, "permissions.xml", "permissions.xml")
.addPackage(CommonCriteria.class.getPackage());
return jar;
}
/**
* Test that when the security role linking via the security-role-ref element in the ejb-jar.xml
* takes into account the security-role mapping between the principal and the role name in the jboss-ejb3.xml.
*
* @throws Exception
*/
@Test
public void testIsCallerInRole() throws Exception {
final CallerRoleCheckerBean callerRoleCheckerBean = InitialContext.doLookup("java:module/" + CallerRoleCheckerBean.class.getSimpleName());
final Callable<Void> callable = () -> {
final String realRoleName = "RealRole";
final boolean callerInRealRole = callerRoleCheckerBean.isCallerInRole(realRoleName);
Assert.assertTrue("Caller was expected to be in " + realRoleName + " but wasn't", callerInRealRole);
final String aliasRoleName = "AliasRole";
final boolean callerInAliasRole = callerRoleCheckerBean.isCallerInRole(aliasRoleName);
Assert.assertTrue("Caller was expected to be in " + aliasRoleName + " but wasn't", callerInAliasRole);
final String invalidRole = "UselessRole";
final boolean callerInUselessRole = callerRoleCheckerBean.isCallerInRole(invalidRole);
Assert.assertFalse("Caller wasn't expected to be in " + invalidRole + " but was", callerInUselessRole);
return null;
};
try {
Util.switchIdentity("phantom", "pass", callable);
} catch (Exception e) {
Assert.fail(e.toString());
throw e;
}
}
}
| 5,452 | 42.624 | 146 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/missingmethodpermission/SecuredBeanOne.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.missingmethodpermission;
import jakarta.annotation.Resource;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.EJBContext;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* @author Jaikiran Pai
*/
@Stateless
@Remote (SecurityTestRemoteView.class)
public class SecuredBeanOne implements SecurityTestRemoteView {
@Resource
private EJBContext ejbContext;
@RolesAllowed("Role1")
public String methodWithSpecificRole() {
return ejbContext.getCallerPrincipal().getName();
}
public String methodWithNoRole() {
return ejbContext.getCallerPrincipal().getName();
}
}
| 1,714 | 33.3 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/missingmethodpermission/SecuredBeanTwo.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.missingmethodpermission;
import jakarta.annotation.Resource;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.EJBContext;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* @author Jaikiran Pai
*/
@Stateless
@Remote (SecurityTestRemoteView.class)
public class SecuredBeanTwo implements SecurityTestRemoteView {
@Resource
private EJBContext ejbContext;
@RolesAllowed("Role1")
public String methodWithSpecificRole() {
return ejbContext.getCallerPrincipal().getName();
}
public String methodWithNoRole() {
return ejbContext.getCallerPrincipal().getName();
}
}
| 1,714 | 33.3 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/missingmethodpermission/SecurityTestRemoteView.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.missingmethodpermission;
/**
* @author Jaikiran Pai
*/
public interface SecurityTestRemoteView {
String methodWithSpecificRole();
String methodWithNoRole();
}
| 1,248 | 34.685714 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/missingmethodpermission/MissingMethodPermissionsDefaultAllowedTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.missingmethodpermission;
import java.util.concurrent.Callable;
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.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.ejb.security.EjbSecurityDomainSetup;
import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup;
import org.jboss.as.test.shared.integration.ejb.security.Util;
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.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
/**
* Tests the <code>missing-method-permissions-deny-access</code> configuration which lets users decide whether secured beans whose
* methods don't have explicit security configurations, are denied access or allowed access
*
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
@ServerSetup({MissingMethodPermissionsDefaultAllowedTestCase.MissingMethodPermissionsDefaultAllowedTestCaseServerSetup.class})
public class MissingMethodPermissionsDefaultAllowedTestCase {
private static final Logger logger = Logger.getLogger(MissingMethodPermissionsDefaultAllowedTestCase.class);
private static final String APP_NAME = "missing-method-permissions-test-app";
private static final String MODULE_ONE_NAME = "missing-method-permissions-test-ejb-jar-one";
private static final String MODULE_TWO_NAME = "missing-method-permissions-test-ejb-jar-two";
private static final String MODULE_THREE_NAME = "missing-method-permissions-test-ejb-jar-three";
static class MissingMethodPermissionsDefaultAllowedTestCaseServerSetup implements ServerSetupTask {
@Override
public void setup(final ManagementClient managementClient, final String containerId) throws Exception {
ModelNode address = getAddress();
ModelNode operation = new ModelNode();
operation.get(OP).set("write-attribute");
operation.get(OP_ADDR).set(address);
operation.get("name").set("default-missing-method-permissions-deny-access");
operation.get("value").set(false);
ModelNode result = managementClient.getControllerClient().execute(operation);
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
}
@Override
public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception {
ModelNode address = getAddress();
ModelNode operation = new ModelNode();
operation.get(OP).set("write-attribute");
operation.get(OP_ADDR).set(address);
operation.get("name").set("default-missing-method-permissions-deny-access");
operation.get("value").set(true);
ModelNode result = managementClient.getControllerClient().execute(operation);
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
}
private static ModelNode getAddress() {
ModelNode address = new ModelNode();
address.add("subsystem", "ejb3");
address.protect();
return address;
}
}
@Deployment
public static Archive createDeployment() {
final Package currentPackage = MissingMethodPermissionsDefaultAllowedTestCase.class.getPackage();
final JavaArchive ejbJarOne = ShrinkWrap.create(JavaArchive.class, MODULE_ONE_NAME + ".jar")
.addClasses(SecuredBeanOne.class)
.addAsManifestResource(currentPackage, "one-jboss-ejb3.xml", "jboss-ejb3.xml");
final JavaArchive ejbJarTwo = ShrinkWrap.create(JavaArchive.class, MODULE_TWO_NAME + ".jar")
.addClass(SecuredBeanTwo.class)
.addAsManifestResource(currentPackage, "two-jboss-ejb3.xml", "jboss-ejb3.xml");
final JavaArchive ejbJarThree = ShrinkWrap.create(JavaArchive.class, MODULE_THREE_NAME + ".jar")
.addClass(SecuredBeanThree.class);
final JavaArchive libJar = ShrinkWrap.create(JavaArchive.class, "bean-interfaces.jar")
.addClasses(AbstractSecurityDomainSetup.class, EjbSecurityDomainSetup.class)
.addClasses(SecurityTestRemoteView.class, Util.class, MissingMethodPermissionsDefaultAllowedTestCase.class);
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear")
.addAsModules(ejbJarOne, ejbJarTwo, ejbJarThree)
.addAsLibrary(libJar)
.addAsManifestResource(currentPackage, "permissions.xml", "permissions.xml");
return ear;
}
/**
* Tests that methods without any explicit security permissions on an EJB marked
* with <missing-method-permissions-deny-access>false</missing-method-permissions-deny-access> are allowed access
*
* @throws Exception
*/
@Test
public void testAllowAccessForMethodsMissingPermissions() throws Exception {
Callable<Void> callable = () -> {
final SecurityTestRemoteView allowAccessBean = InitialContext.doLookup("java:global/" + APP_NAME + "/" + MODULE_ONE_NAME + "/" + SecuredBeanOne.class.getSimpleName() + "!" + SecurityTestRemoteView.class.getName());
// first invoke on a method which has a specific role and that invocation should pass
final String callerPrincipalName = allowAccessBean.methodWithSpecificRole();
Assert.assertEquals("Unexpected caller prinicpal", "user1", callerPrincipalName);
// now invoke on a method which doesn't have an explicit security configuration. The SecuredBeanOne (deployment) is configured for
// <missing-method-permissions-deny-access>false</missing-method-permissions-deny-access>
// so the invocation on such a method is expected to fail
final String callerPrincipalForMethodWithNoRole = allowAccessBean.methodWithNoRole();
Assert.assertEquals("Unexpected caller prinicpal when invoking method with no role", "user1", callerPrincipalForMethodWithNoRole);
return null;
};
// establish an identity using the security domain associated with the beans in the JARs in the EAR deployment
Util.switchIdentity("user1", "password1", callable, SecuredBeanOne.class.getClassLoader());
}
/**
* Tests that methods without any explicit security permissions on an EJB marked
* with <missing-method-permissions-deny-access>true</missing-method-permissions-deny-access> are denied access
*
* @throws Exception
*/
@Test
public void testDenyAccessForMethodsMissingPermissions() throws Exception {
Callable<Void> callable = () -> {
final SecurityTestRemoteView denyAccessBean = InitialContext.doLookup("java:global/" + APP_NAME + "/" + MODULE_TWO_NAME + "/" + SecuredBeanTwo.class.getSimpleName() + "!" + SecurityTestRemoteView.class.getName());
// first invoke on a method which has a specific role and that invocation should pass
final String callerPrincipalName = denyAccessBean.methodWithSpecificRole();
Assert.assertEquals("Unexpected caller prinicpal", "user1", callerPrincipalName);
// now invoke on a method which doesn't have an explicit security configuration. The SecuredBeanTwo (deployment) is configured for
// <missing-method-permissions-deny-access>true</missing-method-permissions-deny-access>
// so the invocation on such a method is expected to fail
try {
denyAccessBean.methodWithNoRole();
Assert.fail("Invocation on a method with no specific security configurations was expected to fail by default, but it didn't");
} catch (EJBAccessException eae) {
logger.trace("Got the expected exception", eae);
}
return null;
};
// establish an identity using the security domain associated with the beans in the JARs in the EAR deployment
Util.switchIdentity("user1", "password1", callable, SecuredBeanOne.class.getClassLoader());
}
/**
* Tests that methods without any explicit security permissions or any entry in the descriptor are allowed
*
* @throws Exception
*/
@Test
public void testAllowAccessByDefaultForMethodsMissingPermissions() throws Exception {
Callable<Void> callable = () -> {
final SecurityTestRemoteView allowAccessBean = InitialContext.doLookup("java:global/" + APP_NAME + "/" + MODULE_THREE_NAME + "/" + SecuredBeanThree.class.getSimpleName() + "!" + SecurityTestRemoteView.class.getName());
// first invoke on a method which has a specific role and that invocation should pass
final String callerPrincipalName = allowAccessBean.methodWithSpecificRole();
Assert.assertEquals("Unexpected caller prinicpal", "user1", callerPrincipalName);
// now invoke on a method which doesn't have an explicit security configuration. The SecuredBeanTwo (deployment) is configured for
// <missing-method-permissions-deny-access>true</missing-method-permissions-deny-access>
// so the invocation on such a method is expected to fail
final String callerPrincipalForMethodWithNoRole = allowAccessBean.methodWithNoRole();
Assert.assertEquals("Unexpected caller prinicpal when invoking method with no role", "user1", callerPrincipalForMethodWithNoRole);
return null;
};
// establish an identity using the security domain associated with the beans in the JARs in the EAR deployment
Util.switchIdentity("user1", "password1", callable, SecuredBeanOne.class.getClassLoader());
}
}
| 11,559 | 53.78673 | 230 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/missingmethodpermission/SecuredBeanThree.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.missingmethodpermission;
import jakarta.annotation.Resource;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.EJBContext;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* @author Jaikiran Pai
*/
@Stateless
@Remote (SecurityTestRemoteView.class)
public class SecuredBeanThree implements SecurityTestRemoteView {
@Resource
private EJBContext ejbContext;
@RolesAllowed("Role1")
public String methodWithSpecificRole() {
return ejbContext.getCallerPrincipal().getName();
}
public String methodWithNoRole() {
return ejbContext.getCallerPrincipal().getName();
}
}
| 1,716 | 33.34 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/missingmethodpermission/MissingMethodPermissionsTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.missingmethodpermission;
import java.util.concurrent.Callable;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.test.integration.ejb.security.EjbSecurityDomainSetup;
import org.jboss.as.test.integration.security.common.AbstractSecurityDomainSetup;
import org.jboss.as.test.shared.integration.ejb.security.Util;
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.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import jakarta.ejb.EJBAccessException;
import javax.naming.InitialContext;
/**
* Tests the <code>missing-method-permissions-deny-access</code> configuration which lets users decide whether secured beans whose
* methods don't have explicit security configurations, are denied access or allowed access
*
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
public class MissingMethodPermissionsTestCase {
private static final Logger logger = Logger.getLogger(MissingMethodPermissionsTestCase.class);
private static final String APP_NAME = "missing-method-permissions-test-app";
private static final String MODULE_ONE_NAME = "missing-method-permissions-test-ejb-jar-one";
private static final String MODULE_TWO_NAME = "missing-method-permissions-test-ejb-jar-two";
private static final String MODULE_THREE_NAME = "missing-method-permissions-test-ejb-jar-three";
@Deployment
public static Archive createDeployment() {
final Package currentPackage = MissingMethodPermissionsTestCase.class.getPackage();
final JavaArchive ejbJarOne = ShrinkWrap.create(JavaArchive.class, MODULE_ONE_NAME + ".jar")
.addClasses(SecuredBeanOne.class)
.addAsManifestResource(currentPackage, "one-jboss-ejb3.xml", "jboss-ejb3.xml");
final JavaArchive ejbJarTwo = ShrinkWrap.create(JavaArchive.class, MODULE_TWO_NAME + ".jar")
.addClass(SecuredBeanTwo.class)
.addAsManifestResource(currentPackage, "two-jboss-ejb3.xml", "jboss-ejb3.xml");
final JavaArchive ejbJarThree = ShrinkWrap.create(JavaArchive.class, MODULE_THREE_NAME + ".jar")
.addClass(SecuredBeanThree.class);
final JavaArchive libJar = ShrinkWrap.create(JavaArchive.class, "bean-interfaces.jar")
.addClasses(AbstractSecurityDomainSetup.class, EjbSecurityDomainSetup.class)
.addClasses(SecurityTestRemoteView.class, Util.class, MissingMethodPermissionsTestCase.class);
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear")
.addAsModules(ejbJarOne, ejbJarTwo, ejbJarThree)
.addAsLibrary(libJar)
.addAsManifestResource(currentPackage, "permissions.xml", "permissions.xml");
return ear;
}
/**
* Tests that methods without any explicit security permissions on an EJB marked
* with <missing-method-permissions-deny-access>false</missing-method-permissions-deny-access> are allowed access
*
* @throws Exception
*/
@Test
public void testAllowAccessForMethodsMissingPermissions() throws Exception {
Callable<Void> callable = () -> {
final SecurityTestRemoteView allowAccessBean = InitialContext.doLookup("java:global/" + APP_NAME + "/" + MODULE_ONE_NAME + "/" + SecuredBeanOne.class.getSimpleName() + "!" + SecurityTestRemoteView.class.getName());
// first invoke on a method which has a specific role and that invocation should pass
final String callerPrincipalName = allowAccessBean.methodWithSpecificRole();
Assert.assertEquals("Unexpected caller prinicpal", "user1", callerPrincipalName);
// now invoke on a method which doesn't have an explicit security configuration. The SecuredBeanOne (deployment) is configured for
// <missing-method-permissions-deny-access>false</missing-method-permissions-deny-access>
// so the invocation on such a method is expected to fail
final String callerPrincipalForMethodWithNoRole = allowAccessBean.methodWithNoRole();
Assert.assertEquals("Unexpected caller prinicpal when invoking method with no role", "user1", callerPrincipalForMethodWithNoRole);
return null;
};
// establish an identity using the security domain associated with the beans in the JARs in the EAR deployment
Util.switchIdentity("user1", "password1", callable, SecuredBeanOne.class.getClassLoader());
}
/**
* Tests that methods without any explicit security permissions on an EJB marked
* with <missing-method-permissions-deny-access>true</missing-method-permissions-deny-access> are denied access
*
* @throws Exception
*/
@Test
public void testDenyAccessForMethodsMissingPermissions() throws Exception {
Callable<Void> callable = () -> {
final SecurityTestRemoteView denyAccessBean = InitialContext.doLookup("java:global/" + APP_NAME + "/" + MODULE_TWO_NAME + "/" + SecuredBeanTwo.class.getSimpleName() + "!" + SecurityTestRemoteView.class.getName());
// first invoke on a method which has a specific role and that invocation should pass
final String callerPrincipalName = denyAccessBean.methodWithSpecificRole();
Assert.assertEquals("Unexpected caller prinicpal", "user1", callerPrincipalName);
// now invoke on a method which doesn't have an explicit security configuration. The SecuredBeanTwo (deployment) is configured for
// <missing-method-permissions-deny-access>true</missing-method-permissions-deny-access>
// so the invocation on such a method is expected to fail
try {
denyAccessBean.methodWithNoRole();
Assert.fail("Invocation on a method with no specific security configurations was expected to fail due to <missing-method-permissions-deny-access>true</missing-method-permissions-deny-access> configuration, but it didn't");
} catch (EJBAccessException eae) {
logger.trace("Got the expected exception", eae);
}
return null;
};
// establish an identity using the security domain associated with the beans in the JARs in the EAR deployment
Util.switchIdentity("user1", "password1", callable, SecuredBeanOne.class.getClassLoader());
}
/**
* Tests that methods without any explicit security permissions or any entry in the descriptor are denied
*
* @throws Exception
*/
@Test
public void testDenyAccessByDefaultForMethodsMissingPermissions() throws Exception {
Callable<Void> callable = () -> {
final SecurityTestRemoteView denyAccessBean = InitialContext.doLookup("java:global/" + APP_NAME + "/" + MODULE_THREE_NAME + "/" + SecuredBeanThree.class.getSimpleName() + "!" + SecurityTestRemoteView.class.getName());
// first invoke on a method which has a specific role and that invocation should pass
final String callerPrincipalName = denyAccessBean.methodWithSpecificRole();
Assert.assertEquals("Unexpected caller prinicpal", "user1", callerPrincipalName);
// now invoke on a method which doesn't have an explicit security configuration. The SecuredBeanTwo (deployment) is configured for
// <missing-method-permissions-deny-access>true</missing-method-permissions-deny-access>
// so the invocation on such a method is expected to fail
try {
denyAccessBean.methodWithNoRole();
Assert.fail("Invocation on a method with no specific security configurations was expected to fail due to <missing-method-permissions-deny-access>true</missing-method-permissions-deny-access> configuration, but it didn't");
} catch (EJBAccessException eae) {
logger.trace("Got the expected exception", eae);
}
return null;
};
// establish an identity using the security domain associated with the beans in the JARs in the EAR deployment
Util.switchIdentity("user1", "password1", callable, SecuredBeanOne.class.getClassLoader());
}
}
| 9,520 | 55.337278 | 238 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/base/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.base;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.ejb.SessionContext;
import java.util.concurrent.Callable;
import org.jboss.as.test.integration.ejb.security.WhoAmI;
import org.jboss.as.test.shared.integration.ejb.security.Util;
/**
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
public abstract class EntryBean {
@EJB
private WhoAmI whoAmIBean;
@Resource
private SessionContext context;
public String whoAmI() {
return context.getCallerPrincipal().getName();
}
public String[] doubleWhoAmI() {
String localWho = context.getCallerPrincipal().getName();
String remoteWho = whoAmIBean.getCallerPrincipal().getName();
String secondLocalWho = context.getCallerPrincipal().getName();
if (secondLocalWho.equals(localWho) == false) {
throw new IllegalStateException("Local getCallerPrincipal changed from '" + localWho + "' to '" + secondLocalWho);
}
return new String[]{localWho, remoteWho};
}
public String[] doubleWhoAmI(String username, String password) throws Exception {
String localWho = context.getCallerPrincipal().getName();
final Callable<String[]> callable = () -> {
String remoteWho = whoAmIBean.getCallerPrincipal().getName();
return new String[]{localWho, remoteWho};
};
try {
return Util.switchIdentity(username, password, callable);
} finally {
String secondLocalWho = context.getCallerPrincipal().getName();
if (secondLocalWho.equals(localWho) == false) {
throw new IllegalStateException("Local getCallerPrincipal changed from '" + localWho + "' to '" + secondLocalWho);
}
}
}
public boolean doIHaveRole(String roleName) {
return context.isCallerInRole(roleName);
}
public boolean[] doubleDoIHaveRole(String roleName) {
boolean localDoI = context.isCallerInRole(roleName);
boolean remoteDoI = whoAmIBean.doIHaveRole(roleName);
return new boolean[]{localDoI, remoteDoI};
}
public boolean[] doubleDoIHaveRole(String roleName, String username, String password) throws Exception {
boolean localDoI = context.isCallerInRole(roleName);
final Callable<boolean[]> callable = () -> {
boolean remoteDoI = whoAmIBean.doIHaveRole(roleName);
return new boolean[]{localDoI, remoteDoI};
};
try {
return Util.switchIdentity(username, password, callable);
} finally {
boolean secondLocalDoI = context.isCallerInRole(roleName);
if (secondLocalDoI != localDoI) {
throw new IllegalStateException("Local call to isCallerInRole for '" + roleName + "' changed from " + localDoI + " to " + secondLocalDoI);
}
}
}
}
| 3,996 | 37.432692 | 154 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/base/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.base;
import java.security.Principal;
import jakarta.annotation.Resource;
import jakarta.ejb.SessionContext;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public abstract class WhoAmIBean {
@Resource
private SessionContext context;
public Principal getCallerPrincipal() {
return context.getCallerPrincipal();
}
public boolean doIHaveRole(String roleName) {
return context.isCallerInRole(roleName);
}
}
| 1,554 | 32.804348 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/security/callerprincipal/SLSBWithoutSecurityDomain.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.Resource;
import jakarta.ejb.Remote;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
/**
* SessionBeanWithoutSecurityDomain - testing getCallerPrincipal() method
*
* @author Jaikiran Pai, Ondrej Chaloupka
*/
@Stateless
@Remote(ISLSBWithoutSecurityDomain.class)
public class SLSBWithoutSecurityDomain implements ISLSBWithoutSecurityDomain {
@Resource
private SessionContext sessContext;
/**
* {@inheritDoc}
*/
public Principal getCallerPrincipal() {
// as per the API, the getCallerPrincipal never returns null.
// if there is no principal associated then 'anonymous' role is returned
return this.sessContext.getCallerPrincipal();
}
}
| 1,864 | 34.188679 | 80 |
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.