use of org.apache.openejb.jee.MethodPermission in project tomee by apache.
the class RemoveWebServices method deploy.
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
for (final EjbModule ejbModule : appModule.getEjbModules()) {
final EjbJar ejbJar = ejbModule.getEjbJar();
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
final String ejbName = bean.getEjbName();
final EjbDeployment ejbDeployment = deployments.get(ejbName);
// Clear any <service-ref> references from ejbs
bean.getServiceRef().clear();
if (!(bean instanceof SessionBean)) {
continue;
}
final SessionBean sessionBean = (SessionBean) bean;
if (sessionBean.getServiceEndpoint() == null) {
continue;
}
sessionBean.setServiceEndpoint(null);
// if not, then we should just delete it
if (sessionBean.getHome() != null) {
continue;
}
if (sessionBean.getLocalHome() != null) {
continue;
}
if (sessionBean.getBusinessLocal().size() > 0) {
continue;
}
if (sessionBean.getBusinessRemote().size() > 0) {
continue;
}
// Ok, delete away...
ejbJar.removeEnterpriseBean(ejbName);
openejbJar.removeEjbDeployment(ejbDeployment);
// As well, let's get rid of any transaction or security attributes
// associated with the bean we just deleted.
final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
for (final MethodPermission permission : copy(assemblyDescriptor.getMethodPermission())) {
for (final Method method : copy(permission.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
permission.getMethod().remove(method);
}
}
if (permission.getMethod().size() == 0) {
assemblyDescriptor.getMethodPermission().remove(permission);
}
}
for (final ContainerTransaction transaction : copy(assemblyDescriptor.getContainerTransaction())) {
for (final Method method : copy(transaction.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
transaction.getMethod().remove(method);
}
}
if (transaction.getMethod().size() == 0) {
assemblyDescriptor.getContainerTransaction().remove(transaction);
}
}
for (final InterceptorBinding binding : copy(assemblyDescriptor.getInterceptorBinding())) {
if (binding.getEjbName().equals(ejbName)) {
assemblyDescriptor.getInterceptorBinding().remove(binding);
}
}
}
}
// Clear any <service-ref> references from interceptors
for (final Interceptor interceptor : ejbJar.getInterceptors()) {
interceptor.getServiceRef().clear();
}
}
return appModule;
}
use of org.apache.openejb.jee.MethodPermission in project tomee by apache.
the class DebuggableVmHackery method deploy.
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
for (final EjbModule ejbModule : appModule.getEjbModules()) {
final EjbJar ejbJar = ejbModule.getEjbJar();
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
ejbJar.setRelationships(null);
final List<String> removed = new ArrayList<String>();
for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
final String ejbName = bean.getEjbName();
final EjbDeployment ejbDeployment = deployments.get(ejbName);
pruneRefs(bean, ejbDeployment);
// }
if (!(bean instanceof MessageDrivenBean) && !(bean instanceof EntityBean)) {
continue;
}
ejbJar.removeEnterpriseBean(ejbName);
openejbJar.removeEjbDeployment(ejbDeployment);
removed.add(ejbName);
final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
for (final MethodPermission permission : copy(assemblyDescriptor.getMethodPermission())) {
for (final Method method : copy(permission.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
permission.getMethod().remove(method);
}
}
if (permission.getMethod().size() == 0) {
assemblyDescriptor.getMethodPermission().remove(permission);
}
}
for (final ContainerTransaction transaction : copy(assemblyDescriptor.getContainerTransaction())) {
for (final Method method : copy(transaction.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
transaction.getMethod().remove(method);
}
}
if (transaction.getMethod().size() == 0) {
assemblyDescriptor.getContainerTransaction().remove(transaction);
}
}
for (final InterceptorBinding binding : copy(assemblyDescriptor.getInterceptorBinding())) {
if (binding.getEjbName().equals(ejbName)) {
assemblyDescriptor.getInterceptorBinding().remove(binding);
}
}
}
}
// Drop any ejb ref to with an ejb-link to a removed ejb
for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
bean.getEjbLocalRefMap().keySet().removeAll(removed);
bean.getEjbRefMap().keySet().removeAll(removed);
}
for (final Interceptor interceptor : ejbJar.getInterceptors()) {
pruneRefs(interceptor, new EjbDeployment());
}
}
return appModule;
}
use of org.apache.openejb.jee.MethodPermission in project tomee by apache.
the class CheckAssemblyBindings method validate.
public void validate(final EjbModule ejbModule) {
checkUnusedInterceptors(ejbModule);
final Map<String, EnterpriseBean> ejbsByName = ejbModule.getEjbJar().getEnterpriseBeansByEjbName();
final AssemblyDescriptor assembly = ejbModule.getEjbJar().getAssemblyDescriptor();
if (assembly == null) {
return;
}
for (final InterceptorBinding binding : assembly.getInterceptorBinding()) {
final List<String> interceptorClasses = binding.getInterceptorClass();
if (binding.getInterceptorOrder() != null) {
interceptorClasses.addAll(binding.getInterceptorOrder().getInterceptorClass());
}
if (binding.getEjbName() != null && !binding.getEjbName().equals("*") && !ejbsByName.containsKey(binding.getEjbName())) {
fail("InterceptorBinding", "interceptorBinding.noSuchEjbName", binding.getEjbName(), join(",", interceptorClasses));
}
if (binding.getMethod() != null) {
if (binding.getEjbName() == null) {
fail("InterceptorBinding", "interceptorBinding.ejbNameRequiredWithMethod", binding.getMethod().getMethodName(), join(",", interceptorClasses));
}
}
}
for (final MethodPermission permission : assembly.getMethodPermission()) {
for (final Method method : permission.getMethod()) {
if (method.getEjbName() == null) {
fail("MethodPermission", "methodPermission.ejbNameRequired", method.getMethodName(), join(",", permission.getRoleName()));
} else if (method.getEjbName().equals("*")) {
// NOPMD
// no-op. Just continue the loop.
} else if (!ejbsByName.containsKey(method.getEjbName())) {
fail("MethodPermission", "methodPermission.noSuchEjbName", method.getEjbName(), method.getMethodName(), join(",", permission.getRoleName()));
}
}
}
for (final ContainerTransaction transaction : assembly.getContainerTransaction()) {
for (final Method method : transaction.getMethod()) {
if (method.getEjbName() == null) {
fail("ContainerTransaction", "containerTransaction.ejbNameRequired", method.getMethodName(), transaction.getTransAttribute());
} else if (method.getEjbName().equals("*")) {
// NOPMD
// no-op. Just continue the loop.
} else if (!ejbsByName.containsKey(method.getEjbName())) {
fail("ContainerTransaction", "containerTransaction.noSuchEjbName", method.getEjbName(), method.getMethodName(), transaction.getTransAttribute());
}
}
}
}
use of org.apache.openejb.jee.MethodPermission in project tomee by apache.
the class AssemblyDescriptor$JAXB method _read.
public static final AssemblyDescriptor _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
// Check for xsi:nil
if (reader.isXsiNil()) {
return null;
}
if (context == null) {
context = new RuntimeContext();
}
final AssemblyDescriptor assemblyDescriptor = new AssemblyDescriptor();
context.beforeUnmarshal(assemblyDescriptor, LifecycleCallback.NONE);
List<SecurityRole> securityRole = null;
List<MethodPermission> methodPermission = null;
List<ContainerTransaction> containerTransaction = null;
List<ContainerConcurrency> containerConcurrency = null;
List<InterceptorBinding> interceptorBinding = null;
List<MessageDestination> messageDestination = null;
KeyedCollection<String, ApplicationException> applicationException = null;
// Check xsi:type
final QName xsiType = reader.getXsiType();
if (xsiType != null) {
if (("assembly-descriptorType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
return context.unexpectedXsiType(reader, AssemblyDescriptor.class);
}
}
// Read attributes
for (final Attribute attribute : reader.getAttributes()) {
if (("id" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
// ATTRIBUTE: id
final String id = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
context.addXmlId(reader, id, assemblyDescriptor);
assemblyDescriptor.id = id;
} else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
context.unexpectedAttribute(attribute, new QName("", "id"));
}
}
// Read elements
for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
if (("security-role" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: securityRole
final SecurityRole securityRoleItem = readSecurityRole(elementReader, context);
if (securityRole == null) {
securityRole = assemblyDescriptor.securityRole;
if (securityRole != null) {
securityRole.clear();
} else {
securityRole = new ArrayList<SecurityRole>();
}
}
securityRole.add(securityRoleItem);
} else if (("method-permission" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: methodPermission
final MethodPermission methodPermissionItem = readMethodPermission(elementReader, context);
if (methodPermission == null) {
methodPermission = assemblyDescriptor.methodPermission;
if (methodPermission != null) {
methodPermission.clear();
} else {
methodPermission = new ArrayList<MethodPermission>();
}
}
methodPermission.add(methodPermissionItem);
} else if (("container-transaction" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: containerTransaction
final ContainerTransaction containerTransactionItem = readContainerTransaction(elementReader, context);
if (containerTransaction == null) {
containerTransaction = assemblyDescriptor.containerTransaction;
if (containerTransaction != null) {
containerTransaction.clear();
} else {
containerTransaction = new ArrayList<ContainerTransaction>();
}
}
containerTransaction.add(containerTransactionItem);
} else if (("container-concurrency" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: containerConcurrency
final ContainerConcurrency containerConcurrencyItem = readContainerConcurrency(elementReader, context);
if (containerConcurrency == null) {
containerConcurrency = assemblyDescriptor.containerConcurrency;
if (containerConcurrency != null) {
containerConcurrency.clear();
} else {
containerConcurrency = new ArrayList<ContainerConcurrency>();
}
}
containerConcurrency.add(containerConcurrencyItem);
} else if (("interceptor-binding" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: interceptorBinding
final InterceptorBinding interceptorBindingItem = readInterceptorBinding(elementReader, context);
if (interceptorBinding == null) {
interceptorBinding = assemblyDescriptor.interceptorBinding;
if (interceptorBinding != null) {
interceptorBinding.clear();
} else {
interceptorBinding = new ArrayList<InterceptorBinding>();
}
}
interceptorBinding.add(interceptorBindingItem);
} else if (("message-destination" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: messageDestination
final MessageDestination messageDestinationItem = readMessageDestination(elementReader, context);
if (messageDestination == null) {
messageDestination = assemblyDescriptor.messageDestination;
if (messageDestination != null) {
messageDestination.clear();
} else {
messageDestination = new ArrayList<MessageDestination>();
}
}
messageDestination.add(messageDestinationItem);
} else if (("exclude-list" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: excludeList
final ExcludeList excludeList = readExcludeList(elementReader, context);
assemblyDescriptor.excludeList = excludeList;
} else if (("application-exception" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
// ELEMENT: applicationException
final ApplicationException applicationExceptionItem = readApplicationException(elementReader, context);
if (applicationException == null) {
applicationException = assemblyDescriptor.applicationException;
if (applicationException != null) {
applicationException.clear();
} else {
applicationException = new KeyedCollection<String, ApplicationException>();
}
}
applicationException.add(applicationExceptionItem);
} else {
context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "security-role"), new QName("http://java.sun.com/xml/ns/javaee", "method-permission"), new QName("http://java.sun.com/xml/ns/javaee", "container-transaction"), new QName("http://java.sun.com/xml/ns/javaee", "container-concurrency"), new QName("http://java.sun.com/xml/ns/javaee", "interceptor-binding"), new QName("http://java.sun.com/xml/ns/javaee", "message-destination"), new QName("http://java.sun.com/xml/ns/javaee", "exclude-list"), new QName("http://java.sun.com/xml/ns/javaee", "application-exception"));
}
}
if (securityRole != null) {
assemblyDescriptor.securityRole = securityRole;
}
if (methodPermission != null) {
assemblyDescriptor.methodPermission = methodPermission;
}
if (containerTransaction != null) {
assemblyDescriptor.containerTransaction = containerTransaction;
}
if (containerConcurrency != null) {
assemblyDescriptor.containerConcurrency = containerConcurrency;
}
if (interceptorBinding != null) {
assemblyDescriptor.interceptorBinding = interceptorBinding;
}
if (messageDestination != null) {
assemblyDescriptor.messageDestination = messageDestination;
}
if (applicationException != null) {
assemblyDescriptor.applicationException = applicationException;
}
context.afterUnmarshal(assemblyDescriptor, LifecycleCallback.NONE);
return assemblyDescriptor;
}
use of org.apache.openejb.jee.MethodPermission in project tomee by apache.
the class CheckInvalidMethodPermissionsTest method test.
@Keys({ @Key("methodPermission.ejbNameRequired"), @Key("methodPermission.noSuchEjbName") })
public EjbJar test() throws Exception {
final EjbJar ejbJar = new EjbJar();
final MethodPermission permission = new MethodPermission(new Method((String) null, (String) null));
ejbJar.getAssemblyDescriptor().getMethodPermission().add(permission);
final MethodPermission permission1 = new MethodPermission(new Method("wrongEjbName", "wrongMethodName"));
ejbJar.getAssemblyDescriptor().getMethodPermission().add(permission1);
return ejbJar;
}
Aggregations